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 URL with multiple application tests. | 21 // Share the application name with multiple application tests. |
22 String g_url; | 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 uint32_t g_user_id = shell::mojom::Connector::kUserRoot; |
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& url, | 48 const mojo::String& name, |
49 uint32_t id, | 49 uint32_t id, |
50 uint32_t user_id) override { | 50 uint32_t user_id) override { |
51 g_url = url; | 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_url, | 59 const String& requestor_name, |
60 uint32_t requestor_user_id, | 60 uint32_t 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& url) 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 }; |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 MojoResult RunAllTests(MojoHandle shell_client_request_handle) { | 74 MojoResult RunAllTests(MojoHandle shell_client_request_handle) { |
75 { | 75 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 (void)g_shell_client_request.PassMessagePipe(); | 111 (void)g_shell_client_request.PassMessagePipe(); |
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 url_(g_url) { | 121 name_(g_name) { |
122 // Fake ShellClient initialization. | 122 // Fake ShellClient initialization. |
123 shell::mojom::ShellClient* shell_client = shell_connection_.get(); | 123 shell::mojom::ShellClient* shell_client = shell_connection_.get(); |
124 shell_client->Initialize(std::move(g_connector), g_url, g_id, g_user_id); | 124 shell_client->Initialize(std::move(g_connector), g_name, g_id, g_user_id); |
125 } | 125 } |
126 | 126 |
127 TestHelper::~TestHelper() { | 127 TestHelper::~TestHelper() { |
128 // We may have supplied a member as the client. Delete |shell_connection_| | 128 // We may have supplied a member as the client. Delete |shell_connection_| |
129 // while still valid. | 129 // while still valid. |
130 shell_connection_.reset(); | 130 shell_connection_.reset(); |
131 } | 131 } |
132 | 132 |
133 ApplicationTestBase::ApplicationTestBase() : test_helper_(nullptr) {} | 133 ApplicationTestBase::ApplicationTestBase() : test_helper_(nullptr) {} |
134 | 134 |
(...skipping 26 matching lines...) Expand all Loading... |
161 if (ShouldCreateDefaultRunLoop()) | 161 if (ShouldCreateDefaultRunLoop()) |
162 Environment::DestroyDefaultRunLoop(); | 162 Environment::DestroyDefaultRunLoop(); |
163 } | 163 } |
164 | 164 |
165 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 165 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
166 return true; | 166 return true; |
167 } | 167 } |
168 | 168 |
169 } // namespace test | 169 } // namespace test |
170 } // namespace mojo | 170 } // namespace mojo |
OLD | NEW |