Chromium Code Reviews| Index: content/browser/utility_process_host_impl_browsertest.cc |
| diff --git a/content/browser/utility_process_host_impl_browsertest.cc b/content/browser/utility_process_host_impl_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0d0e90f3f4f8e967962d6741da0f1358e6ef6cd9 |
| --- /dev/null |
| +++ b/content/browser/utility_process_host_impl_browsertest.cc |
| @@ -0,0 +1,109 @@ |
| +// 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.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/run_loop.h" |
| +#include "content/browser/utility_process_host_impl.h" |
| +#include "content/common/utility_messages.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/utility_process_host.h" |
| +#include "content/public/browser/utility_process_host_client.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +// TODO(haven): This test won't actually work as a browser test since it |
| +// 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
|
| + |
| +static const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(10); |
| + |
| +namespace content { |
| + |
| +class FakeUtilityProcessHostClient : public UtilityProcessHostClient { |
| + public: |
| + FakeUtilityProcessHostClient() : response_received(false) { |
| + } |
| + |
| + void SetQuitClosure(base::Closure quit_closure) { |
| + quit_closure_ = quit_closure; |
| + } |
| + |
| + virtual bool OnMessageReceived(const IPC::Message& message) { |
| + bool handled = true; |
| + bool msg_is_good = false; |
| + IPC_BEGIN_MESSAGE_MAP_EX(FakeUtilityProcessHostClient, |
| + message, |
| + msg_is_good) |
| + IPC_MESSAGE_HANDLER(UtilityHostMsg_IsElevated, OnIsElevated) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP_EX() |
| + if (!msg_is_good) { |
| + DLOG(ERROR) << "Message deserialization failed."; |
| + } |
| + return handled; |
| + } |
| + |
| + void OnIsElevated(bool elevated) { |
| + EXPECT_EQ(true, elevated); |
| + response_received = true; |
| + base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); |
| + } |
| + |
| + void Timeout() { |
| + DLOG(ERROR) << "Timeout."; |
| + quit_closure_.Run(); |
| + FAIL(); |
| + } |
| + |
| + void LaunchProcess() { |
| + base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| + base::Bind(&FakeUtilityProcessHostClient::Timeout, this), kTimeout); |
| + |
| + utility_process_host_ = UtilityProcessHost::Create( |
| + this, |
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| + |
| + utility_process_host_->ElevatePrivileges(); |
| + utility_process_host_->Send(new UtilityMsg_IsElevated()); |
| + } |
| + |
| + bool response_received; |
| + |
| + private: |
| + base::Closure quit_closure_; |
| + UtilityProcessHost* utility_process_host_; |
| +}; |
| + |
| +class UtilityProcessHostImplBrowserTest : public testing::Test { |
| + public: |
| + UtilityProcessHostImplBrowserTest() |
| + : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) { |
| + } |
| + protected: |
| + virtual void SetUp() OVERRIDE { |
| + testing::Test::SetUp(); |
| + } |
| + |
| + virtual void TearDown() OVERRIDE { |
| + } |
| + |
| + scoped_refptr<FakeUtilityProcessHostClient> fake_process_host_client_; |
| + TestBrowserThreadBundle thread_bundle_; |
| +}; |
| + |
| +TEST_F(UtilityProcessHostImplBrowserTest, DISABLED_LaunchPrivileged) { |
| + base::RunLoop loop; |
| + |
| + fake_process_host_client_ = new FakeUtilityProcessHostClient(); |
| + fake_process_host_client_->SetQuitClosure(loop.QuitClosure()); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&FakeUtilityProcessHostClient::LaunchProcess, |
| + fake_process_host_client_)); |
| + |
| + loop.Run(); |
| + |
| + EXPECT_TRUE(fake_process_host_client_->response_received); |
| +} |
| + |
| +} // namespace content |