| 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 shell::mojom::IdentityPtr g_identity; |
| 23 uint32_t g_id = shell::mojom::kInvalidInstanceID; | 23 uint32_t g_id = shell::mojom::kInvalidInstanceID; |
| 24 String g_user_id = shell::mojom::kRootUserID; | |
| 25 | 24 |
| 26 // ShellClient request handle passed from the shell in MojoMain, stored in | 25 // ShellClient request handle passed from the shell in MojoMain, stored in |
| 27 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections. | 26 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections. |
| 28 InterfaceRequest<shell::mojom::ShellClient> g_shell_client_request; | 27 InterfaceRequest<shell::mojom::ShellClient> g_shell_client_request; |
| 29 | 28 |
| 30 // Connector pointer passed in the initial mojo.ShellClient.Initialize() call, | 29 // Connector pointer passed in the initial mojo.ShellClient.Initialize() call, |
| 31 // stored in between initial setup and the first test and between SetUp/TearDown | 30 // stored in between initial setup and the first test and between SetUp/TearDown |
| 32 // calls so we can (re-)initialize new ShellConnections. | 31 // calls so we can (re-)initialize new ShellConnections. |
| 33 shell::mojom::ConnectorPtr g_connector; | 32 shell::mojom::ConnectorPtr g_connector; |
| 34 | 33 |
| 35 class ShellGrabber : public shell::mojom::ShellClient { | 34 class ShellGrabber : public shell::mojom::ShellClient { |
| 36 public: | 35 public: |
| 37 explicit ShellGrabber(InterfaceRequest<shell::mojom::ShellClient> request) | 36 explicit ShellGrabber(InterfaceRequest<shell::mojom::ShellClient> request) |
| 38 : binding_(this, std::move(request)) {} | 37 : binding_(this, std::move(request)) {} |
| 39 | 38 |
| 40 void WaitForInitialize() { | 39 void WaitForInitialize() { |
| 41 // Initialize is always the first call made on ShellClient. | 40 // Initialize is always the first call made on ShellClient. |
| 42 CHECK(binding_.WaitForIncomingMethodCall()); | 41 CHECK(binding_.WaitForIncomingMethodCall()); |
| 43 } | 42 } |
| 44 | 43 |
| 45 private: | 44 private: |
| 46 // shell::mojom::ShellClient implementation. | 45 // shell::mojom::ShellClient implementation. |
| 47 void Initialize(shell::mojom::ConnectorPtr connector, | 46 void Initialize(shell::mojom::ConnectorPtr connector, |
| 48 const String& name, | 47 shell::mojom::IdentityPtr identity, |
| 49 const String& user_id, | |
| 50 uint32_t id) override { | 48 uint32_t id) override { |
| 51 g_name = name; | 49 g_identity = std::move(identity); |
| 52 g_id = id; | 50 g_id = id; |
| 53 g_user_id = user_id; | |
| 54 g_shell_client_request = binding_.Unbind(); | 51 g_shell_client_request = binding_.Unbind(); |
| 55 g_connector = std::move(connector); | 52 g_connector = std::move(connector); |
| 56 } | 53 } |
| 57 | 54 |
| 58 void AcceptConnection( | 55 void AcceptConnection( |
| 59 const String& requestor_name, | 56 shell::mojom::IdentityPtr source, |
| 60 const String& requestor_user_id, | 57 uint32_t source_id, |
| 61 uint32_t requestor_id, | |
| 62 shell::mojom::InterfaceProviderRequest local_interfaces, | 58 shell::mojom::InterfaceProviderRequest local_interfaces, |
| 63 shell::mojom::InterfaceProviderPtr remote_interfaces, | 59 shell::mojom::InterfaceProviderPtr remote_interfaces, |
| 64 Array<String> allowed_interfaces, | 60 Array<String> allowed_interfaces, |
| 65 const String& name) override { | 61 const String& name) override { |
| 66 CHECK(false); | 62 CHECK(false); |
| 67 } | 63 } |
| 68 | 64 |
| 69 Binding<ShellClient> binding_; | 65 Binding<ShellClient> binding_; |
| 70 }; | 66 }; |
| 71 | 67 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 (void)g_shell_client_request.PassMessagePipe(); | 107 (void)g_shell_client_request.PassMessagePipe(); |
| 112 g_connector.reset(); | 108 g_connector.reset(); |
| 113 | 109 |
| 114 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; | 110 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; |
| 115 } | 111 } |
| 116 | 112 |
| 117 TestHelper::TestHelper(ShellClient* client) | 113 TestHelper::TestHelper(ShellClient* client) |
| 118 : shell_connection_(new ShellConnection( | 114 : shell_connection_(new ShellConnection( |
| 119 client == nullptr ? &default_shell_client_ : client, | 115 client == nullptr ? &default_shell_client_ : client, |
| 120 std::move(g_shell_client_request))), | 116 std::move(g_shell_client_request))), |
| 121 name_(g_name), | 117 name_(g_identity->name), |
| 122 userid_(g_user_id), | 118 userid_(g_identity->user_id), |
| 123 instance_id_(g_id) { | 119 instance_id_(g_id) { |
| 124 // Fake ShellClient initialization. | 120 // Fake ShellClient initialization. |
| 125 shell::mojom::ShellClient* shell_client = shell_connection_.get(); | 121 shell::mojom::ShellClient* shell_client = shell_connection_.get(); |
| 126 shell_client->Initialize(std::move(g_connector), g_name, g_user_id, g_id); | 122 shell_client->Initialize(std::move(g_connector), std::move(g_identity), g_id); |
| 127 } | 123 } |
| 128 | 124 |
| 129 TestHelper::~TestHelper() { | 125 TestHelper::~TestHelper() { |
| 130 // We may have supplied a member as the client. Delete |shell_connection_| | 126 // We may have supplied a member as the client. Delete |shell_connection_| |
| 131 // while still valid. | 127 // while still valid. |
| 132 shell_connection_.reset(); | 128 shell_connection_.reset(); |
| 133 } | 129 } |
| 134 | 130 |
| 135 ApplicationTestBase::ApplicationTestBase() : test_helper_(nullptr) {} | 131 ApplicationTestBase::ApplicationTestBase() : test_helper_(nullptr) {} |
| 136 | 132 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 163 if (ShouldCreateDefaultRunLoop()) | 159 if (ShouldCreateDefaultRunLoop()) |
| 164 Environment::DestroyDefaultRunLoop(); | 160 Environment::DestroyDefaultRunLoop(); |
| 165 } | 161 } |
| 166 | 162 |
| 167 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 163 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
| 168 return true; | 164 return true; |
| 169 } | 165 } |
| 170 | 166 |
| 171 } // namespace test | 167 } // namespace test |
| 172 } // namespace mojo | 168 } // namespace mojo |
| OLD | NEW |