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

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

Issue 1436583002: Revert of Remove setVoiceSearchSupported part of EmbeddedSearch SearchBox API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 <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
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));
49 MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state)); 50 MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state));
50 MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool)); 51 MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool));
51 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); 52 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url));
52 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); 53 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url));
53 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); 54 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void());
54 MOCK_METHOD2(OnLogEvent, void(NTPLoggingEventType event, 55 MOCK_METHOD2(OnLogEvent, void(NTPLoggingEventType event,
55 base::TimeDelta time)); 56 base::TimeDelta time));
56 MOCK_METHOD2(OnLogMostVisitedImpression, 57 MOCK_METHOD2(OnLogMostVisitedImpression,
57 void(int position, const base::string16& provider)); 58 void(int position, const base::string16& provider));
58 MOCK_METHOD2(OnLogMostVisitedNavigation, 59 MOCK_METHOD2(OnLogMostVisitedNavigation,
59 void(int position, const base::string16& provider)); 60 void(int position, const base::string16& provider));
60 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); 61 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&));
61 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); 62 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity));
62 MOCK_METHOD0(OnHistorySyncCheck, void()); 63 MOCK_METHOD0(OnHistorySyncCheck, void());
63 }; 64 };
64 65
65 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { 66 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
66 public: 67 public:
67 virtual ~MockSearchIPCRouterPolicy() {} 68 virtual ~MockSearchIPCRouterPolicy() {}
68 69
70 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool());
69 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); 71 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool));
70 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool)); 72 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool));
71 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); 73 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool());
72 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); 74 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool());
73 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); 75 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool());
74 MOCK_METHOD0(ShouldProcessLogEvent, bool()); 76 MOCK_METHOD0(ShouldProcessLogEvent, bool());
75 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); 77 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool));
76 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); 78 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool());
77 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool()); 79 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool());
78 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); 80 MOCK_METHOD0(ShouldSendSetPromoInformation, bool());
79 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); 81 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool());
80 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); 82 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool());
81 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool()); 83 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool());
82 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); 84 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool));
83 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); 85 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
84 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); 86 MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
85 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); 87 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool());
88 MOCK_METHOD0(ShouldSendToggleVoiceSearch, bool());
86 MOCK_METHOD0(ShouldSubmitQuery, bool()); 89 MOCK_METHOD0(ShouldSubmitQuery, bool());
87 }; 90 };
88 91
89 } // namespace 92 } // namespace
90 93
91 class SearchIPCRouterTest : public BrowserWithTestWindowTest { 94 class SearchIPCRouterTest : public BrowserWithTestWindowTest {
92 public: 95 public:
93 SearchIPCRouterTest() : field_trial_list_(NULL) {} 96 SearchIPCRouterTest() : field_trial_list_(NULL) {}
94 97
95 void SetUp() override { 98 void SetUp() override {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 EXPECT_TRUE(is_active_tab); 219 EXPECT_TRUE(is_active_tab);
217 220
218 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 221 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
219 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); 222 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
220 223
221 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate( 224 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
222 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url, 225 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
223 CURRENT_TAB, true)); 226 CURRENT_TAB, true));
224 } 227 }
225 228
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
226 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { 255 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) {
227 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 256 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
228 SetupMockDelegateAndPolicy(); 257 SetupMockDelegateAndPolicy();
229 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 258 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
230 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); 259 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1);
231 260
232 content::WebContents* contents = web_contents(); 261 content::WebContents* contents = web_contents();
233 bool is_active_tab = IsActiveTab(contents); 262 bool is_active_tab = IsActiveTab(contents);
234 EXPECT_TRUE(is_active_tab); 263 EXPECT_TRUE(is_active_tab);
235 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 264 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 SetupMockDelegateAndPolicy(); 870 SetupMockDelegateAndPolicy();
842 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 871 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
843 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1) 872 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1)
844 .WillOnce(testing::Return(false)); 873 .WillOnce(testing::Return(false));
845 874
846 process()->sink().ClearMessages(); 875 process()->sink().ClearMessages();
847 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams()); 876 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams());
848 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID)); 877 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID));
849 } 878 }
850 879
880 TEST_F(SearchIPCRouterTest, SendToggleVoiceSearch) {
881 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
882 SetupMockDelegateAndPolicy();
883 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
884 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
885 .WillOnce(testing::Return(true));
886
887 process()->sink().ClearMessages();
888 GetSearchIPCRouter().ToggleVoiceSearch();
889 EXPECT_TRUE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
890 }
891
892 TEST_F(SearchIPCRouterTest, DoNotSendToggleVoiceSearch) {
893 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
894 SetupMockDelegateAndPolicy();
895 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
896 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
897 .WillOnce(testing::Return(false));
898
899 process()->sink().ClearMessages();
900 GetSearchIPCRouter().ToggleVoiceSearch();
901 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
902 }
903
851 TEST_F(SearchIPCRouterTest, SpuriousMessageTypesIgnored) { 904 TEST_F(SearchIPCRouterTest, SpuriousMessageTypesIgnored) {
852 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 905 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
853 SetupMockDelegateAndPolicy(); 906 SetupMockDelegateAndPolicy();
854 const int routing_id = web_contents()->GetRoutingID(); 907 const int routing_id = web_contents()->GetRoutingID();
855 908
856 // Construct a series of synthetic messages for each valid IPC message type, 909 // Construct a series of synthetic messages for each valid IPC message type,
857 // ensuring the router ignores them all. 910 // ensuring the router ignores them all.
858 for (int i = 0; i < LastIPCMsgStart; ++i) { 911 for (int i = 0; i < LastIPCMsgStart; ++i) {
859 const int message_id = i << 16; 912 const int message_id = i << 16;
860 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); 913 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i);
861 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); 914 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW);
862 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; 915 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i;
863 } 916 }
864 } 917 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ipc_router_policy_unittest.cc ('k') | chrome/browser/ui/search/search_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698