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

Side by Side Diff: chrome/browser/ui/search/search_ipc_router_unittest.cc

Issue 2149973002: Remove embeddedSearch.searchBox.displayInstantResults (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@searchbox_applauncher
Patch Set: rebase Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <tuple> 10 #include <tuple>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 virtual ~MockSearchIPCRouterPolicy() {} 69 virtual ~MockSearchIPCRouterPolicy() {}
70 70
71 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); 71 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool));
72 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); 72 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool());
73 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); 73 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool());
74 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); 74 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool());
75 MOCK_METHOD0(ShouldProcessLogEvent, bool()); 75 MOCK_METHOD0(ShouldProcessLogEvent, bool());
76 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); 76 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool));
77 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); 77 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool());
78 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); 78 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool());
79 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool());
80 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); 79 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool());
81 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); 80 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool));
82 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); 81 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
83 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); 82 MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
84 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); 83 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool());
85 MOCK_METHOD0(ShouldSubmitQuery, bool()); 84 MOCK_METHOD0(ShouldSubmitQuery, bool());
86 }; 85 };
87 86
88 } // namespace 87 } // namespace
89 88
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); 139 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
141 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate()); 140 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate());
142 search_tab_helper->ipc_router().set_policy_for_testing( 141 search_tab_helper->ipc_router().set_policy_for_testing(
143 base::WrapUnique(new MockSearchIPCRouterPolicy)); 142 base::WrapUnique(new MockSearchIPCRouterPolicy));
144 } 143 }
145 144
146 bool MessageWasSent(uint32_t id) { 145 bool MessageWasSent(uint32_t id) {
147 return process()->sink().GetFirstMessageMatching(id) != NULL; 146 return process()->sink().GetFirstMessageMatching(id) != NULL;
148 } 147 }
149 148
150 void VerifyDisplayInstantResultsMsg(bool expected_param_value) {
151 SetupMockDelegateAndPolicy();
152 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
153 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1)
154 .WillOnce(testing::Return(true));
155
156 GetSearchIPCRouter().SetDisplayInstantResults();
157 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
158 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID);
159 EXPECT_NE(static_cast<const IPC::Message*>(NULL), message);
160 std::tuple<bool> display_instant_results_param;
161 ChromeViewMsg_SearchBoxSetDisplayInstantResults::Read(
162 message, &display_instant_results_param);
163 EXPECT_EQ(expected_param_value,
164 std::get<0>(display_instant_results_param));
165 }
166
167 MockSearchIPCRouterDelegate* mock_delegate() { return &delegate_; } 149 MockSearchIPCRouterDelegate* mock_delegate() { return &delegate_; }
168 150
169 MockSearchIPCRouterPolicy* GetSearchIPCRouterPolicy() { 151 MockSearchIPCRouterPolicy* GetSearchIPCRouterPolicy() {
170 content::WebContents* contents = web_contents(); 152 content::WebContents* contents = web_contents();
171 EXPECT_NE(static_cast<content::WebContents*>(NULL), contents); 153 EXPECT_NE(static_cast<content::WebContents*>(NULL), contents);
172 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); 154 SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents);
173 EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); 155 EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper);
174 return static_cast<MockSearchIPCRouterPolicy*>( 156 return static_cast<MockSearchIPCRouterPolicy*>(
175 search_tab_helper->ipc_router().policy_for_testing()); 157 search_tab_helper->ipc_router().policy_for_testing());
176 } 158 }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 EXPECT_TRUE(is_active_tab); 528 EXPECT_TRUE(is_active_tab);
547 529
548 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 530 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
549 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 531 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
550 .WillOnce(testing::Return(false)); 532 .WillOnce(testing::Return(false));
551 533
552 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown( 534 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
553 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text)); 535 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
554 } 536 }
555 537
556 TEST_F(SearchIPCRouterTest,
557 SendSetDisplayInstantResultsMsg_EnableInstantOnResultsPage) {
558 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
559 "EmbeddedSearch",
560 "Group1 espv:42 query_extraction:1 prefetch_results_srp:1"));
561 NavigateAndCommitActiveTab(GURL("https://foo.com/url?espv&bar=abc"));
562
563 // Make sure ChromeViewMsg_SearchBoxSetDisplayInstantResults message param is
564 // set to true if the underlying page is a results page and
565 // "prefetch_results_srp" flag is enabled via field trials.
566 VerifyDisplayInstantResultsMsg(true);
567 }
568
569 TEST_F(SearchIPCRouterTest,
570 SendSetDisplayInstantResultsMsg_DisableInstantOnResultsPage) {
571 // |prefetch_results_srp" flag is disabled via field trials.
572 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
573 "EmbeddedSearch",
574 "Group1 espv:42 query_extraction:1 prefetch_results_srp:0"));
575 NavigateAndCommitActiveTab(GURL("https://foo.com/url?espv&bar=abc"));
576
577 // Make sure ChromeViewMsg_SearchBoxSetDisplayInstantResults message param is
578 // set to false.
579 VerifyDisplayInstantResultsMsg(false);
580 }
581
582 TEST_F(SearchIPCRouterTest,
583 SendSetDisplayInstantResultsMsg_EnableInstantOutsideSearchResultsPage) {
584 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
585 // Make sure ChromeViewMsg_SearchBoxSetDisplayInstantResults param is set to
586 // true if the underlying page is not a search results page.
587 VerifyDisplayInstantResultsMsg(true);
588 }
589
590 TEST_F(SearchIPCRouterTest, DoNotSendSetDisplayInstantResultsMsg) {
591 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
592 SetupMockDelegateAndPolicy();
593 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
594 EXPECT_CALL(*policy, ShouldSendSetDisplayInstantResults()).Times(1)
595 .WillOnce(testing::Return(false));
596
597 process()->sink().ClearMessages();
598 GetSearchIPCRouter().SetDisplayInstantResults();
599 EXPECT_FALSE(MessageWasSent(
600 ChromeViewMsg_SearchBoxSetDisplayInstantResults::ID));
601 }
602
603 TEST_F(SearchIPCRouterTest, SendSetSuggestionToPrefetch) { 538 TEST_F(SearchIPCRouterTest, SendSetSuggestionToPrefetch) {
604 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 539 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
605 SetupMockDelegateAndPolicy(); 540 SetupMockDelegateAndPolicy();
606 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 541 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
607 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1) 542 EXPECT_CALL(*policy, ShouldSendSetSuggestionToPrefetch()).Times(1)
608 .WillOnce(testing::Return(true)); 543 .WillOnce(testing::Return(true));
609 544
610 process()->sink().ClearMessages(); 545 process()->sink().ClearMessages();
611 content::WebContents* contents = web_contents(); 546 content::WebContents* contents = web_contents();
612 GetSearchTabHelper(contents)->SetSuggestionToPrefetch(InstantSuggestion()); 547 GetSearchTabHelper(contents)->SetSuggestionToPrefetch(InstantSuggestion());
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 696
762 // Construct a series of synthetic messages for each valid IPC message type, 697 // Construct a series of synthetic messages for each valid IPC message type,
763 // ensuring the router ignores them all. 698 // ensuring the router ignores them all.
764 for (int i = 0; i < LastIPCMsgStart; ++i) { 699 for (int i = 0; i < LastIPCMsgStart; ++i) {
765 const int message_id = i << 16; 700 const int message_id = i << 16;
766 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); 701 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i);
767 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); 702 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW);
768 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; 703 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i;
769 } 704 }
770 } 705 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698