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

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

Issue 98603007: Launches a privileged utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleans up ChildProcessLauncher implementations. Created 6 years, 10 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
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/run_loop.h"
6 #include "content/browser/utility_process_host_impl.h"
7 #include "content/common/utility_messages.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/utility_process_host.h"
10 #include "content/public/browser/utility_process_host_client.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 // TODO(haven): This test won't actually work as a browser test since it
15 // requires interaction in the form of a UAC prompt
jam 2014/01/30 21:41:03 why are including it then?
Drew Haven 2014/01/31 20:00:12 It's just here because I wanted a quick way to tes
16
17 static const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(10);
18
19 namespace content {
20
21 class FakeUtilityProcessHostClient : public UtilityProcessHostClient {
22 public:
23 FakeUtilityProcessHostClient() : response_received(false) {
24 }
25
26 void SetQuitClosure(base::Closure quit_closure) {
27 quit_closure_ = quit_closure;
28 }
29
30 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
31 bool handled = true;
32 bool msg_is_good = false;
33 IPC_BEGIN_MESSAGE_MAP_EX(FakeUtilityProcessHostClient,
34 message,
35 msg_is_good)
36 IPC_MESSAGE_HANDLER(UtilityHostMsg_IsElevated, OnIsElevated)
37 IPC_MESSAGE_UNHANDLED(handled = false)
38 IPC_END_MESSAGE_MAP_EX()
39 if (!msg_is_good) {
40 DLOG(ERROR) << "Message deserialization failed.";
41 }
42 return handled;
43 }
44
45 virtual void OnProcessLaunchFailed() OVERRIDE {
46 DLOG(ERROR) << "Process failed to launch.";
47 quit_closure_.Run();
48 }
49
50 virtual void OnProcessCrashed(int exit_code) OVERRIDE {
51 DLOG(ERROR) << "Process crashed with exit code: " << exit_code;
52 quit_closure_.Run();
53 }
54
55 void OnIsElevated(bool elevated) {
56 EXPECT_EQ(true, elevated);
57 response_received = true;
58 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
59 }
60
61 void Timeout() {
62 DLOG(ERROR) << "Timeout.";
63 quit_closure_.Run();
64 FAIL();
65 }
66
67 void LaunchProcess() {
68 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
69 base::Bind(&FakeUtilityProcessHostClient::Timeout, this), kTimeout);
70
71 utility_process_host_ = UtilityProcessHost::Create(
72 this,
73 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
74
75 utility_process_host_->ElevatePrivileges();
76
77 if (!utility_process_host_->Send(new UtilityMsg_IsElevated())) {
78 DLOG(ERROR) << "Send failed.";
79 quit_closure_.Run();
80 }
81 }
82
83 bool response_received;
84
85 private:
86 base::Closure quit_closure_;
87 UtilityProcessHost* utility_process_host_;
88 };
89
90 class UtilityProcessHostImplBrowserTest : public testing::Test {
91 public:
92 UtilityProcessHostImplBrowserTest()
93 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {
94 }
95 protected:
96 virtual void SetUp() OVERRIDE {
97 testing::Test::SetUp();
98 }
99
100 virtual void TearDown() OVERRIDE {
101 }
102
103 scoped_refptr<FakeUtilityProcessHostClient> fake_process_host_client_;
104 TestBrowserThreadBundle thread_bundle_;
105 };
106
107 TEST_F(UtilityProcessHostImplBrowserTest, DISABLED_LaunchPrivileged) {
108 base::RunLoop loop;
109
110 fake_process_host_client_ = new FakeUtilityProcessHostClient();
111 fake_process_host_client_->SetQuitClosure(loop.QuitClosure());
112 BrowserThread::PostTask(
113 BrowserThread::IO,
114 FROM_HERE,
115 base::Bind(&FakeUtilityProcessHostClient::LaunchProcess,
116 fake_process_host_client_));
117
118 loop.Run();
119
120 EXPECT_TRUE(fake_process_host_client_->response_received);
121 }
122
123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698