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

Side by Side Diff: content/browser/utility_process_host_impl_browsertest.cc

Issue 2096643002: Eliminate MojoApplicationHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mah3
Patch Set: . Created 4 years, 6 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/utility_process_host.h" 9 #include "content/public/browser/utility_process_host.h"
10 #include "content/public/browser/utility_process_host_client.h" 10 #include "content/public/browser/utility_process_host_client.h"
11 #include "content/public/common/service_registry.h"
12 #include "content/public/test/content_browser_test.h" 11 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h" 12 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/public/test/test_mojo_service.mojom.h" 13 #include "content/public/test/test_mojo_service.mojom.h"
14 #include "services/shell/public/cpp/interface_provider.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 class UtilityProcessHostImplBrowserTest : public ContentBrowserTest { 18 class UtilityProcessHostImplBrowserTest : public ContentBrowserTest {
19 public: 19 public:
20 void RunUtilityProcess(bool elevated) { 20 void RunUtilityProcess(bool elevated) {
21 base::RunLoop run_loop; 21 base::RunLoop run_loop;
22 done_closure_ = run_loop.QuitClosure(); 22 done_closure_ = run_loop.QuitClosure();
23 BrowserThread::PostTask( 23 BrowserThread::PostTask(
24 BrowserThread::IO, FROM_HERE, 24 BrowserThread::IO, FROM_HERE,
25 base::Bind( 25 base::Bind(
26 &UtilityProcessHostImplBrowserTest::RunUtilityProcessOnIOThread, 26 &UtilityProcessHostImplBrowserTest::RunUtilityProcessOnIOThread,
27 base::Unretained(this), elevated)); 27 base::Unretained(this), elevated));
28 run_loop.Run(); 28 run_loop.Run();
29 } 29 }
30 30
31 protected: 31 protected:
32 void RunUtilityProcessOnIOThread(bool elevated) { 32 void RunUtilityProcessOnIOThread(bool elevated) {
33 UtilityProcessHost* host = UtilityProcessHost::Create(nullptr, nullptr); 33 UtilityProcessHost* host = UtilityProcessHost::Create(nullptr, nullptr);
34 host->SetName(base::ASCIIToUTF16("TestProcess")); 34 host->SetName(base::ASCIIToUTF16("TestProcess"));
35 #if defined(OS_WIN) 35 #if defined(OS_WIN)
36 if (elevated) 36 if (elevated)
37 host->ElevatePrivileges(); 37 host->ElevatePrivileges();
38 #endif 38 #endif
39 EXPECT_TRUE(host->Start()); 39 EXPECT_TRUE(host->Start());
40 40
41 ServiceRegistry* service_registry = host->GetServiceRegistry(); 41 host->GetRemoteInterfaces()->GetInterface(&service_);
42 service_registry->ConnectToRemoteService(mojo::GetProxy(&service_));
43 service_->DoSomething(base::Bind( 42 service_->DoSomething(base::Bind(
44 &UtilityProcessHostImplBrowserTest::OnSomething, 43 &UtilityProcessHostImplBrowserTest::OnSomething,
45 base::Unretained(this))); 44 base::Unretained(this)));
46 } 45 }
47 46
48 void OnSomething() { 47 void OnSomething() {
49 service_.reset(); 48 service_.reset();
50 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_closure_); 49 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_closure_);
51 } 50 }
52 51
53 mojom::TestMojoServicePtr service_; 52 mojom::TestMojoServicePtr service_;
54 base::Closure done_closure_; 53 base::Closure done_closure_;
55 }; 54 };
56 55
57 IN_PROC_BROWSER_TEST_F(UtilityProcessHostImplBrowserTest, LaunchProcess) { 56 IN_PROC_BROWSER_TEST_F(UtilityProcessHostImplBrowserTest, LaunchProcess) {
58 RunUtilityProcess(false); 57 RunUtilityProcess(false);
59 } 58 }
60 59
61 #if defined(OS_WIN) 60 #if defined(OS_WIN)
62 IN_PROC_BROWSER_TEST_F(UtilityProcessHostImplBrowserTest, 61 IN_PROC_BROWSER_TEST_F(UtilityProcessHostImplBrowserTest,
63 LaunchElevatedProcess) { 62 LaunchElevatedProcess) {
64 RunUtilityProcess(true); 63 RunUtilityProcess(true);
65 } 64 }
66 #endif 65 #endif
67 66
68 } // namespace content 67 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/utility_process_host_impl.cc ('k') | content/child/background_sync/background_sync_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698