| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "mojo/public/cpp/bindings/binding.h" | 9 #include "mojo/public/cpp/bindings/binding.h" |
| 10 #include "mojo/public/cpp/environment/environment.h" | 10 #include "mojo/public/cpp/environment/environment.h" |
| 11 #include "mojo/public/cpp/system/message_pipe.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
| 12 #include "mojo/shell/public/cpp/application_impl.h" | 12 #include "mojo/shell/public/cpp/application_impl.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/interfaces/application.mojom.h" | 14 #include "mojo/shell/public/interfaces/application.mojom.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace test { | 17 namespace test { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 // Share the application URL with multiple application tests. | 20 // Share the application URL with multiple application tests. |
| 21 String g_url; | 21 String g_url; |
| 22 uint32_t g_id = Shell::kInvalidApplicationID; |
| 22 | 23 |
| 23 // Application request handle passed from the shell in MojoMain, stored in | 24 // Application request handle passed from the shell in MojoMain, stored in |
| 24 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. | 25 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. |
| 25 InterfaceRequest<Application> g_application_request; | 26 InterfaceRequest<Application> g_application_request; |
| 26 | 27 |
| 27 // Shell pointer passed in the initial mojo.Application.Initialize() call, | 28 // Shell pointer passed in the initial mojo.Application.Initialize() call, |
| 28 // stored in between initial setup and the first test and between SetUp/TearDown | 29 // stored in between initial setup and the first test and between SetUp/TearDown |
| 29 // calls so we can (re-)initialize new ApplicationImpls. | 30 // calls so we can (re-)initialize new ApplicationImpls. |
| 30 ShellPtr g_shell; | 31 ShellPtr g_shell; |
| 31 | 32 |
| 32 class ShellGrabber : public Application { | 33 class ShellGrabber : public Application { |
| 33 public: | 34 public: |
| 34 explicit ShellGrabber(InterfaceRequest<Application> application_request) | 35 explicit ShellGrabber(InterfaceRequest<Application> application_request) |
| 35 : binding_(this, std::move(application_request)) {} | 36 : binding_(this, std::move(application_request)) {} |
| 36 | 37 |
| 37 void WaitForInitialize() { | 38 void WaitForInitialize() { |
| 38 // Initialize is always the first call made on Application. | 39 // Initialize is always the first call made on Application. |
| 39 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); | 40 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); |
| 40 } | 41 } |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 // Application implementation. | 44 // Application implementation. |
| 44 void Initialize(ShellPtr shell, const mojo::String& url) override { | 45 void Initialize(ShellPtr shell, |
| 46 const mojo::String& url, |
| 47 uint32_t id) override { |
| 45 g_url = url; | 48 g_url = url; |
| 49 g_id = id; |
| 46 g_application_request = binding_.Unbind(); | 50 g_application_request = binding_.Unbind(); |
| 47 g_shell = std::move(shell); | 51 g_shell = std::move(shell); |
| 48 } | 52 } |
| 49 | 53 |
| 50 void AcceptConnection(const String& requestor_url, | 54 void AcceptConnection(const String& requestor_url, |
| 55 uint32_t requestor_id, |
| 51 InterfaceRequest<ServiceProvider> services, | 56 InterfaceRequest<ServiceProvider> services, |
| 52 ServiceProviderPtr exposed_services, | 57 ServiceProviderPtr exposed_services, |
| 53 Array<String> allowed_interfaces, | 58 Array<String> allowed_interfaces, |
| 54 const String& url) override { | 59 const String& url) override { |
| 55 MOJO_CHECK(false); | 60 MOJO_CHECK(false); |
| 56 } | 61 } |
| 57 | 62 |
| 58 void OnQuitRequested(const Callback<void(bool)>& callback) override { | 63 void OnQuitRequested(const Callback<void(bool)>& callback) override { |
| 59 MOJO_CHECK(false); | 64 MOJO_CHECK(false); |
| 60 } | 65 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 130 |
| 126 MOJO_CHECK(g_application_request.is_pending()); | 131 MOJO_CHECK(g_application_request.is_pending()); |
| 127 MOJO_CHECK(g_shell); | 132 MOJO_CHECK(g_shell); |
| 128 | 133 |
| 129 // New applications are constructed for each test to avoid persisting state. | 134 // New applications are constructed for each test to avoid persisting state. |
| 130 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), | 135 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), |
| 131 std::move(g_application_request)); | 136 std::move(g_application_request)); |
| 132 | 137 |
| 133 // Fake application initialization. | 138 // Fake application initialization. |
| 134 Application* application = application_impl_; | 139 Application* application = application_impl_; |
| 135 application->Initialize(std::move(g_shell), g_url); | 140 application->Initialize(std::move(g_shell), g_url, g_id); |
| 136 } | 141 } |
| 137 | 142 |
| 138 void ApplicationTestBase::TearDown() { | 143 void ApplicationTestBase::TearDown() { |
| 139 MOJO_CHECK(!g_application_request.is_pending()); | 144 MOJO_CHECK(!g_application_request.is_pending()); |
| 140 MOJO_CHECK(!g_shell); | 145 MOJO_CHECK(!g_shell); |
| 141 | 146 |
| 142 // TODO: commented out until http://crbug.com/533107 is solved. | 147 // TODO: commented out until http://crbug.com/533107 is solved. |
| 143 // { | 148 // { |
| 144 // ApplicationImpl::TestApi test_api(application_impl_); | 149 // ApplicationImpl::TestApi test_api(application_impl_); |
| 145 // test_api.UnbindConnections(&g_application_request, &g_shell); | 150 // test_api.UnbindConnections(&g_application_request, &g_shell); |
| 146 // } | 151 // } |
| 147 delete application_impl_; | 152 delete application_impl_; |
| 148 if (ShouldCreateDefaultRunLoop()) | 153 if (ShouldCreateDefaultRunLoop()) |
| 149 Environment::DestroyDefaultRunLoop(); | 154 Environment::DestroyDefaultRunLoop(); |
| 150 } | 155 } |
| 151 | 156 |
| 152 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 157 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
| 153 return true; | 158 return true; |
| 154 } | 159 } |
| 155 | 160 |
| 156 | 161 |
| 157 } // namespace test | 162 } // namespace test |
| 158 } // namespace mojo | 163 } // namespace mojo |
| OLD | NEW |