OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/search/search_ipc_router.h" | 5 #include "chrome/browser/ui/search/search_ipc_router.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "ui/base/window_open_disposition.h" | 39 #include "ui/base/window_open_disposition.h" |
40 #include "url/gurl.h" | 40 #include "url/gurl.h" |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { | 44 class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { |
45 public: | 45 public: |
46 virtual ~MockSearchIPCRouterDelegate() {} | 46 virtual ~MockSearchIPCRouterDelegate() {} |
47 | 47 |
48 MOCK_METHOD1(OnInstantSupportDetermined, void(bool supports_instant)); | 48 MOCK_METHOD1(OnInstantSupportDetermined, void(bool supports_instant)); |
49 MOCK_METHOD1(OnSetVoiceSearchSupport, void(bool supports_voice_search)); | |
50 MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state)); | 49 MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state)); |
51 MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool)); | 50 MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool)); |
52 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); | 51 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); |
53 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); | 52 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); |
54 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); | 53 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); |
55 MOCK_METHOD2(OnLogEvent, void(NTPLoggingEventType event, | 54 MOCK_METHOD2(OnLogEvent, void(NTPLoggingEventType event, |
56 base::TimeDelta time)); | 55 base::TimeDelta time)); |
57 MOCK_METHOD2(OnLogMostVisitedImpression, | 56 MOCK_METHOD2(OnLogMostVisitedImpression, |
58 void(int position, const base::string16& provider)); | 57 void(int position, const base::string16& provider)); |
59 MOCK_METHOD2(OnLogMostVisitedNavigation, | 58 MOCK_METHOD2(OnLogMostVisitedNavigation, |
60 void(int position, const base::string16& provider)); | 59 void(int position, const base::string16& provider)); |
61 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); | 60 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); |
62 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); | 61 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); |
63 MOCK_METHOD0(OnHistorySyncCheck, void()); | 62 MOCK_METHOD0(OnHistorySyncCheck, void()); |
64 }; | 63 }; |
65 | 64 |
66 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { | 65 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { |
67 public: | 66 public: |
68 virtual ~MockSearchIPCRouterPolicy() {} | 67 virtual ~MockSearchIPCRouterPolicy() {} |
69 | 68 |
70 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool()); | |
71 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); | 69 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); |
72 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool)); | 70 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool)); |
73 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); | 71 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); |
74 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); | 72 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); |
75 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); | 73 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); |
76 MOCK_METHOD0(ShouldProcessLogEvent, bool()); | 74 MOCK_METHOD0(ShouldProcessLogEvent, bool()); |
77 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); | 75 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); |
78 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); | 76 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); |
79 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); | 77 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); |
80 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); | 78 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 EXPECT_TRUE(is_active_tab); | 217 EXPECT_TRUE(is_active_tab); |
220 | 218 |
221 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 219 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
222 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); | 220 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); |
223 | 221 |
224 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate( | 222 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate( |
225 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url, | 223 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url, |
226 CURRENT_TAB, true)); | 224 CURRENT_TAB, true)); |
227 } | 225 } |
228 | 226 |
229 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) { | |
230 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | |
231 SetupMockDelegateAndPolicy(); | |
232 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
233 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1); | |
234 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1) | |
235 .WillOnce(testing::Return(true)); | |
236 | |
237 content::WebContents* contents = web_contents(); | |
238 OnMessageReceived(ChromeViewHostMsg_SetVoiceSearchSupported( | |
239 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true)); | |
240 } | |
241 | |
242 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) { | |
243 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | |
244 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0); | |
245 SetupMockDelegateAndPolicy(); | |
246 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | |
247 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1) | |
248 .WillOnce(testing::Return(false)); | |
249 | |
250 content::WebContents* contents = web_contents(); | |
251 OnMessageReceived(ChromeViewHostMsg_SetVoiceSearchSupported( | |
252 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true)); | |
253 } | |
254 | |
255 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { | 227 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { |
256 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 228 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
257 SetupMockDelegateAndPolicy(); | 229 SetupMockDelegateAndPolicy(); |
258 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 230 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
259 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); | 231 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); |
260 | 232 |
261 content::WebContents* contents = web_contents(); | 233 content::WebContents* contents = web_contents(); |
262 bool is_active_tab = IsActiveTab(contents); | 234 bool is_active_tab = IsActiveTab(contents); |
263 EXPECT_TRUE(is_active_tab); | 235 EXPECT_TRUE(is_active_tab); |
264 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) | 236 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 | 880 |
909 // Construct a series of synthetic messages for each valid IPC message type, | 881 // Construct a series of synthetic messages for each valid IPC message type, |
910 // ensuring the router ignores them all. | 882 // ensuring the router ignores them all. |
911 for (int i = 0; i < LastIPCMsgStart; ++i) { | 883 for (int i = 0; i < LastIPCMsgStart; ++i) { |
912 const int message_id = i << 16; | 884 const int message_id = i << 16; |
913 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); | 885 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); |
914 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); | 886 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); |
915 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; | 887 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; |
916 } | 888 } |
917 } | 889 } |
OLD | NEW |