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..f5ce097df0f03ce0abdc6afd080eab02c446e413 |
--- /dev/null |
+++ b/content/browser/utility_process_host_impl_browsertest.cc |
@@ -0,0 +1,123 @@ |
+// Copyright (c) 2014 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 |
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
|
+ |
+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) OVERRIDE { |
+ 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; |
+ } |
+ |
+ virtual void OnProcessLaunchFailed() OVERRIDE { |
+ DLOG(ERROR) << "Process failed to launch."; |
+ quit_closure_.Run(); |
+ } |
+ |
+ virtual void OnProcessCrashed(int exit_code) OVERRIDE { |
+ DLOG(ERROR) << "Process crashed with exit code: " << exit_code; |
+ quit_closure_.Run(); |
+ } |
+ |
+ 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(); |
+ |
+ if (!utility_process_host_->Send(new UtilityMsg_IsElevated())) { |
+ DLOG(ERROR) << "Send failed."; |
+ quit_closure_.Run(); |
+ } |
+ } |
+ |
+ 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 |