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

Side by Side Diff: chrome/test/base/mash_browser_tests_main.cc

Issue 2834693002: Mus Browser Tests (Closed)
Patch Set: Address Comments Created 3 years, 8 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
« no previous file with comments | « chrome/test/BUILD.gn ('k') | chrome/test/base/mojo_test_connector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/debugger.h" 9 #include "base/debug/debugger.h"
10 #include "base/debug/stack_trace.h" 10 #include "base/debug/stack_trace.h"
(...skipping 22 matching lines...) Expand all
33 #include "services/service_manager/public/cpp/service_context.h" 33 #include "services/service_manager/public/cpp/service_context.h"
34 #include "services/service_manager/public/cpp/service_runner.h" 34 #include "services/service_manager/public/cpp/service_runner.h"
35 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h" 35 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h"
36 #include "services/service_manager/runner/common/switches.h" 36 #include "services/service_manager/runner/common/switches.h"
37 #include "services/service_manager/runner/init.h" 37 #include "services/service_manager/runner/init.h"
38 #include "services/ui/common/switches.h" 38 #include "services/ui/common/switches.h"
39 #include "ui/aura/env.h" 39 #include "ui/aura/env.h"
40 40
41 namespace { 41 namespace {
42 42
43 const base::FilePath::CharType kCatalogFilename[] = 43 const base::FilePath::CharType kMashCatalogFilename[] =
44 FILE_PATH_LITERAL("mash_browser_tests_catalog.json"); 44 FILE_PATH_LITERAL("mash_browser_tests_catalog.json");
45 const base::FilePath::CharType kMusCatalogFilename[] =
46 FILE_PATH_LITERAL("mus_browser_tests_catalog.json");
45 47
46 void ConnectToDefaultApps(service_manager::Connector* connector) { 48 void ConnectToDefaultApps(service_manager::Connector* connector) {
47 connector->StartService(mash::session::mojom::kServiceName); 49 connector->StartService(mash::session::mojom::kServiceName);
48 } 50 }
49 51
50 class MashTestSuite : public ChromeTestSuite { 52 class MashTestSuite : public ChromeTestSuite {
51 public: 53 public:
52 MashTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {} 54 MashTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {}
53 55
54 void SetMojoTestConnector(std::unique_ptr<MojoTestConnector> connector) { 56 void SetMojoTestConnector(std::unique_ptr<MojoTestConnector> connector) {
(...skipping 12 matching lines...) Expand all
67 } 69 }
68 70
69 std::unique_ptr<MojoTestConnector> mojo_test_connector_; 71 std::unique_ptr<MojoTestConnector> mojo_test_connector_;
70 72
71 DISALLOW_COPY_AND_ASSIGN(MashTestSuite); 73 DISALLOW_COPY_AND_ASSIGN(MashTestSuite);
72 }; 74 };
73 75
74 // Used to setup the command line for passing a mojo channel to tests. 76 // Used to setup the command line for passing a mojo channel to tests.
75 class MashTestLauncherDelegate : public ChromeTestLauncherDelegate { 77 class MashTestLauncherDelegate : public ChromeTestLauncherDelegate {
76 public: 78 public:
77 MashTestLauncherDelegate() : ChromeTestLauncherDelegate(nullptr) {} 79 MashTestLauncherDelegate() : ChromeTestLauncherDelegate(nullptr) {
80 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
81 config_ = command_line->HasSwitch("run-in-mash")
82 ? MojoTestConnector::Config::MASH
83 : MojoTestConnector::Config::MUS;
84 }
78 ~MashTestLauncherDelegate() override {} 85 ~MashTestLauncherDelegate() override {}
79 86
80 MojoTestConnector* GetMojoTestConnectorForSingleProcess() { 87 MojoTestConnector* GetMojoTestConnectorForSingleProcess() {
81 // This is only called for single process tests, in which case we need 88 // This is only called for single process tests, in which case we need
82 // the TestSuite to own the MojoTestConnector. 89 // the TestSuite to own the MojoTestConnector.
83 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 90 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
84 content::kSingleProcessTestsFlag)); 91 content::kSingleProcessTestsFlag));
85 DCHECK(test_suite_); 92 DCHECK(test_suite_);
86 test_suite_->SetMojoTestConnector( 93 test_suite_->SetMojoTestConnector(
87 base::MakeUnique<MojoTestConnector>(ReadCatalogManifest())); 94 base::MakeUnique<MojoTestConnector>(ReadCatalogManifest(), config_));
88 return test_suite_->mojo_test_connector(); 95 return test_suite_->mojo_test_connector();
89 } 96 }
90 97
91 private: 98 private:
92 // ChromeTestLauncherDelegate: 99 // ChromeTestLauncherDelegate:
93 int RunTestSuite(int argc, char** argv) override { 100 int RunTestSuite(int argc, char** argv) override {
94 test_suite_.reset(new MashTestSuite(argc, argv)); 101 test_suite_.reset(new MashTestSuite(argc, argv));
95 content::GetContentMainParams()->env_mode = aura::Env::Mode::MUS; 102 content::GetContentMainParams()->env_mode = aura::Env::Mode::MUS;
96 const int result = test_suite_->Run(); 103 const int result = test_suite_->Run();
97 test_suite_.reset(); 104 test_suite_.reset();
98 return result; 105 return result;
99 } 106 }
100 107
101 std::unique_ptr<content::TestState> PreRunTest( 108 std::unique_ptr<content::TestState> PreRunTest(
102 base::CommandLine* command_line, 109 base::CommandLine* command_line,
103 base::TestLauncher::LaunchOptions* test_launch_options) override { 110 base::TestLauncher::LaunchOptions* test_launch_options) override {
104 if (!mojo_test_connector_) { 111 if (!mojo_test_connector_) {
105 mojo_test_connector_ = 112 mojo_test_connector_ =
106 base::MakeUnique<MojoTestConnector>(ReadCatalogManifest()); 113 base::MakeUnique<MojoTestConnector>(ReadCatalogManifest(), config_);
107 context_.reset(new service_manager::ServiceContext( 114 context_.reset(new service_manager::ServiceContext(
108 base::MakeUnique<mash::MashPackagedService>(), 115 base::MakeUnique<mash::MashPackagedService>(),
109 mojo_test_connector_->Init())); 116 mojo_test_connector_->Init()));
110 } 117 }
111 std::unique_ptr<content::TestState> test_state = 118 std::unique_ptr<content::TestState> test_state =
112 mojo_test_connector_->PrepareForTest(command_line, test_launch_options); 119 mojo_test_connector_->PrepareForTest(command_line, test_launch_options);
113 120
114 // Start default apps after chrome, as they may try to connect to chrome on 121 // Start default apps after chrome, as they may try to connect to chrome on
115 // startup. Attempt to connect once per test in case a previous test crashed 122 // startup. Attempt to connect once per test in case a previous test crashed
116 // mash_session. 123 // mash_session.
117 ConnectToDefaultApps(context_->connector()); 124 ConnectToDefaultApps(context_->connector());
118 return test_state; 125 return test_state;
119 } 126 }
120 127
121 void OnDoneRunningTests() override { 128 void OnDoneRunningTests() override {
122 // We have to shutdown this state here, while an AtExitManager is still 129 // We have to shutdown this state here, while an AtExitManager is still
123 // valid. 130 // valid.
124 context_.reset(); 131 context_.reset();
125 mojo_test_connector_.reset(); 132 mojo_test_connector_.reset();
126 } 133 }
127 134
128 std::unique_ptr<base::Value> ReadCatalogManifest() { 135 std::unique_ptr<base::Value> ReadCatalogManifest() {
129 std::string catalog_contents; 136 std::string catalog_contents;
130 base::FilePath exe_path; 137 base::FilePath exe_path;
131 base::PathService::Get(base::DIR_EXE, &exe_path); 138 base::PathService::Get(base::DIR_EXE, &exe_path);
132 base::FilePath catalog_path = exe_path.Append(kCatalogFilename); 139 base::FilePath catalog_path = exe_path.Append(
140 config_ == MojoTestConnector::Config::MASH ? kMashCatalogFilename
141 : kMusCatalogFilename);
133 bool result = base::ReadFileToString(catalog_path, &catalog_contents); 142 bool result = base::ReadFileToString(catalog_path, &catalog_contents);
134 DCHECK(result); 143 DCHECK(result);
135 std::unique_ptr<base::Value> manifest_value = 144 std::unique_ptr<base::Value> manifest_value =
136 base::JSONReader::Read(catalog_contents); 145 base::JSONReader::Read(catalog_contents);
137 DCHECK(manifest_value); 146 DCHECK(manifest_value);
138 return manifest_value; 147 return manifest_value;
139 } 148 }
140 149
150 MojoTestConnector::Config config_;
151
141 std::unique_ptr<MashTestSuite> test_suite_; 152 std::unique_ptr<MashTestSuite> test_suite_;
142 std::unique_ptr<MojoTestConnector> mojo_test_connector_; 153 std::unique_ptr<MojoTestConnector> mojo_test_connector_;
143 std::unique_ptr<service_manager::ServiceContext> context_; 154 std::unique_ptr<service_manager::ServiceContext> context_;
144 155
145 DISALLOW_COPY_AND_ASSIGN(MashTestLauncherDelegate); 156 DISALLOW_COPY_AND_ASSIGN(MashTestLauncherDelegate);
146 }; 157 };
147 158
148 std::unique_ptr<content::ServiceManagerConnection> 159 std::unique_ptr<content::ServiceManagerConnection>
149 CreateServiceManagerConnection(MashTestLauncherDelegate* delegate) { 160 CreateServiceManagerConnection(MashTestLauncherDelegate* delegate) {
150 std::unique_ptr<content::ServiceManagerConnection> connection( 161 std::unique_ptr<content::ServiceManagerConnection> connection(
(...skipping 15 matching lines...) Expand all
166 std::move(service_request)); 177 std::move(service_request));
167 context.SetQuitClosure(run_loop.QuitClosure()); 178 context.SetQuitClosure(run_loop.QuitClosure());
168 run_loop.Run(); 179 run_loop.Run();
169 } 180 }
170 181
171 } // namespace 182 } // namespace
172 183
173 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) { 184 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) {
174 base::CommandLine::Init(argc, argv); 185 base::CommandLine::Init(argc, argv);
175 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 186 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
176 if (!command_line->HasSwitch("run-in-mash")) 187 if (!command_line->HasSwitch("run-in-mash") &&
188 !command_line->HasSwitch("run-in-mus")) {
177 return false; 189 return false;
190 }
178 191
179 if (command_line->HasSwitch(MojoTestConnector::kMashApp)) { 192 if (command_line->HasSwitch(MojoTestConnector::kMashApp)) {
180 #if defined(OS_LINUX) 193 #if defined(OS_LINUX)
181 base::AtExitManager exit_manager; 194 base::AtExitManager exit_manager;
182 #endif 195 #endif
183 base::i18n::InitializeICU(); 196 base::i18n::InitializeICU();
184 197
185 #if !defined(OFFICIAL_BUILD) 198 #if !defined(OFFICIAL_BUILD)
186 base::debug::EnableInProcessStackDumping(); 199 base::debug::EnableInProcessStackDumping();
187 #endif 200 #endif
(...skipping 14 matching lines...) Expand all
202 if (command_line->HasSwitch(content::kSingleProcessTestsFlag) && 215 if (command_line->HasSwitch(content::kSingleProcessTestsFlag) &&
203 !command_line->HasSwitch(switches::kPrimordialPipeToken)) { 216 !command_line->HasSwitch(switches::kPrimordialPipeToken)) {
204 service_manager_connection_factory = 217 service_manager_connection_factory =
205 base::Bind(&CreateServiceManagerConnection, &delegate); 218 base::Bind(&CreateServiceManagerConnection, &delegate);
206 content::ServiceManagerConnection::SetFactoryForTest( 219 content::ServiceManagerConnection::SetFactoryForTest(
207 &service_manager_connection_factory); 220 &service_manager_connection_factory);
208 } 221 }
209 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); 222 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv);
210 return true; 223 return true;
211 } 224 }
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | chrome/test/base/mojo_test_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698