Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / search / search_ipc_router_unittest.cc
blob224c714701aab8bd11edb5ccfd921042559b8f15
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/search/search_ipc_router.h"
7 #include <vector>
9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/field_trial.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/tuple.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search/search.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/ui/search/search_ipc_router_policy_impl.h"
19 #include "chrome/browser/ui/search/search_tab_helper.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/instant_types.h"
23 #include "chrome/common/ntp_logging_events.h"
24 #include "chrome/common/omnibox_focus_state.h"
25 #include "chrome/common/render_messages.h"
26 #include "chrome/common/url_constants.h"
27 #include "chrome/test/base/browser_with_test_window_test.h"
28 #include "chrome/test/base/ui_test_utils.h"
29 #include "components/search_engines/template_url_service.h"
30 #include "content/public/browser/navigation_controller.h"
31 #include "content/public/browser/navigation_entry.h"
32 #include "content/public/browser/web_contents.h"
33 #include "content/public/test/mock_render_process_host.h"
34 #include "ipc/ipc_message.h"
35 #include "ipc/ipc_message_start.h"
36 #include "ipc/ipc_test_sink.h"
37 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "ui/base/window_open_disposition.h"
40 #include "url/gurl.h"
42 namespace {
44 class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate {
45 public:
46 virtual ~MockSearchIPCRouterDelegate() {}
48 MOCK_METHOD1(OnInstantSupportDetermined, void(bool supports_instant));
49 MOCK_METHOD1(OnSetVoiceSearchSupport, void(bool supports_voice_search));
50 MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state));
51 MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool));
52 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url));
53 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url));
54 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void());
55 MOCK_METHOD2(OnLogEvent, void(NTPLoggingEventType event,
56 base::TimeDelta time));
57 MOCK_METHOD2(OnLogMostVisitedImpression,
58 void(int position, const base::string16& provider));
59 MOCK_METHOD2(OnLogMostVisitedNavigation,
60 void(int position, const base::string16& provider));
61 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&));
62 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity));
63 MOCK_METHOD0(OnHistorySyncCheck, void());
66 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
67 public:
68 virtual ~MockSearchIPCRouterPolicy() {}
70 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool());
71 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool));
72 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool));
73 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool());
74 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool());
75 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool());
76 MOCK_METHOD0(ShouldProcessLogEvent, bool());
77 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool));
78 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool());
79 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool());
80 MOCK_METHOD0(ShouldSendSetPromoInformation, bool());
81 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool());
82 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool());
83 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool());
84 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool));
85 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
86 MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
87 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool());
88 MOCK_METHOD0(ShouldSendToggleVoiceSearch, bool());
89 MOCK_METHOD0(ShouldSubmitQuery, bool());
92 } // namespace
94 class SearchIPCRouterTest : public BrowserWithTestWindowTest {
95 public:
96 SearchIPCRouterTest() : field_trial_list_(NULL) {}
98 void SetUp() override {
99 BrowserWithTestWindowTest::SetUp();
100 AddTab(browser(), GURL("chrome://blank"));
101 SearchTabHelper::CreateForWebContents(web_contents());
103 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
104 profile(),
105 &TemplateURLServiceFactory::BuildInstanceFor);
106 TemplateURLService* template_url_service =
107 TemplateURLServiceFactory::GetForProfile(profile());
108 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
110 TemplateURLData data;
111 data.SetShortName(base::ASCIIToUTF16("foo.com"));
112 data.SetURL("http://foo.com/url?bar={searchTerms}");
113 data.instant_url = "http://foo.com/instant?"
114 "{google:omniboxStartMarginParameter}foo=foo#foo=foo&espv";
115 data.new_tab_url = "https://foo.com/newtab?espv";
116 data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}");
117 data.search_terms_replacement_key = "espv";
119 TemplateURL* template_url = new TemplateURL(data);
120 // Takes ownership of |template_url|.
121 template_url_service->Add(template_url);
122 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
123 process()->sink().ClearMessages();
126 content::WebContents* web_contents() {
127 return browser()->tab_strip_model()->GetActiveWebContents();
130 content::MockRenderProcessHost* process() {
131 return static_cast<content::MockRenderProcessHost*>(
132 web_contents()->GetRenderViewHost()->GetProcess());
135 SearchTabHelper* GetSearchTabHelper(
136 content::WebContents* web_contents) {
137 EXPECT_NE(static_cast<content::WebContents*>(NULL), web_contents);
138 return SearchTabHelper::FromWebContents(web_contents);
141 void SetupMockDelegateAndPolicy() {
142 content::WebContents* contents = web_contents();
143 ASSERT_NE(static_cast<content::WebContents*>(NULL), contents);
144 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents);
145 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
146 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate());
147 search_tab_helper->ipc_router().set_policy_for_testing(
148 make_scoped_ptr(new MockSearchIPCRouterPolicy));
151 bool MessageWasSent(uint32 id) {
152 return process()->sink().GetFirstMessageMatching(id) != NULL;
155 void VerifyDisplayInstantResultsMsg(bool expected_param_value) {
156 SetupMockDelegateAndPolicy();
157 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
158 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1)
159 .WillOnce(testing::Return(true));
161 GetSearchIPCRouter().SetDisplayInstantResults();
162 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
163 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID);
164 EXPECT_NE(static_cast<const IPC::Message*>(NULL), message);
165 Tuple<bool> display_instant_results_param;
166 ChromeViewMsg_SearchBoxSetDisplayInstantResults::Read(
167 message, &display_instant_results_param);
168 EXPECT_EQ(expected_param_value, get<0>(display_instant_results_param));
171 MockSearchIPCRouterDelegate* mock_delegate() { return &delegate_; }
173 MockSearchIPCRouterPolicy* GetSearchIPCRouterPolicy() {
174 content::WebContents* contents = web_contents();
175 EXPECT_NE(static_cast<content::WebContents*>(NULL), contents);
176 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents);
177 EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
178 return static_cast<MockSearchIPCRouterPolicy*>(
179 search_tab_helper->ipc_router().policy_for_testing());
182 SearchIPCRouter& GetSearchIPCRouter() {
183 return GetSearchTabHelper(web_contents())->ipc_router();
186 int GetSearchIPCRouterSeqNo() {
187 return GetSearchIPCRouter().page_seq_no_for_testing();
190 void OnMessageReceived(const IPC::Message& message) {
191 bool should_handle_message =
192 chrome::IsRenderedInInstantProcess(web_contents(), profile());
193 bool handled = GetSearchIPCRouter().OnMessageReceived(message);
194 ASSERT_EQ(should_handle_message, handled);
197 bool OnSpuriousMessageReceived(const IPC::Message& message) {
198 return GetSearchIPCRouter().OnMessageReceived(message);
201 bool IsActiveTab(content::WebContents* contents) {
202 return GetSearchTabHelper(contents)->ipc_router().is_active_tab_;
205 private:
206 MockSearchIPCRouterDelegate delegate_;
207 base::FieldTrialList field_trial_list_;
210 TEST_F(SearchIPCRouterTest, IgnoreMessagesFromNonInstantRenderers) {
211 NavigateAndCommitActiveTab(GURL("file://foo/bar"));
212 SetupMockDelegateAndPolicy();
213 GURL destination_url("www.foo.com");
214 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
215 true)).Times(0);
216 content::WebContents* contents = web_contents();
217 bool is_active_tab = IsActiveTab(contents);
218 EXPECT_TRUE(is_active_tab);
220 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
221 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
223 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
224 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
225 CURRENT_TAB, true));
228 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) {
229 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
230 SetupMockDelegateAndPolicy();
231 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
232 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1);
233 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1)
234 .WillOnce(testing::Return(true));
236 content::WebContents* contents = web_contents();
237 OnMessageReceived(ChromeViewHostMsg_SetVoiceSearchSupported(
238 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
241 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) {
242 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
243 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0);
244 SetupMockDelegateAndPolicy();
245 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
246 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1)
247 .WillOnce(testing::Return(false));
249 content::WebContents* contents = web_contents();
250 OnMessageReceived(ChromeViewHostMsg_SetVoiceSearchSupported(
251 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
254 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) {
255 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
256 SetupMockDelegateAndPolicy();
257 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
258 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1);
260 content::WebContents* contents = web_contents();
261 bool is_active_tab = IsActiveTab(contents);
262 EXPECT_TRUE(is_active_tab);
263 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
264 .WillOnce(testing::Return(true));
266 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
267 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
268 OMNIBOX_FOCUS_VISIBLE));
271 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) {
272 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
273 SetupMockDelegateAndPolicy();
274 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
275 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
277 content::WebContents* contents = web_contents();
278 bool is_active_tab = IsActiveTab(contents);
279 EXPECT_TRUE(is_active_tab);
280 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
281 .WillOnce(testing::Return(false));
283 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
284 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
285 OMNIBOX_FOCUS_VISIBLE));
288 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) {
289 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
290 content::WebContents* contents = web_contents();
291 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents));
292 EXPECT_TRUE(IsActiveTab(contents));
294 // Add a new tab to deactivate the current tab.
295 AddTab(browser(), GURL(url::kAboutBlankURL));
296 EXPECT_EQ(2, browser()->tab_strip_model()->count());
297 EXPECT_EQ(1, browser()->tab_strip_model()->GetIndexOfWebContents(contents));
298 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
299 EXPECT_FALSE(IsActiveTab(contents));
301 // Activate the first tab.
302 browser()->tab_strip_model()->ActivateTabAt(1, false);
303 EXPECT_EQ(browser()->tab_strip_model()->active_index(),
304 browser()->tab_strip_model()->GetIndexOfWebContents(contents));
305 EXPECT_TRUE(IsActiveTab(contents));
308 TEST_F(SearchIPCRouterTest, ProcessNavigateToURLMsg) {
309 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
310 SetupMockDelegateAndPolicy();
311 GURL destination_url("www.foo.com");
312 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
313 true)).Times(1);
314 content::WebContents* contents = web_contents();
315 bool is_active_tab = IsActiveTab(contents);
316 EXPECT_TRUE(is_active_tab);
318 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
319 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
320 .WillOnce(testing::Return(true));
322 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
323 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
324 CURRENT_TAB, true));
327 TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) {
328 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
329 SetupMockDelegateAndPolicy();
330 GURL destination_url("www.foo.com");
331 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
332 true)).Times(0);
333 content::WebContents* contents = web_contents();
334 bool is_active_tab = IsActiveTab(contents);
335 EXPECT_TRUE(is_active_tab);
337 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
338 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
339 .WillOnce(testing::Return(false));
341 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
342 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
343 CURRENT_TAB, true));
346 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) {
347 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123);
348 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
349 SetupMockDelegateAndPolicy();
350 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
351 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER, delta)).Times(1);
352 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
353 .WillOnce(testing::Return(true));
355 content::WebContents* contents = web_contents();
356 OnMessageReceived(ChromeViewHostMsg_LogEvent(
357 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
358 NTP_MOUSEOVER, delta));
361 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
362 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123);
363 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
364 SetupMockDelegateAndPolicy();
365 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
366 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER, delta)).Times(0);
367 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
368 .WillOnce(testing::Return(false));
370 content::WebContents* contents = web_contents();
371 OnMessageReceived(ChromeViewHostMsg_LogEvent(
372 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
373 NTP_MOUSEOVER, delta));
376 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) {
377 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
378 SetupMockDelegateAndPolicy();
379 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
380 EXPECT_CALL(*mock_delegate(),
381 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1);
382 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
383 .WillOnce(testing::Return(true));
385 content::WebContents* contents = web_contents();
386 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedImpression(
387 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 3,
388 base::ASCIIToUTF16("Server")));
391 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) {
392 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
393 SetupMockDelegateAndPolicy();
394 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
395 EXPECT_CALL(*mock_delegate(),
396 OnLogMostVisitedNavigation(3, base::ASCIIToUTF16("Server"))).Times(1);
397 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
398 .WillOnce(testing::Return(true));
400 content::WebContents* contents = web_contents();
401 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedNavigation(
402 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 3,
403 base::ASCIIToUTF16("Server")));
406 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) {
407 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
408 SetupMockDelegateAndPolicy();
409 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
410 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
411 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1);
412 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
413 .WillOnce(testing::Return(true));
415 content::WebContents* contents = web_contents();
416 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck(
417 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
420 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) {
421 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
422 SetupMockDelegateAndPolicy();
423 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
425 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
426 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0);
427 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
428 .WillOnce(testing::Return(false));
430 content::WebContents* contents = web_contents();
431 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck(
432 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
435 TEST_F(SearchIPCRouterTest, ProcessHistorySyncCheckMsg) {
436 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
437 SetupMockDelegateAndPolicy();
438 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
439 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(1);
440 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1)
441 .WillOnce(testing::Return(true));
443 content::WebContents* contents = web_contents();
444 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck(
445 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
448 TEST_F(SearchIPCRouterTest, IgnoreHistorySyncCheckMsg) {
449 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
450 SetupMockDelegateAndPolicy();
451 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
453 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(0);
454 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1)
455 .WillOnce(testing::Return(false));
457 content::WebContents* contents = web_contents();
458 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck(
459 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
462 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) {
463 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
464 SetupMockDelegateAndPolicy();
465 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
466 GURL item_url("www.foo.com");
467 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1);
468 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
469 .WillOnce(testing::Return(true));
471 content::WebContents* contents = web_contents();
472 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
473 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
476 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) {
477 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
478 SetupMockDelegateAndPolicy();
479 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
480 GURL item_url("www.foo.com");
481 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
482 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
483 .WillOnce(testing::Return(false));
485 content::WebContents* contents = web_contents();
486 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
487 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
490 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) {
491 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
492 SetupMockDelegateAndPolicy();
493 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
494 GURL item_url("www.foo.com");
495 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1);
496 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
497 .WillOnce(testing::Return(true));
499 content::WebContents* contents = web_contents();
500 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
501 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
504 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) {
505 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
506 SetupMockDelegateAndPolicy();
507 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
508 GURL item_url("www.foo.com");
509 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
510 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
511 .WillOnce(testing::Return(false));
513 content::WebContents* contents = web_contents();
514 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
515 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
518 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) {
519 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
520 SetupMockDelegateAndPolicy();
521 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
522 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1);
523 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
524 .WillOnce(testing::Return(true));
526 content::WebContents* contents = web_contents();
527 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
528 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
531 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) {
532 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
533 SetupMockDelegateAndPolicy();
534 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
535 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
536 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
537 .WillOnce(testing::Return(false));
539 content::WebContents* contents = web_contents();
540 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
541 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
544 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) {
545 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
546 SetupMockDelegateAndPolicy();
547 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
548 int page_seq_no = GetSearchIPCRouterSeqNo();
550 content::WebContents* contents = web_contents();
551 bool is_active_tab = IsActiveTab(contents);
552 GURL item_url("www.foo.com");
553 EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB,
554 true)).Times(0);
555 // At this point, in a real test, the navigation would cause the
556 // SearchIPCRouter's page sequence to advance. In this test it doesn't, so
557 // we'll decrement the sequence number on this side to simulate it.
558 --page_seq_no;
559 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
560 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
561 contents->GetRoutingID(), page_seq_no, item_url, CURRENT_TAB, true));
563 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
564 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0);
565 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
566 contents->GetRoutingID(), page_seq_no, item_url));
568 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
569 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0);
570 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
571 contents->GetRoutingID(), page_seq_no, item_url));
573 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
574 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0);
575 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
576 contents->GetRoutingID(), page_seq_no));
578 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
579 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0);
580 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
581 contents->GetRoutingID(), page_seq_no, OMNIBOX_FOCUS_VISIBLE));
583 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(123);
584 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER, delta)).Times(0);
585 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0);
586 OnMessageReceived(ChromeViewHostMsg_LogEvent(contents->GetRoutingID(),
587 page_seq_no,
588 NTP_MOUSEOVER, delta));
590 base::string16 text;
591 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
592 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0);
593 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
594 contents->GetRoutingID(), page_seq_no, text));
597 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) {
598 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
599 SetupMockDelegateAndPolicy();
600 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
602 content::WebContents* contents = web_contents();
603 bool is_active_tab = IsActiveTab(contents);
604 EXPECT_TRUE(is_active_tab);
606 base::string16 text;
607 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1);
608 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
609 .WillOnce(testing::Return(true));
610 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
611 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
614 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) {
615 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
616 SetupMockDelegateAndPolicy();
617 base::string16 text;
618 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
620 content::WebContents* contents = web_contents();
621 bool is_active_tab = IsActiveTab(contents);
622 EXPECT_TRUE(is_active_tab);
624 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
625 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
626 .WillOnce(testing::Return(false));
628 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
629 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
632 TEST_F(SearchIPCRouterTest, SendSetPromoInformationMsg) {
633 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
634 SetupMockDelegateAndPolicy();
635 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
636 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1)
637 .WillOnce(testing::Return(true));
639 GetSearchIPCRouter().SetPromoInformation(true);
640 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxPromoInformation::ID));
643 TEST_F(SearchIPCRouterTest, DoNotSendSetPromoInformationMsg) {
644 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
645 SetupMockDelegateAndPolicy();
646 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
647 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1)
648 .WillOnce(testing::Return(false));
650 GetSearchIPCRouter().SetPromoInformation(false);
651 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxPromoInformation::ID));
654 TEST_F(SearchIPCRouterTest,
655 SendSetDisplayInstantResultsMsg_EnableInstantOnResultsPage) {
656 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
657 "EmbeddedSearch",
658 "Group1 espv:42 query_extraction:1 prefetch_results_srp:1"));
659 NavigateAndCommitActiveTab(GURL("https://foo.com/url?espv&bar=abc"));
661 // Make sure ChromeViewMsg_SearchBoxSetDisplayInstantResults message param is
662 // set to true if the underlying page is a results page and
663 // "prefetch_results_srp" flag is enabled via field trials.
664 VerifyDisplayInstantResultsMsg(true);
667 TEST_F(SearchIPCRouterTest,
668 SendSetDisplayInstantResultsMsg_DisableInstantOnResultsPage) {
669 // |prefetch_results_srp" flag is disabled via field trials.
670 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
671 "EmbeddedSearch",
672 "Group1 espv:42 query_extraction:1 prefetch_results_srp:0"));
673 NavigateAndCommitActiveTab(GURL("https://foo.com/url?espv&bar=abc"));
675 // Make sure ChromeViewMsg_SearchBoxSetDisplayInstantResults message param is
676 // set to false.
677 VerifyDisplayInstantResultsMsg(false);
680 TEST_F(SearchIPCRouterTest,
681 SendSetDisplayInstantResultsMsg_EnableInstantOutsideSearchResultsPage) {
682 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
683 // Make sure ChromeViewMsg_SearchBoxSetDisplayInstantResults param is set to
684 // true if the underlying page is not a search results page.
685 VerifyDisplayInstantResultsMsg(true);
688 TEST_F(SearchIPCRouterTest, DoNotSendSetDisplayInstantResultsMsg) {
689 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
690 SetupMockDelegateAndPolicy();
691 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
692 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1)
693 .WillOnce(testing::Return(false));
695 process()->sink().ClearMessages();
696 GetSearchIPCRouter().SetDisplayInstantResults();
697 EXPECT_FALSE(MessageWasSent(
698 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID));
701 TEST_F(SearchIPCRouterTest, SendSetSuggestionToPrefetch) {
702 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
703 SetupMockDelegateAndPolicy();
704 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
705 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1)
706 .WillOnce(testing::Return(true));
708 process()->sink().ClearMessages();
709 content::WebContents* contents = web_contents();
710 GetSearchTabHelper(contents)->SetSuggestionToPrefetch(InstantSuggestion());
711 EXPECT_TRUE(MessageWasSent(
712 ChromeViewMsg_SearchBoxSetSuggestionToPrefetch::ID));
715 TEST_F(SearchIPCRouterTest, DoNotSendSetSuggestionToPrefetch) {
716 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
717 SetupMockDelegateAndPolicy();
718 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
719 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1)
720 .WillOnce(testing::Return(false));
722 process()->sink().ClearMessages();
723 content::WebContents* contents = web_contents();
724 GetSearchTabHelper(contents)->SetSuggestionToPrefetch(InstantSuggestion());
725 EXPECT_FALSE(MessageWasSent(
726 ChromeViewMsg_SearchBoxSetSuggestionToPrefetch::ID));
729 TEST_F(SearchIPCRouterTest, SendSetOmniboxStartMargin) {
730 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
731 SetupMockDelegateAndPolicy();
732 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
733 EXPECT_CALL(*policy, ShouldSendSetOmniboxStartMargin()).Times(1)
734 .WillOnce(testing::Return(true));
736 process()->sink().ClearMessages();
737 GetSearchIPCRouter().SetOmniboxStartMargin(92);
738 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID));
741 TEST_F(SearchIPCRouterTest, DoNotSendSetOmniboxStartMargin) {
742 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
743 SetupMockDelegateAndPolicy();
744 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
745 EXPECT_CALL(*policy, ShouldSendSetOmniboxStartMargin()).Times(1)
746 .WillOnce(testing::Return(false));
748 process()->sink().ClearMessages();
749 GetSearchIPCRouter().SetOmniboxStartMargin(92);
750 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxMarginChange::ID));
753 TEST_F(SearchIPCRouterTest, SendOmniboxFocusChange) {
754 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
755 SetupMockDelegateAndPolicy();
756 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
757 EXPECT_CALL(*policy, ShouldSendOmniboxFocusChanged()).Times(1)
758 .WillOnce(testing::Return(true));
760 process()->sink().ClearMessages();
761 GetSearchIPCRouter().OmniboxFocusChanged(OMNIBOX_FOCUS_NONE,
762 OMNIBOX_FOCUS_CHANGE_EXPLICIT);
763 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxFocusChanged::ID));
766 TEST_F(SearchIPCRouterTest, DoNotSendOmniboxFocusChange) {
767 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
768 SetupMockDelegateAndPolicy();
769 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
770 EXPECT_CALL(*policy, ShouldSendOmniboxFocusChanged()).Times(1)
771 .WillOnce(testing::Return(false));
773 process()->sink().ClearMessages();
774 GetSearchIPCRouter().OmniboxFocusChanged(OMNIBOX_FOCUS_NONE,
775 OMNIBOX_FOCUS_CHANGE_EXPLICIT);
776 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxFocusChanged::ID));
779 TEST_F(SearchIPCRouterTest, SendSetInputInProgress) {
780 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
781 SetupMockDelegateAndPolicy();
782 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
783 EXPECT_CALL(*policy, ShouldSendSetInputInProgress(true)).Times(1)
784 .WillOnce(testing::Return(true));
786 process()->sink().ClearMessages();
787 GetSearchIPCRouter().SetInputInProgress(true);
788 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxSetInputInProgress::ID));
791 TEST_F(SearchIPCRouterTest, DoNotSendSetInputInProgress) {
792 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
793 SetupMockDelegateAndPolicy();
794 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
795 EXPECT_CALL(*policy, ShouldSendSetInputInProgress(true)).Times(1)
796 .WillOnce(testing::Return(false));
798 process()->sink().ClearMessages();
799 GetSearchIPCRouter().SetInputInProgress(true);
800 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSetInputInProgress::ID));
803 TEST_F(SearchIPCRouterTest, SendMostVisitedItemsMsg) {
804 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
805 SetupMockDelegateAndPolicy();
806 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
807 EXPECT_CALL(*policy, ShouldSendMostVisitedItems()).Times(1)
808 .WillOnce(testing::Return(true));
810 process()->sink().ClearMessages();
811 GetSearchIPCRouter().SendMostVisitedItems(
812 std::vector<InstantMostVisitedItem>());
813 EXPECT_TRUE(MessageWasSent(
814 ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID));
817 TEST_F(SearchIPCRouterTest, DoNotSendMostVisitedItemsMsg) {
818 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
819 SetupMockDelegateAndPolicy();
820 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
821 EXPECT_CALL(*policy, ShouldSendMostVisitedItems()).Times(1)
822 .WillOnce(testing::Return(false));
824 process()->sink().ClearMessages();
825 GetSearchIPCRouter().SendMostVisitedItems(
826 std::vector<InstantMostVisitedItem>());
827 EXPECT_FALSE(MessageWasSent(
828 ChromeViewMsg_SearchBoxMostVisitedItemsChanged::ID));
831 TEST_F(SearchIPCRouterTest, SendThemeBackgroundInfoMsg) {
832 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
833 SetupMockDelegateAndPolicy();
834 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
835 EXPECT_CALL(*policy, ShouldSendThemeBackgroundInfo()).Times(1)
836 .WillOnce(testing::Return(true));
838 process()->sink().ClearMessages();
839 GetSearchIPCRouter().SendThemeBackgroundInfo(ThemeBackgroundInfo());
840 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID));
843 TEST_F(SearchIPCRouterTest, DoNotSendThemeBackgroundInfoMsg) {
844 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
845 SetupMockDelegateAndPolicy();
846 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
847 EXPECT_CALL(*policy, ShouldSendThemeBackgroundInfo()).Times(1)
848 .WillOnce(testing::Return(false));
850 process()->sink().ClearMessages();
851 GetSearchIPCRouter().SendThemeBackgroundInfo(ThemeBackgroundInfo());
852 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxThemeChanged::ID));
855 TEST_F(SearchIPCRouterTest, SendSubmitMsg) {
856 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
857 SetupMockDelegateAndPolicy();
858 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
859 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1)
860 .WillOnce(testing::Return(true));
862 process()->sink().ClearMessages();
863 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams());
864 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID));
867 TEST_F(SearchIPCRouterTest, DoNotSendSubmitMsg) {
868 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
869 SetupMockDelegateAndPolicy();
870 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
871 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1)
872 .WillOnce(testing::Return(false));
874 process()->sink().ClearMessages();
875 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams());
876 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID));
879 TEST_F(SearchIPCRouterTest, SendToggleVoiceSearch) {
880 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
881 SetupMockDelegateAndPolicy();
882 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
883 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
884 .WillOnce(testing::Return(true));
886 process()->sink().ClearMessages();
887 GetSearchIPCRouter().ToggleVoiceSearch();
888 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
891 TEST_F(SearchIPCRouterTest, DoNotSendToggleVoiceSearch) {
892 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
893 SetupMockDelegateAndPolicy();
894 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
895 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
896 .WillOnce(testing::Return(false));
898 process()->sink().ClearMessages();
899 GetSearchIPCRouter().ToggleVoiceSearch();
900 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
903 TEST_F(SearchIPCRouterTest, SpuriousMessageTypesIgnored) {
904 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
905 SetupMockDelegateAndPolicy();
906 const int routing_id = web_contents()->GetRoutingID();
908 // Construct a series of synthetic messages for each valid IPC message type,
909 // ensuring the router ignores them all.
910 for (int i = 0; i < LastIPCMsgStart; ++i) {
911 const int message_id = i << 16;
912 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i);
913 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW);
914 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i;