Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: mojo/public/cpp/application/lib/application_test_base.cc

Issue 996533002: Remove hardcoded tests URLs from apptests. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 String g_url;
viettrungluu 2015/03/10 15:31:52 No comment? (Also, the seemingly-random order of
Nick Bray (chromium) 2015/03/10 19:39:00 Done.
21
20 // Application request handle passed from the shell in MojoMain, stored in 22 // Application request handle passed from the shell in MojoMain, stored in
21 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. 23 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls.
22 InterfaceRequest<Application> g_application_request; 24 InterfaceRequest<Application> g_application_request;
23 25
24 // Shell pointer passed in the initial mojo.Application.Initialize() call, 26 // Shell pointer passed in the initial mojo.Application.Initialize() call,
25 // stored in between initial setup and the first test and between SetUp/TearDown 27 // stored in between initial setup and the first test and between SetUp/TearDown
26 // calls so we can (re-)initialize new ApplicationImpls. 28 // calls so we can (re-)initialize new ApplicationImpls.
27 ShellPtr g_shell; 29 ShellPtr g_shell;
28 30
29 void InitializeArgs(int argc, std::vector<const char*> argv) { 31 void InitializeArgs(int argc, std::vector<const char*> argv) {
(...skipping 14 matching lines...) Expand all
44 // Initialize is always the first call made on Application. 46 // Initialize is always the first call made on Application.
45 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); 47 MOJO_CHECK(binding_.WaitForIncomingMethodCall());
46 } 48 }
47 49
48 private: 50 private:
49 // Application implementation. 51 // Application implementation.
50 void Initialize(ShellPtr shell, 52 void Initialize(ShellPtr shell,
51 Array<String> args, 53 Array<String> args,
52 const mojo::String& url) override { 54 const mojo::String& url) override {
53 *args_ = args.Pass(); 55 *args_ = args.Pass();
56 g_url = url;
54 g_application_request = binding_.Unbind(); 57 g_application_request = binding_.Unbind();
55 g_shell = shell.Pass(); 58 g_shell = shell.Pass();
56 } 59 }
57 60
58 void AcceptConnection(const String& requestor_url, 61 void AcceptConnection(const String& requestor_url,
59 InterfaceRequest<ServiceProvider> services, 62 InterfaceRequest<ServiceProvider> services,
60 ServiceProviderPtr exposed_services, 63 ServiceProviderPtr exposed_services,
61 const String& url) override { 64 const String& url) override {
62 MOJO_CHECK(false); 65 MOJO_CHECK(false);
63 } 66 }
64 67
65 void RequestQuit() override { MOJO_CHECK(false); } 68 void RequestQuit() override { MOJO_CHECK(false); }
66 69
67 Array<String>* args_; 70 Array<String>* args_;
68 Binding<Application> binding_; 71 Binding<Application> binding_;
69 }; 72 };
70 73
71 } // namespace 74 } // namespace
72 75
73 const Array<String>& Args() { 76 const Array<String>& Args() {
74 return g_args; 77 return g_args;
75 } 78 }
76 79
80 const String& Url() {
81 return g_url;
82 }
83
77 MojoResult RunAllTests(MojoHandle application_request_handle) { 84 MojoResult RunAllTests(MojoHandle application_request_handle) {
78 { 85 {
79 // This loop is used for init, and then destroyed before running tests. 86 // This loop is used for init, and then destroyed before running tests.
80 Environment::InstantiateDefaultRunLoop(); 87 Environment::InstantiateDefaultRunLoop();
81 88
82 // Grab the shell handle and GTEST commandline arguments. 89 // Grab the shell handle and GTEST commandline arguments.
83 // GTEST command line arguments are supported amid application arguments: 90 // GTEST command line arguments are supported amid application arguments:
84 // $ mojo_shell mojo:example_apptests 91 // $ mojo_shell mojo:example_apptests
85 // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2' 92 // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2'
86 Array<String> args; 93 Array<String> args;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 Environment::InstantiateDefaultRunLoop(); 140 Environment::InstantiateDefaultRunLoop();
134 141
135 MOJO_CHECK(g_application_request.is_pending()); 142 MOJO_CHECK(g_application_request.is_pending());
136 MOJO_CHECK(g_shell); 143 MOJO_CHECK(g_shell);
137 144
138 // New applications are constructed for each test to avoid persisting state. 145 // New applications are constructed for each test to avoid persisting state.
139 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), 146 application_impl_ = new ApplicationImpl(GetApplicationDelegate(),
140 g_application_request.Pass()); 147 g_application_request.Pass());
141 148
142 // Fake application initialization with the given command line arguments. 149 // Fake application initialization with the given command line arguments.
143 application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), ""); 150 application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), g_url);
viettrungluu 2015/03/10 15:31:52 I agree that this is probably right, and that pass
144 } 151 }
145 152
146 void ApplicationTestBase::TearDown() { 153 void ApplicationTestBase::TearDown() {
147 MOJO_CHECK(!g_application_request.is_pending()); 154 MOJO_CHECK(!g_application_request.is_pending());
148 MOJO_CHECK(!g_shell); 155 MOJO_CHECK(!g_shell);
149 156
150 application_impl_->UnbindConnections(&g_application_request, &g_shell); 157 application_impl_->UnbindConnections(&g_application_request, &g_shell);
151 delete application_impl_; 158 delete application_impl_;
152 if (ShouldCreateDefaultRunLoop()) 159 if (ShouldCreateDefaultRunLoop())
153 Environment::DestroyDefaultRunLoop(); 160 Environment::DestroyDefaultRunLoop();
154 } 161 }
155 162
156 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { 163 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() {
157 return true; 164 return true;
158 } 165 }
159 166
160 } // namespace test 167 } // namespace test
161 } // namespace mojo 168 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698