OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/shell/public/cpp/shell_test.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 #include "base/run_loop.h" | |
9 #include "mojo/shell/background/background_shell.h" | |
10 #include "mojo/shell/public/cpp/shell_client.h" | |
11 | |
12 namespace mojo { | |
13 namespace test { | |
14 | |
15 ShellTestClient::ShellTestClient(ShellTest* test) : test_(test) {} | |
16 ShellTestClient::~ShellTestClient() {} | |
17 | |
18 void ShellTestClient::Initialize(Connector* connector, const Identity& identity, | |
19 uint32_t id) { | |
20 test_->InitializeCalled(connector, identity.name(), identity.user_id(), id); | |
21 } | |
22 | |
23 ShellTest::ShellTest() {} | |
24 ShellTest::ShellTest(const std::string& test_name) : test_name_(test_name) {} | |
25 ShellTest::~ShellTest() {} | |
26 | |
27 void ShellTest::InitTestName(const std::string& test_name) { | |
28 DCHECK(test_name_.empty()); | |
29 test_name_ = test_name; | |
30 } | |
31 | |
32 scoped_ptr<ShellClient> ShellTest::CreateShellClient() { | |
33 return make_scoped_ptr(new ShellTestClient(this)); | |
34 } | |
35 | |
36 scoped_ptr<base::MessageLoop> ShellTest::CreateMessageLoop() { | |
37 return make_scoped_ptr(new base::MessageLoop); | |
38 } | |
39 | |
40 void ShellTest::InitializeCalled(Connector* connector, | |
41 const std::string& name, | |
42 const std::string& user_id, | |
43 uint32_t id) { | |
44 DCHECK_EQ(connector_, connector); | |
45 initialize_name_ = name; | |
46 initialize_instance_id_ = id; | |
47 initialize_userid_ = user_id; | |
48 initialize_called_.Run(); | |
49 } | |
50 | |
51 void ShellTest::SetUp() { | |
52 shell_client_ = CreateShellClient(); | |
53 message_loop_ = CreateMessageLoop(); | |
54 background_shell_.reset(new shell::BackgroundShell); | |
55 background_shell_->Init(nullptr); | |
56 | |
57 // Create the shell connection. We don't proceed until we get our | |
58 // ShellClient's Initialize() method is called. | |
59 base::RunLoop run_loop; | |
60 base::MessageLoop::ScopedNestableTaskAllower allow( | |
61 base::MessageLoop::current()); | |
62 initialize_called_ = run_loop.QuitClosure(); | |
63 | |
64 shell_connection_.reset(new ShellConnection( | |
65 shell_client_.get(), | |
66 background_shell_->CreateShellClientRequest(test_name_))); | |
67 connector_ = shell_connection_->connector(); | |
68 | |
69 run_loop.Run(); | |
70 } | |
71 | |
72 void ShellTest::TearDown() { | |
73 shell_connection_.reset(); | |
74 background_shell_.reset(); | |
75 message_loop_.reset(); | |
76 shell_client_.reset(); | |
77 } | |
78 | |
79 } // namespace test | |
80 } // namespace mojo | |
OLD | NEW |