OLD | NEW |
---|---|
(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 "chrome/utility/chrome_content_utility_client.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "chrome/utility/utility_message_handler.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "ipc/ipc_message_macros.h" | |
11 #include "chrome/common/chrome_utility_messages.h" | |
12 #include "content/public/common/content_switches.h" | |
13 | |
14 #define IPC_MESSAGE_START ChromeUtilityMsgStart | |
15 | |
16 // TODO(haven): Debugging only. | |
17 IPC_MESSAGE_CONTROL0(ChromeUtilityMsg_DummyRequest) | |
18 IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_DummyResponse) | |
19 | |
20 namespace chrome { | |
21 | |
22 namespace { | |
23 | |
24 class MockHandler : public UtilityMessageHandler { | |
25 public: | |
26 MockHandler() : request_received(false) {} | |
27 | |
28 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | |
29 bool handled = true; | |
30 | |
31 IPC_BEGIN_MESSAGE_MAP(MockHandler, message) | |
32 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DummyRequest, OnDummyRequest) | |
33 IPC_MESSAGE_UNHANDLED(handled = false); | |
34 IPC_END_MESSAGE_MAP() | |
35 | |
36 return handled; | |
37 } | |
38 | |
39 void OnDummyRequest() { | |
40 request_received = true; | |
41 } | |
42 | |
43 bool request_received; | |
44 }; | |
45 | |
46 class ChromeContentUtilityClientTest : public testing::Test { | |
47 }; | |
48 | |
49 } // namespace | |
50 | |
51 TEST_F(ChromeContentUtilityClientTest, MessageWhitelistAccept) { | |
52 MockHandler* handler = new MockHandler; | |
53 | |
54 ChromeContentUtilityClient client; | |
55 | |
56 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
57 command_line->AppendSwitch(switches::kUtilityProcessRunningElevated); | |
58 | |
59 // Ownership given to client. | |
60 client.AddHandler(handler); | |
61 client.AddWhitelistMessageType(ChromeUtilityMsg_DummyRequest::ID); | |
62 client.UtilityThreadStarted(); | |
63 | |
64 ChromeUtilityMsg_DummyRequest message; | |
65 | |
66 EXPECT_TRUE(client.OnMessageReceived(message)); | |
67 | |
68 EXPECT_TRUE(handler->request_received); | |
69 } | |
70 | |
71 TEST_F(ChromeContentUtilityClientTest, MessageWhitelistReject) { | |
72 MockHandler* handler = new MockHandler; | |
73 | |
74 ChromeContentUtilityClient client; | |
75 | |
76 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
77 command_line->AppendSwitch(switches::kUtilityProcessRunningElevated); | |
78 | |
79 // Ownership given to client. | |
80 client.AddHandler(handler); | |
81 client.UtilityThreadStarted(); | |
82 | |
83 ChromeUtilityMsg_DummyRequest message; | |
84 | |
85 EXPECT_FALSE(client.OnMessageReceived(message)); | |
86 | |
87 EXPECT_FALSE(handler->request_received); | |
88 } | |
89 | |
90 | |
91 } // namespace chrome | |
OLD | NEW |