| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
| 13 #include "mojo/public/cpp/system/message_pipe.h" | 13 #include "mojo/public/cpp/system/message_pipe.h" |
| 14 #include "services/shell/public/cpp/application_test_base.h" | 14 #include "services/shell/public/cpp/application_test_base.h" |
| 15 #include "services/shell/public/cpp/shell_connection.h" | 15 #include "services/shell/public/cpp/shell_connection.h" |
| 16 #include "services/shell/public/interfaces/shell_client.mojom.h" | 16 #include "services/shell/public/interfaces/shell_client.mojom.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace shell { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Share the application name with multiple application tests. | 23 // Share the application name with multiple application tests. |
| 24 shell::mojom::IdentityPtr g_identity; | 24 mojom::IdentityPtr g_identity; |
| 25 uint32_t g_id = shell::mojom::kInvalidInstanceID; | 25 uint32_t g_id = mojom::kInvalidInstanceID; |
| 26 | 26 |
| 27 // ShellClient request handle passed from the shell in MojoMain, stored in | 27 // ShellClient request handle passed from the shell in MojoMain, stored in |
| 28 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections. | 28 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections. |
| 29 InterfaceRequest<shell::mojom::ShellClient> g_shell_client_request; | 29 mojom::ShellClientRequest g_shell_client_request; |
| 30 | 30 |
| 31 // Connector pointer passed in the initial mojo.ShellClient.Initialize() call, | 31 // Connector pointer passed in the initial mojo.ShellClient.Initialize() call, |
| 32 // stored in between initial setup and the first test and between SetUp/TearDown | 32 // stored in between initial setup and the first test and between SetUp/TearDown |
| 33 // calls so we can (re-)initialize new ShellConnections. | 33 // calls so we can (re-)initialize new ShellConnections. |
| 34 shell::mojom::ConnectorPtr g_connector; | 34 mojom::ConnectorPtr g_connector; |
| 35 | 35 |
| 36 class ShellGrabber : public shell::mojom::ShellClient { | 36 class ShellGrabber : public mojom::ShellClient { |
| 37 public: | 37 public: |
| 38 explicit ShellGrabber(InterfaceRequest<shell::mojom::ShellClient> request) | 38 explicit ShellGrabber(mojom::ShellClientRequest request) |
| 39 : binding_(this, std::move(request)) { | 39 : binding_(this, std::move(request)) { |
| 40 binding_.set_connection_error_handler([] { _exit(1); }); | 40 binding_.set_connection_error_handler([] { _exit(1); }); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void WaitForInitialize() { | 43 void WaitForInitialize() { |
| 44 // Initialize is always the first call made on ShellClient. | 44 // Initialize is always the first call made on ShellClient. |
| 45 CHECK(binding_.WaitForIncomingMethodCall()); | 45 CHECK(binding_.WaitForIncomingMethodCall()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 // shell::mojom::ShellClient implementation. | 49 // mojom::ShellClient implementation. |
| 50 void Initialize(shell::mojom::IdentityPtr identity, | 50 void Initialize(mojom::IdentityPtr identity, |
| 51 uint32_t id, | 51 uint32_t id, |
| 52 const InitializeCallback& callback) override { | 52 const InitializeCallback& callback) override { |
| 53 callback.Run(GetProxy(&g_connector)); | 53 callback.Run(GetProxy(&g_connector)); |
| 54 | 54 |
| 55 g_identity = std::move(identity); | 55 g_identity = std::move(identity); |
| 56 g_id = id; | 56 g_id = id; |
| 57 g_shell_client_request = binding_.Unbind(); | 57 g_shell_client_request = binding_.Unbind(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void AcceptConnection( | 60 void AcceptConnection(mojom::IdentityPtr source, |
| 61 shell::mojom::IdentityPtr source, | 61 uint32_t source_id, |
| 62 uint32_t source_id, | 62 mojom::InterfaceProviderRequest local_interfaces, |
| 63 shell::mojom::InterfaceProviderRequest local_interfaces, | 63 mojom::InterfaceProviderPtr remote_interfaces, |
| 64 shell::mojom::InterfaceProviderPtr remote_interfaces, | 64 mojom::CapabilityRequestPtr capability_spec, |
| 65 shell::mojom::CapabilityRequestPtr capability_spec, | 65 const mojo::String& name) override { |
| 66 const String& name) override { | |
| 67 CHECK(false); | 66 CHECK(false); |
| 68 } | 67 } |
| 69 | 68 |
| 70 Binding<ShellClient> binding_; | 69 mojo::Binding<ShellClient> binding_; |
| 71 }; | 70 }; |
| 72 | 71 |
| 73 void IgnoreConnectorRequest(shell::mojom::ConnectorRequest) {} | 72 void IgnoreConnectorRequest(mojom::ConnectorRequest) {} |
| 74 | 73 |
| 75 } // namespace | 74 } // namespace |
| 76 | 75 |
| 77 MojoResult RunAllTests(MojoHandle shell_client_request_handle) { | 76 MojoResult RunAllTests(MojoHandle shell_client_request_handle) { |
| 78 { | 77 { |
| 79 // This loop is used for init, and then destroyed before running tests. | 78 // This loop is used for init, and then destroyed before running tests. |
| 80 base::MessageLoop message_loop; | 79 base::MessageLoop message_loop; |
| 81 | 80 |
| 82 // Grab the shell handle. | 81 // Grab the shell handle. |
| 83 ShellGrabber grabber( | 82 ShellGrabber grabber( |
| 84 MakeRequest<shell::mojom::ShellClient>(MakeScopedHandle( | 83 mojo::MakeRequest<mojom::ShellClient>(mojo::MakeScopedHandle( |
| 85 MessagePipeHandle(shell_client_request_handle)))); | 84 mojo::MessagePipeHandle(shell_client_request_handle)))); |
| 86 grabber.WaitForInitialize(); | 85 grabber.WaitForInitialize(); |
| 87 CHECK(g_connector); | 86 CHECK(g_connector); |
| 88 CHECK(g_shell_client_request.is_pending()); | 87 CHECK(g_shell_client_request.is_pending()); |
| 89 | 88 |
| 90 int argc = 0; | 89 int argc = 0; |
| 91 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 90 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 92 const char** argv = new const char* [cmd_line->argv().size() + 1]; | 91 const char** argv = new const char* [cmd_line->argv().size() + 1]; |
| 93 #if defined(OS_WIN) | 92 #if defined(OS_WIN) |
| 94 std::vector<std::string> local_strings; | 93 std::vector<std::string> local_strings; |
| 95 #endif | 94 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 118 TestHelper::TestHelper(ShellClient* client) | 117 TestHelper::TestHelper(ShellClient* client) |
| 119 : shell_connection_(new ShellConnection( | 118 : shell_connection_(new ShellConnection( |
| 120 client == nullptr ? &default_shell_client_ : client, | 119 client == nullptr ? &default_shell_client_ : client, |
| 121 std::move(g_shell_client_request))), | 120 std::move(g_shell_client_request))), |
| 122 name_(g_identity->name), | 121 name_(g_identity->name), |
| 123 userid_(g_identity->user_id), | 122 userid_(g_identity->user_id), |
| 124 instance_id_(g_id) { | 123 instance_id_(g_id) { |
| 125 shell_connection_->SetAppTestConnectorForTesting(std::move(g_connector)); | 124 shell_connection_->SetAppTestConnectorForTesting(std::move(g_connector)); |
| 126 | 125 |
| 127 // Fake ShellClient initialization. | 126 // Fake ShellClient initialization. |
| 128 shell::mojom::ShellClient* shell_client = shell_connection_.get(); | 127 mojom::ShellClient* shell_client = shell_connection_.get(); |
| 129 shell_client->Initialize(std::move(g_identity), g_id, | 128 shell_client->Initialize(std::move(g_identity), g_id, |
| 130 base::Bind(&IgnoreConnectorRequest)); | 129 base::Bind(&IgnoreConnectorRequest)); |
| 131 } | 130 } |
| 132 | 131 |
| 133 TestHelper::~TestHelper() { | 132 TestHelper::~TestHelper() { |
| 134 // We may have supplied a member as the client. Delete |shell_connection_| | 133 // We may have supplied a member as the client. Delete |shell_connection_| |
| 135 // while still valid. | 134 // while still valid. |
| 136 shell_connection_.reset(); | 135 shell_connection_.reset(); |
| 137 } | 136 } |
| 138 | 137 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 delete base::MessageLoop::current(); | 172 delete base::MessageLoop::current(); |
| 174 CHECK(!base::MessageLoop::current()); | 173 CHECK(!base::MessageLoop::current()); |
| 175 } | 174 } |
| 176 } | 175 } |
| 177 | 176 |
| 178 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 177 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
| 179 return true; | 178 return true; |
| 180 } | 179 } |
| 181 | 180 |
| 182 } // namespace test | 181 } // namespace test |
| 183 } // namespace mojo | 182 } // namespace shell |
| OLD | NEW |