OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
11 #include "mojo/public/cpp/environment/environment.h" | 11 #include "mojo/public/cpp/environment/environment.h" |
12 #include "mojo/public/cpp/system/message_pipe.h" | 12 #include "mojo/public/cpp/system/message_pipe.h" |
13 #include "mojo/shell/public/cpp/application_test_base.h" | 13 #include "mojo/shell/public/cpp/application_test_base.h" |
14 #include "mojo/shell/public/cpp/shell_connection.h" | 14 #include "mojo/shell/public/cpp/shell_connection.h" |
15 #include "mojo/shell/public/interfaces/shell_client.mojom.h" | 15 #include "mojo/shell/public/interfaces/shell_client.mojom.h" |
16 | 16 |
17 namespace mojo { | 17 namespace mojo { |
18 namespace test { | 18 namespace test { |
19 | 19 |
20 namespace { | 20 namespace { |
21 // Share the application name with multiple application tests. | 21 // Share the application name with multiple application tests. |
22 String g_name; | 22 String g_name; |
23 uint32_t g_id = shell::mojom::Connector::kInvalidApplicationID; | 23 uint32_t g_id = shell::mojom::Connector::kInvalidApplicationID; |
24 uint32_t g_user_id = shell::mojom::Connector::kUserRoot; | 24 String g_user_id = shell::mojom::kRootUserID; |
25 | 25 |
26 // ShellClient request handle passed from the shell in MojoMain, stored in | 26 // ShellClient request handle passed from the shell in MojoMain, stored in |
27 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections. | 27 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections. |
28 InterfaceRequest<shell::mojom::ShellClient> g_shell_client_request; | 28 InterfaceRequest<shell::mojom::ShellClient> g_shell_client_request; |
29 | 29 |
30 // Connector pointer passed in the initial mojo.ShellClient.Initialize() call, | 30 // Connector pointer passed in the initial mojo.ShellClient.Initialize() call, |
31 // stored in between initial setup and the first test and between SetUp/TearDown | 31 // stored in between initial setup and the first test and between SetUp/TearDown |
32 // calls so we can (re-)initialize new ShellConnections. | 32 // calls so we can (re-)initialize new ShellConnections. |
33 shell::mojom::ConnectorPtr g_connector; | 33 shell::mojom::ConnectorPtr g_connector; |
34 | 34 |
35 class ShellGrabber : public shell::mojom::ShellClient { | 35 class ShellGrabber : public shell::mojom::ShellClient { |
36 public: | 36 public: |
37 explicit ShellGrabber(InterfaceRequest<shell::mojom::ShellClient> request) | 37 explicit ShellGrabber(InterfaceRequest<shell::mojom::ShellClient> request) |
38 : binding_(this, std::move(request)) {} | 38 : binding_(this, std::move(request)) {} |
39 | 39 |
40 void WaitForInitialize() { | 40 void WaitForInitialize() { |
41 // Initialize is always the first call made on ShellClient. | 41 // Initialize is always the first call made on ShellClient. |
42 CHECK(binding_.WaitForIncomingMethodCall()); | 42 CHECK(binding_.WaitForIncomingMethodCall()); |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 // shell::mojom::ShellClient implementation. | 46 // shell::mojom::ShellClient implementation. |
47 void Initialize(shell::mojom::ConnectorPtr connector, | 47 void Initialize(shell::mojom::ConnectorPtr connector, |
48 const mojo::String& name, | 48 const String& name, |
49 uint32_t id, | 49 const String& user_id, |
50 uint32_t user_id) override { | 50 uint32_t id) override { |
51 g_name = name; | 51 g_name = name; |
52 g_id = id; | 52 g_id = id; |
53 g_user_id = user_id; | 53 g_user_id = user_id; |
54 g_shell_client_request = binding_.Unbind(); | 54 g_shell_client_request = binding_.Unbind(); |
55 g_connector = std::move(connector); | 55 g_connector = std::move(connector); |
56 } | 56 } |
57 | 57 |
58 void AcceptConnection( | 58 void AcceptConnection( |
59 const String& requestor_name, | 59 const String& requestor_name, |
60 uint32_t requestor_user_id, | 60 const String& requestor_user_id, |
61 uint32_t requestor_id, | 61 uint32_t requestor_id, |
62 shell::mojom::InterfaceProviderRequest local_interfaces, | 62 shell::mojom::InterfaceProviderRequest local_interfaces, |
63 shell::mojom::InterfaceProviderPtr remote_interfaces, | 63 shell::mojom::InterfaceProviderPtr remote_interfaces, |
64 Array<String> allowed_interfaces, | 64 Array<String> allowed_interfaces, |
65 const String& name) override { | 65 const String& name) override { |
66 CHECK(false); | 66 CHECK(false); |
67 } | 67 } |
68 | 68 |
69 Binding<ShellClient> binding_; | 69 Binding<ShellClient> binding_; |
70 }; | 70 }; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 g_connector.reset(); | 112 g_connector.reset(); |
113 | 113 |
114 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; | 114 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; |
115 } | 115 } |
116 | 116 |
117 TestHelper::TestHelper(ShellClient* client) | 117 TestHelper::TestHelper(ShellClient* client) |
118 : shell_connection_(new ShellConnection( | 118 : shell_connection_(new ShellConnection( |
119 client == nullptr ? &default_shell_client_ : client, | 119 client == nullptr ? &default_shell_client_ : client, |
120 std::move(g_shell_client_request))), | 120 std::move(g_shell_client_request))), |
121 name_(g_name), | 121 name_(g_name), |
122 instance_id_(g_id), | 122 userid_(g_user_id), |
123 userid_(g_user_id) { | 123 instance_id_(g_id) { |
124 // Fake ShellClient initialization. | 124 // Fake ShellClient initialization. |
125 shell::mojom::ShellClient* shell_client = shell_connection_.get(); | 125 shell::mojom::ShellClient* shell_client = shell_connection_.get(); |
126 shell_client->Initialize(std::move(g_connector), g_name, g_id, g_user_id); | 126 shell_client->Initialize(std::move(g_connector), g_name, g_user_id, g_id); |
127 } | 127 } |
128 | 128 |
129 TestHelper::~TestHelper() { | 129 TestHelper::~TestHelper() { |
130 // We may have supplied a member as the client. Delete |shell_connection_| | 130 // We may have supplied a member as the client. Delete |shell_connection_| |
131 // while still valid. | 131 // while still valid. |
132 shell_connection_.reset(); | 132 shell_connection_.reset(); |
133 } | 133 } |
134 | 134 |
135 ApplicationTestBase::ApplicationTestBase() : test_helper_(nullptr) {} | 135 ApplicationTestBase::ApplicationTestBase() : test_helper_(nullptr) {} |
136 | 136 |
(...skipping 26 matching lines...) Expand all Loading... |
163 if (ShouldCreateDefaultRunLoop()) | 163 if (ShouldCreateDefaultRunLoop()) |
164 Environment::DestroyDefaultRunLoop(); | 164 Environment::DestroyDefaultRunLoop(); |
165 } | 165 } |
166 | 166 |
167 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 167 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 } // namespace test | 171 } // namespace test |
172 } // namespace mojo | 172 } // namespace mojo |
OLD | NEW |