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

Unified Diff: chrome/utility/chrome_content_utility_client_unittest.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 side-by-side diff with in-line comments
Download patch
Index: chrome/utility/chrome_content_utility_client_unittest.cc
diff --git a/chrome/utility/chrome_content_utility_client_unittest.cc b/chrome/utility/chrome_content_utility_client_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5f4ae3ede1e3a65e1aed5cd4749d9b81097f991b
--- /dev/null
+++ b/chrome/utility/chrome_content_utility_client_unittest.cc
@@ -0,0 +1,91 @@
+// 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 "chrome/utility/chrome_content_utility_client.h"
+
+#include "base/command_line.h"
+#include "chrome/utility/utility_message_handler.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ipc/ipc_message_macros.h"
+#include "chrome/common/chrome_utility_messages.h"
+#include "content/public/common/content_switches.h"
+
+#define IPC_MESSAGE_START ChromeUtilityMsgStart
+
+// TODO(haven): Debugging only.
+IPC_MESSAGE_CONTROL0(ChromeUtilityMsg_DummyRequest)
+IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_DummyResponse)
+
+namespace chrome {
+
+namespace {
+
+class MockHandler : public UtilityMessageHandler {
+ public:
+ MockHandler() : request_received(false) {}
+
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(MockHandler, message)
+ IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DummyRequest, OnDummyRequest)
+ IPC_MESSAGE_UNHANDLED(handled = false);
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+ }
+
+ void OnDummyRequest() {
+ request_received = true;
+ }
+
+ bool request_received;
+};
+
+class ChromeContentUtilityClientTest : public testing::Test {
+};
+
+} // namespace
+
+TEST_F(ChromeContentUtilityClientTest, MessageWhitelistAccept) {
+ MockHandler* handler = new MockHandler;
+
+ ChromeContentUtilityClient client;
+
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ command_line->AppendSwitch(switches::kUtilityProcessRunningElevated);
+
+ // Ownership given to client.
+ client.AddHandler(handler);
+ client.AddWhitelistMessageType(ChromeUtilityMsg_DummyRequest::ID);
+ client.UtilityThreadStarted();
+
+ ChromeUtilityMsg_DummyRequest message;
+
+ EXPECT_TRUE(client.OnMessageReceived(message));
+
+ EXPECT_TRUE(handler->request_received);
+}
+
+TEST_F(ChromeContentUtilityClientTest, MessageWhitelistReject) {
+ MockHandler* handler = new MockHandler;
+
+ ChromeContentUtilityClient client;
+
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ command_line->AppendSwitch(switches::kUtilityProcessRunningElevated);
+
+ // Ownership given to client.
+ client.AddHandler(handler);
+ client.UtilityThreadStarted();
+
+ ChromeUtilityMsg_DummyRequest message;
+
+ EXPECT_FALSE(client.OnMessageReceived(message));
+
+ EXPECT_FALSE(handler->request_received);
+}
+
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698