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

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

Issue 1428423002: Remove setVoiceSearchSupported part of EmbeddedSearch SearchBox API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mac fix 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));
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());
81 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); 79 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool());
82 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); 80 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool());
83 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool()); 81 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool());
84 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); 82 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool));
85 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); 83 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
86 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); 84 MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
87 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); 85 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool());
88 MOCK_METHOD0(ShouldSendToggleVoiceSearch, bool());
89 MOCK_METHOD0(ShouldSubmitQuery, bool()); 86 MOCK_METHOD0(ShouldSubmitQuery, bool());
90 }; 87 };
91 88
92 } // namespace 89 } // namespace
93 90
94 class SearchIPCRouterTest : public BrowserWithTestWindowTest { 91 class SearchIPCRouterTest : public BrowserWithTestWindowTest {
95 public: 92 public:
96 SearchIPCRouterTest() : field_trial_list_(NULL) {} 93 SearchIPCRouterTest() : field_trial_list_(NULL) {}
97 94
98 void SetUp() override { 95 void SetUp() override {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 EXPECT_TRUE(is_active_tab); 216 EXPECT_TRUE(is_active_tab);
220 217
221 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 218 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
222 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); 219 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
223 220
224 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate( 221 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
225 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url, 222 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
226 CURRENT_TAB, true)); 223 CURRENT_TAB, true));
227 } 224 }
228 225
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) { 226 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) {
256 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 227 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
257 SetupMockDelegateAndPolicy(); 228 SetupMockDelegateAndPolicy();
258 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 229 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
259 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); 230 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1);
260 231
261 content::WebContents* contents = web_contents(); 232 content::WebContents* contents = web_contents();
262 bool is_active_tab = IsActiveTab(contents); 233 bool is_active_tab = IsActiveTab(contents);
263 EXPECT_TRUE(is_active_tab); 234 EXPECT_TRUE(is_active_tab);
264 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 235 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 SetupMockDelegateAndPolicy(); 841 SetupMockDelegateAndPolicy();
871 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 842 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
872 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1) 843 EXPECT_CALL(*policy, ShouldSubmitQuery()).Times(1)
873 .WillOnce(testing::Return(false)); 844 .WillOnce(testing::Return(false));
874 845
875 process()->sink().ClearMessages(); 846 process()->sink().ClearMessages();
876 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams()); 847 GetSearchIPCRouter().Submit(base::string16(), EmbeddedSearchRequestParams());
877 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID)); 848 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxSubmit::ID));
878 } 849 }
879 850
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
904 TEST_F(SearchIPCRouterTest, SpuriousMessageTypesIgnored) { 851 TEST_F(SearchIPCRouterTest, SpuriousMessageTypesIgnored) {
905 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 852 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
906 SetupMockDelegateAndPolicy(); 853 SetupMockDelegateAndPolicy();
907 const int routing_id = web_contents()->GetRoutingID(); 854 const int routing_id = web_contents()->GetRoutingID();
908 855
909 // Construct a series of synthetic messages for each valid IPC message type, 856 // Construct a series of synthetic messages for each valid IPC message type,
910 // ensuring the router ignores them all. 857 // ensuring the router ignores them all.
911 for (int i = 0; i < LastIPCMsgStart; ++i) { 858 for (int i = 0; i < LastIPCMsgStart; ++i) {
912 const int message_id = i << 16; 859 const int message_id = i << 16;
913 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); 860 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i);
914 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); 861 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW);
915 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; 862 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i;
916 } 863 }
917 } 864 }
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