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