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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 111 |
107 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; | 112 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; |
108 } | 113 } |
109 | 114 |
110 TestHelper::TestHelper(ApplicationDelegate* delegate) | 115 TestHelper::TestHelper(ApplicationDelegate* delegate) |
111 : application_impl_(new ApplicationImpl( | 116 : application_impl_(new ApplicationImpl( |
112 delegate == nullptr ? &default_application_delegate_ : delegate, | 117 delegate == nullptr ? &default_application_delegate_ : delegate, |
113 std::move(g_application_request))) { | 118 std::move(g_application_request))) { |
114 // Fake application initialization. | 119 // Fake application initialization. |
115 Application* application = application_impl_.get(); | 120 Application* application = application_impl_.get(); |
116 application->Initialize(std::move(g_shell), g_url); | 121 application->Initialize(std::move(g_shell), g_url, g_id); |
117 } | 122 } |
118 | 123 |
119 TestHelper::~TestHelper() { | 124 TestHelper::~TestHelper() { |
120 // TODO: commented out until http://crbug.com/533107 is solved. | 125 // TODO: commented out until http://crbug.com/533107 is solved. |
121 // { | 126 // { |
122 // ApplicationImpl::TestApi test_api(application_impl_); | 127 // ApplicationImpl::TestApi test_api(application_impl_); |
123 // test_api.UnbindConnections(&g_application_request, &g_shell); | 128 // test_api.UnbindConnections(&g_application_request, &g_shell); |
124 // } | 129 // } |
125 // We may have supplied a member as the delegate. Delete |application_impl_| | 130 // We may have supplied a member as the delegate. Delete |application_impl_| |
126 // while still valid. | 131 // while still valid. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (ShouldCreateDefaultRunLoop()) | 163 if (ShouldCreateDefaultRunLoop()) |
159 Environment::DestroyDefaultRunLoop(); | 164 Environment::DestroyDefaultRunLoop(); |
160 } | 165 } |
161 | 166 |
162 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 167 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
163 return true; | 168 return true; |
164 } | 169 } |
165 | 170 |
166 } // namespace test | 171 } // namespace test |
167 } // namespace mojo | 172 } // namespace mojo |
OLD | NEW |