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

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

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/process/launch.h" 11 #include "base/process/launch.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "chrome/test/base/chrome_test_launcher.h" 13 #include "chrome/test/base/chrome_test_launcher.h"
14 #include "chrome/test/base/chrome_test_suite.h" 14 #include "chrome/test/base/chrome_test_suite.h"
15 #include "chrome/test/base/mojo_test_connector.h" 15 #include "chrome/test/base/mojo_test_connector.h"
16 #include "content/public/common/mojo_shell_connection.h" 16 #include "content/public/common/mojo_shell_connection.h"
17 #include "content/public/test/test_launcher.h" 17 #include "content/public/test/test_launcher.h"
18 #include "services/shell/public/cpp/connector.h" 18 #include "services/shell/public/cpp/connector.h"
19 #include "services/shell/public/cpp/shell_client.h" 19 #include "services/shell/public/cpp/shell_client.h"
20 #include "services/shell/public/cpp/shell_connection.h" 20 #include "services/shell/public/cpp/shell_connection.h"
21 #include "services/shell/runner/common/switches.h" 21 #include "services/shell/runner/common/switches.h"
22 #include "services/shell/runner/host/child_process.h" 22 #include "services/shell/runner/host/child_process.h"
23 #include "services/shell/runner/init.h" 23 #include "services/shell/runner/init.h"
24 24
25 namespace { 25 namespace {
26 26
27 void ConnectToDefaultApps(mojo::Connector* connector) { 27 void ConnectToDefaultApps(shell::Connector* connector) {
28 connector->Connect("mojo:mash_session"); 28 connector->Connect("mojo:mash_session");
29 } 29 }
30 30
31 class MashTestSuite : public ChromeTestSuite { 31 class MashTestSuite : public ChromeTestSuite {
32 public: 32 public:
33 MashTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {} 33 MashTestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) {}
34 34
35 void SetMojoTestConnector(std::unique_ptr<MojoTestConnector> connector) { 35 void SetMojoTestConnector(std::unique_ptr<MojoTestConnector> connector) {
36 mojo_test_connector_ = std::move(connector); 36 mojo_test_connector_ = std::move(connector);
37 } 37 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 test_suite_.reset(new MashTestSuite(argc, argv)); 73 test_suite_.reset(new MashTestSuite(argc, argv));
74 const int result = test_suite_->Run(); 74 const int result = test_suite_->Run();
75 test_suite_.reset(); 75 test_suite_.reset();
76 return result; 76 return result;
77 } 77 }
78 std::unique_ptr<content::TestState> PreRunTest( 78 std::unique_ptr<content::TestState> PreRunTest(
79 base::CommandLine* command_line, 79 base::CommandLine* command_line,
80 base::TestLauncher::LaunchOptions* test_launch_options) override { 80 base::TestLauncher::LaunchOptions* test_launch_options) override {
81 if (!mojo_test_connector_) { 81 if (!mojo_test_connector_) {
82 mojo_test_connector_.reset(new MojoTestConnector); 82 mojo_test_connector_.reset(new MojoTestConnector);
83 shell_client_.reset(new mojo::ShellClient); 83 shell_client_.reset(new shell::ShellClient);
84 shell_connection_.reset(new mojo::ShellConnection( 84 shell_connection_.reset(new shell::ShellConnection(
85 shell_client_.get(), mojo_test_connector_->Init())); 85 shell_client_.get(), mojo_test_connector_->Init()));
86 ConnectToDefaultApps(shell_connection_->connector()); 86 ConnectToDefaultApps(shell_connection_->connector());
87 } 87 }
88 return mojo_test_connector_->PrepareForTest(command_line, 88 return mojo_test_connector_->PrepareForTest(command_line,
89 test_launch_options); 89 test_launch_options);
90 } 90 }
91 void OnDoneRunningTests() override { 91 void OnDoneRunningTests() override {
92 // We have to shutdown this state here, while an AtExitManager is still 92 // We have to shutdown this state here, while an AtExitManager is still
93 // valid. 93 // valid.
94 shell_connection_.reset(); 94 shell_connection_.reset();
95 shell_client_.reset(); 95 shell_client_.reset();
96 mojo_test_connector_.reset(); 96 mojo_test_connector_.reset();
97 } 97 }
98 98
99 std::unique_ptr<MashTestSuite> test_suite_; 99 std::unique_ptr<MashTestSuite> test_suite_;
100 std::unique_ptr<MojoTestConnector> mojo_test_connector_; 100 std::unique_ptr<MojoTestConnector> mojo_test_connector_;
101 std::unique_ptr<mojo::ShellClient> shell_client_; 101 std::unique_ptr<shell::ShellClient> shell_client_;
102 std::unique_ptr<mojo::ShellConnection> shell_connection_; 102 std::unique_ptr<shell::ShellConnection> shell_connection_;
103 103
104 DISALLOW_COPY_AND_ASSIGN(MashTestLauncherDelegate); 104 DISALLOW_COPY_AND_ASSIGN(MashTestLauncherDelegate);
105 }; 105 };
106 106
107 void CreateMojoShellConnection(MashTestLauncherDelegate* delegate) { 107 void CreateMojoShellConnection(MashTestLauncherDelegate* delegate) {
108 const bool is_external_shell = true; 108 const bool is_external_shell = true;
109 content::MojoShellConnection::Create( 109 content::MojoShellConnection::Create(
110 delegate->GetMojoTestConnectorForSingleProcess()->Init(), 110 delegate->GetMojoTestConnectorForSingleProcess()->Init(),
111 is_external_shell); 111 is_external_shell);
112 ConnectToDefaultApps(content::MojoShellConnection::Get()->GetConnector()); 112 ConnectToDefaultApps(content::MojoShellConnection::Get()->GetConnector());
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 116
117 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) { 117 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) {
118 base::CommandLine::Init(argc, argv); 118 base::CommandLine::Init(argc, argv);
119 const base::CommandLine& command_line = 119 const base::CommandLine& command_line =
120 *base::CommandLine::ForCurrentProcess(); 120 *base::CommandLine::ForCurrentProcess();
121 if (!command_line.HasSwitch("run-in-mash")) 121 if (!command_line.HasSwitch("run-in-mash"))
122 return false; 122 return false;
123 123
124 if (command_line.HasSwitch(switches::kChildProcess) && 124 if (command_line.HasSwitch(switches::kChildProcess) &&
125 !command_line.HasSwitch(MojoTestConnector::kTestSwitch)) { 125 !command_line.HasSwitch(MojoTestConnector::kTestSwitch)) {
126 base::AtExitManager at_exit; 126 base::AtExitManager at_exit;
127 mojo::shell::InitializeLogging(); 127 shell::InitializeLogging();
128 mojo::shell::WaitForDebuggerIfNecessary(); 128 shell::WaitForDebuggerIfNecessary();
129 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) 129 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN)
130 base::RouteStdioToConsole(false); 130 base::RouteStdioToConsole(false);
131 #endif 131 #endif
132 *exit_code = mojo::shell::ChildProcessMain(); 132 *exit_code = shell::ChildProcessMain();
133 return true; 133 return true;
134 } 134 }
135 135
136 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); 136 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
137 MashTestLauncherDelegate delegate; 137 MashTestLauncherDelegate delegate;
138 // --single_process and no primoridal pipe token indicate we were run directly 138 // --single_process and no primoridal pipe token indicate we were run directly
139 // from the command line. In this case we have to start up MojoShellConnection 139 // from the command line. In this case we have to start up MojoShellConnection
140 // as though we were embedded. 140 // as though we were embedded.
141 content::MojoShellConnection::Factory shell_connection_factory; 141 content::MojoShellConnection::Factory shell_connection_factory;
142 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && 142 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) &&
143 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { 143 !command_line.HasSwitch(switches::kPrimordialPipeToken)) {
144 shell_connection_factory = 144 shell_connection_factory =
145 base::Bind(&CreateMojoShellConnection, &delegate); 145 base::Bind(&CreateMojoShellConnection, &delegate);
146 content::MojoShellConnection::SetFactoryForTest(&shell_connection_factory); 146 content::MojoShellConnection::SetFactoryForTest(&shell_connection_factory);
147 } 147 }
148 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); 148 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv);
149 return true; 149 return true;
150 } 150 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc ('k') | chrome/test/base/mojo_test_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698