summaryrefslogtreecommitdiffstats
path: root/mojo/shell/public/cpp/lib/shell_test.cc
blob: e5cb3c2edb822e6b922836e9e867bf49433676a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/shell/public/cpp/shell_test.h"

#include "base/message_loop/message_loop.h"
#include "mojo/shell/background/background_shell.h"
#include "mojo/shell/public/cpp/shell_client.h"

namespace mojo {
namespace test {

ShellTestClient::ShellTestClient(ShellTest* test) : test_(test) {}
ShellTestClient::~ShellTestClient() {}

void ShellTestClient::Initialize(Connector* connector, const Identity& identity,
                                 uint32_t id) {
  test_->InitializeCalled(connector, identity.name(), identity.user_id(), id);
}

ShellTest::ShellTest() {}
ShellTest::ShellTest(const std::string& test_name) : test_name_(test_name) {}
ShellTest::~ShellTest() {}

void ShellTest::InitTestName(const std::string& test_name) {
  DCHECK(test_name_.empty());
  test_name_ = test_name;
}

scoped_ptr<ShellClient> ShellTest::CreateShellClient() {
  return make_scoped_ptr(new ShellTestClient(this));
}

scoped_ptr<base::MessageLoop> ShellTest::CreateMessageLoop() {
  return make_scoped_ptr(new base::MessageLoop);
}

void ShellTest::InitializeCalled(Connector* connector,
                                 const std::string& name,
                                 const std::string& user_id,
                                 uint32_t id) {
  DCHECK_EQ(connector_, connector);
  initialize_name_ = name;
  initialize_instance_id_ = id;
  initialize_userid_ = user_id;
}

void ShellTest::SetUp() {
  shell_client_ = CreateShellClient();
  message_loop_ = CreateMessageLoop();
  background_shell_.reset(new shell::BackgroundShell);
  background_shell_->Init(nullptr);
  shell_connection_.reset(new ShellConnection(
      shell_client_.get(),
      background_shell_->CreateShellClientRequest(test_name_)));
  connector_ = shell_connection_->connector();
}

void ShellTest::TearDown() {
  shell_connection_.reset();
  background_shell_.reset();
  message_loop_.reset();
  shell_client_.reset();
}

}  // namespace test
}  // namespace mojo