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

Side by Side Diff: chrome/browser/service_process/service_process_control_browsertest.cc

Issue 2139643003: Use ChannelMojo between browser and service processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/service_process/service_process_control.h" 5 #include "chrome/browser/service_process/service_process_control.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/process/kill.h" 12 #include "base/process/kill.h"
13 #include "base/process/process.h" 13 #include "base/process/process.h"
14 #include "base/process/process_iterator.h" 14 #include "base/process/process_iterator.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/test/test_timeouts.h" 16 #include "base/test/test_timeouts.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/service_messages.h"
21 #include "chrome/common/service_process_util.h" 22 #include "chrome/common/service_process_util.h"
22 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
23 #include "components/version_info/version_info.h" 24 #include "components/version_info/version_info.h"
24 #include "content/public/common/content_paths.h" 25 #include "content/public/common/content_paths.h"
25 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
26 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 29
29 class ServiceProcessControlBrowserTest 30 class ServiceProcessControlBrowserTest
30 : public InProcessBrowserTest { 31 : public InProcessBrowserTest {
31 public: 32 public:
32 ServiceProcessControlBrowserTest() { 33 ServiceProcessControlBrowserTest() {
33 } 34 }
34 virtual ~ServiceProcessControlBrowserTest() { 35 virtual ~ServiceProcessControlBrowserTest() {
35 } 36 }
36 37
37 void HistogramsCallback() { 38 void HistogramsCallback() {
38 MockHistogramsCallback(); 39 MockHistogramsCallback();
39 QuitMessageLoop(); 40 QuitMessageLoop();
40 } 41 }
41 42
42 MOCK_METHOD0(MockHistogramsCallback, void()); 43 MOCK_METHOD0(MockHistogramsCallback, void());
43 44
44 protected: 45 protected:
45 void LaunchServiceProcessControl() { 46 void LaunchServiceProcessControl(bool wait = true) {
Lei Zhang 2016/09/01 06:12:01 Can we avoid having default arguments? There can't
Sam McNally 2016/09/01 06:58:44 Done.
46 // Launch the process asynchronously. 47 // Launch the process asynchronously.
47 ServiceProcessControl::GetInstance()->Launch( 48 ServiceProcessControl::GetInstance()->Launch(
48 base::Bind(&ServiceProcessControlBrowserTest::ProcessControlLaunched, 49 base::Bind(&ServiceProcessControlBrowserTest::ProcessControlLaunched,
49 base::Unretained(this)), 50 base::Unretained(this)),
50 base::Bind( 51 base::Bind(
51 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, 52 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed,
52 base::Unretained(this))); 53 base::Unretained(this)));
53 54
54 // Then run the message loop to keep things running. 55 // Then run the message loop to keep things running.
55 content::RunMessageLoop(); 56 if (wait)
57 content::RunMessageLoop();
56 } 58 }
57 59
58 static void QuitMessageLoop() { 60 static void QuitMessageLoop() {
59 base::MessageLoop::current()->QuitWhenIdle(); 61 base::MessageLoop::current()->QuitWhenIdle();
60 } 62 }
61 63
62 static void CloudPrintInfoCallback( 64 static void CloudPrintInfoCallback(
63 const cloud_print::CloudPrintProxyInfo& proxy_info) { 65 const cloud_print::CloudPrintProxyInfo& proxy_info) {
64 QuitMessageLoop(); 66 QuitMessageLoop();
65 } 67 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // Make sure we are connected to the service process. 166 // Make sure we are connected to the service process.
165 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); 167 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected());
166 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( 168 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo(
167 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); 169 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback));
168 content::RunMessageLoop(); 170 content::RunMessageLoop();
169 171
170 // And then shutdown the service process. 172 // And then shutdown the service process.
171 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); 173 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown());
172 } 174 }
173 175
176 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchAndReconnect) {
177 LaunchServiceProcessControl();
178
179 // Make sure we are connected to the service process.
180 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected());
181 ServiceProcessControl::GetInstance()->Send(
182 new ServiceMsg_StayAliveForTesting);
183 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo(
184 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback));
185 content::RunMessageLoop();
186 Disconnect();
187
188 LaunchServiceProcessControl(false);
189
190 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected());
191 content::RunMessageLoop();
192
193 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo(
194 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback));
195 content::RunMessageLoop();
196
197 // And then shutdown the service process.
198 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown());
199 }
200
174 // This tests the case when a service process is launched when the browser 201 // This tests the case when a service process is launched when the browser
175 // starts but we try to launch it again while setting up Cloud Print. 202 // starts but we try to launch it again while setting up Cloud Print.
176 // Flaky on Mac. http://crbug.com/517420 203 // Flaky on Mac. http://crbug.com/517420
177 #if defined(OS_MACOSX) 204 #if defined(OS_MACOSX)
178 #define MAYBE_LaunchTwice DISABLED_LaunchTwice 205 #define MAYBE_LaunchTwice DISABLED_LaunchTwice
179 #else 206 #else
180 #define MAYBE_LaunchTwice LaunchTwice 207 #define MAYBE_LaunchTwice LaunchTwice
181 #endif 208 #endif
182 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_LaunchTwice) { 209 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_LaunchTwice) {
183 // Launch the service process the first time. 210 // Launch the service process the first time.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // Callback should not be called during GetHistograms call. 362 // Callback should not be called during GetHistograms call.
336 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); 363 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0);
337 // Wait for real callback by providing large timeout value. 364 // Wait for real callback by providing large timeout value.
338 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( 365 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms(
339 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, 366 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback,
340 base::Unretained(this)), 367 base::Unretained(this)),
341 base::TimeDelta::FromHours(1))); 368 base::TimeDelta::FromHours(1)));
342 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); 369 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1);
343 content::RunMessageLoop(); 370 content::RunMessageLoop();
344 } 371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698