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

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: Mostly test cleanup. Created 6 years, 11 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) 2012 The Chromium Authors. All rights reserved.
mef 2014/01/10 18:22:55 nit: 2014
Drew Haven 2014/01/16 02:52:05 Done.
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
mef 2014/01/10 18:22:55 I wonder, how would this whole thing work on XP?
Drew Haven 2014/01/16 02:52:05 Good point. I'll try to find an XP box for testin
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) {
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 void OnIsElevated(bool elevated) {
46 EXPECT_EQ(true, elevated);
47 response_received = true;
48 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
49 }
50
51 void Timeout() {
52 DLOG(ERROR) << "Timeout.";
53 quit_closure_.Run();
54 FAIL();
55 }
56
57 void LaunchProcess() {
58 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
59 base::Bind(&FakeUtilityProcessHostClient::Timeout, this), kTimeout);
60
61 utility_process_host_ = UtilityProcessHost::Create(
62 this,
63 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
64
65 utility_process_host_->ElevatePrivileges();
66 utility_process_host_->Send(new UtilityMsg_IsElevated());
67 }
68
69 bool response_received;
70
71 private:
72 base::Closure quit_closure_;
73 UtilityProcessHost* utility_process_host_;
74 };
75
76 class UtilityProcessHostImplBrowserTest : public testing::Test {
77 public:
78 UtilityProcessHostImplBrowserTest()
79 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {
80 }
81 protected:
82 virtual void SetUp() OVERRIDE {
83 testing::Test::SetUp();
84 }
85
86 virtual void TearDown() OVERRIDE {
87 }
88
89 scoped_refptr<FakeUtilityProcessHostClient> fake_process_host_client_;
90 TestBrowserThreadBundle thread_bundle_;
91 };
92
93 TEST_F(UtilityProcessHostImplBrowserTest, DISABLED_LaunchPrivileged) {
94 base::RunLoop loop;
95
96 fake_process_host_client_ = new FakeUtilityProcessHostClient();
97 fake_process_host_client_->SetQuitClosure(loop.QuitClosure());
98 BrowserThread::PostTask(
99 BrowserThread::IO,
100 FROM_HERE,
101 base::Bind(&FakeUtilityProcessHostClient::LaunchProcess,
102 fake_process_host_client_));
103
104 loop.Run();
105
106 EXPECT_TRUE(fake_process_host_client_->response_received);
107 }
108
109 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698