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 "mojo/public/cpp/application/application_test_base.h" | 5 #include "mojo/public/cpp/application/application_test_base.h" |
6 | 6 |
7 #include "mojo/public/cpp/application/application_impl.h" | 7 #include "mojo/public/cpp/application/application_impl.h" |
8 #include "mojo/public/cpp/bindings/binding.h" | 8 #include "mojo/public/cpp/bindings/binding.h" |
9 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
10 #include "mojo/public/cpp/system/message_pipe.h" | 10 #include "mojo/public/cpp/system/message_pipe.h" |
11 #include "mojo/public/interfaces/application/application.mojom.h" | 11 #include "mojo/public/interfaces/application/application.mojom.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace test { | 14 namespace test { |
15 | 15 |
16 namespace { | 16 namespace { |
17 // Share the application command-line arguments with multiple application tests. | 17 // Share the application command-line arguments with multiple application tests. |
18 Array<String> g_args; | 18 Array<String> g_args; |
19 | 19 |
| 20 // Share the application URL with multiple application tests. |
| 21 String g_url; |
| 22 |
20 // Application request handle passed from the shell in MojoMain, stored in | 23 // Application request handle passed from the shell in MojoMain, stored in |
21 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. | 24 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. |
22 InterfaceRequest<Application> g_application_request; | 25 InterfaceRequest<Application> g_application_request; |
23 | 26 |
24 // Shell pointer passed in the initial mojo.Application.Initialize() call, | 27 // Shell pointer passed in the initial mojo.Application.Initialize() call, |
25 // stored in between initial setup and the first test and between SetUp/TearDown | 28 // stored in between initial setup and the first test and between SetUp/TearDown |
26 // calls so we can (re-)initialize new ApplicationImpls. | 29 // calls so we can (re-)initialize new ApplicationImpls. |
27 ShellPtr g_shell; | 30 ShellPtr g_shell; |
28 | 31 |
29 void InitializeArgs(int argc, std::vector<const char*> argv) { | 32 void InitializeArgs(int argc, std::vector<const char*> argv) { |
(...skipping 14 matching lines...) Expand all Loading... |
44 // Initialize is always the first call made on Application. | 47 // Initialize is always the first call made on Application. |
45 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); | 48 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); |
46 } | 49 } |
47 | 50 |
48 private: | 51 private: |
49 // Application implementation. | 52 // Application implementation. |
50 void Initialize(ShellPtr shell, | 53 void Initialize(ShellPtr shell, |
51 Array<String> args, | 54 Array<String> args, |
52 const mojo::String& url) override { | 55 const mojo::String& url) override { |
53 *args_ = args.Pass(); | 56 *args_ = args.Pass(); |
| 57 g_url = url; |
54 g_application_request = binding_.Unbind(); | 58 g_application_request = binding_.Unbind(); |
55 g_shell = shell.Pass(); | 59 g_shell = shell.Pass(); |
56 } | 60 } |
57 | 61 |
58 void AcceptConnection(const String& requestor_url, | 62 void AcceptConnection(const String& requestor_url, |
59 InterfaceRequest<ServiceProvider> services, | 63 InterfaceRequest<ServiceProvider> services, |
60 ServiceProviderPtr exposed_services, | 64 ServiceProviderPtr exposed_services, |
61 const String& url) override { | 65 const String& url) override { |
62 MOJO_CHECK(false); | 66 MOJO_CHECK(false); |
63 } | 67 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 Environment::InstantiateDefaultRunLoop(); | 137 Environment::InstantiateDefaultRunLoop(); |
134 | 138 |
135 MOJO_CHECK(g_application_request.is_pending()); | 139 MOJO_CHECK(g_application_request.is_pending()); |
136 MOJO_CHECK(g_shell); | 140 MOJO_CHECK(g_shell); |
137 | 141 |
138 // New applications are constructed for each test to avoid persisting state. | 142 // New applications are constructed for each test to avoid persisting state. |
139 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), | 143 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), |
140 g_application_request.Pass()); | 144 g_application_request.Pass()); |
141 | 145 |
142 // Fake application initialization with the given command line arguments. | 146 // Fake application initialization with the given command line arguments. |
143 application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), ""); | 147 application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), g_url); |
144 } | 148 } |
145 | 149 |
146 void ApplicationTestBase::TearDown() { | 150 void ApplicationTestBase::TearDown() { |
147 MOJO_CHECK(!g_application_request.is_pending()); | 151 MOJO_CHECK(!g_application_request.is_pending()); |
148 MOJO_CHECK(!g_shell); | 152 MOJO_CHECK(!g_shell); |
149 | 153 |
150 application_impl_->UnbindConnections(&g_application_request, &g_shell); | 154 application_impl_->UnbindConnections(&g_application_request, &g_shell); |
151 delete application_impl_; | 155 delete application_impl_; |
152 if (ShouldCreateDefaultRunLoop()) | 156 if (ShouldCreateDefaultRunLoop()) |
153 Environment::DestroyDefaultRunLoop(); | 157 Environment::DestroyDefaultRunLoop(); |
154 } | 158 } |
155 | 159 |
156 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 160 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
157 return true; | 161 return true; |
158 } | 162 } |
159 | 163 |
160 } // namespace test | 164 } // namespace test |
161 } // namespace mojo | 165 } // namespace mojo |
OLD | NEW |