| 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..5892f58d991732c99ab3d8600e29a15c33d1fbb4
|
| --- /dev/null
|
| +++ b/content/browser/utility_process_host_impl_browsertest.cc
|
| @@ -0,0 +1,109 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// 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
|
| +
|
| +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_EffectiveUser, OnEffectiveUser)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP_EX()
|
| + if (!msg_is_good) {
|
| + DLOG(ERROR) << "Message deserialization failed.";
|
| + }
|
| + return handled;
|
| + }
|
| +
|
| + void OnEffectiveUser(int user) {
|
| + EXPECT_EQ(0, user);
|
| + 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_EffectiveUser());
|
| + }
|
| +
|
| + 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, 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
|
|
|