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

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

Issue 701973002: Separate checking the user identity and checking if the user is syncing his history in two differen… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Answered kmadhusu and dcheng Created 6 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); 51 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url));
52 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); 52 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url));
53 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); 53 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void());
54 MOCK_METHOD1(OnLogEvent, void(NTPLoggingEventType event)); 54 MOCK_METHOD1(OnLogEvent, void(NTPLoggingEventType event));
55 MOCK_METHOD2(OnLogMostVisitedImpression, 55 MOCK_METHOD2(OnLogMostVisitedImpression,
56 void(int position, const base::string16& provider)); 56 void(int position, const base::string16& provider));
57 MOCK_METHOD2(OnLogMostVisitedNavigation, 57 MOCK_METHOD2(OnLogMostVisitedNavigation,
58 void(int position, const base::string16& provider)); 58 void(int position, const base::string16& provider));
59 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); 59 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&));
60 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); 60 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity));
61 MOCK_METHOD0(OnHistorySyncCheck, void());
61 }; 62 };
62 63
63 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { 64 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy {
64 public: 65 public:
65 virtual ~MockSearchIPCRouterPolicy() {} 66 virtual ~MockSearchIPCRouterPolicy() {}
66 67
67 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool()); 68 MOCK_METHOD0(ShouldProcessSetVoiceSearchSupport, bool());
68 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool)); 69 MOCK_METHOD1(ShouldProcessFocusOmnibox, bool(bool));
69 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool)); 70 MOCK_METHOD1(ShouldProcessNavigateToURL, bool(bool));
70 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool()); 71 MOCK_METHOD0(ShouldProcessDeleteMostVisitedItem, bool());
71 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool()); 72 MOCK_METHOD0(ShouldProcessUndoMostVisitedDeletion, bool());
72 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool()); 73 MOCK_METHOD0(ShouldProcessUndoAllMostVisitedDeletions, bool());
73 MOCK_METHOD0(ShouldProcessLogEvent, bool()); 74 MOCK_METHOD0(ShouldProcessLogEvent, bool());
74 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool)); 75 MOCK_METHOD1(ShouldProcessPasteIntoOmnibox, bool(bool));
75 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool()); 76 MOCK_METHOD0(ShouldProcessChromeIdentityCheck, bool());
77 MOCK_METHOD0(ShouldProcessHistorySyncCheck, bool());
76 MOCK_METHOD0(ShouldSendSetPromoInformation, bool()); 78 MOCK_METHOD0(ShouldSendSetPromoInformation, bool());
77 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool()); 79 MOCK_METHOD0(ShouldSendSetDisplayInstantResults, bool());
78 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool()); 80 MOCK_METHOD0(ShouldSendSetSuggestionToPrefetch, bool());
79 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool()); 81 MOCK_METHOD0(ShouldSendSetOmniboxStartMargin, bool());
80 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool)); 82 MOCK_METHOD1(ShouldSendSetInputInProgress, bool(bool));
81 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool()); 83 MOCK_METHOD0(ShouldSendOmniboxFocusChanged, bool());
82 MOCK_METHOD0(ShouldSendMostVisitedItems, bool()); 84 MOCK_METHOD0(ShouldSendMostVisitedItems, bool());
83 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool()); 85 MOCK_METHOD0(ShouldSendThemeBackgroundInfo, bool());
84 MOCK_METHOD0(ShouldSendToggleVoiceSearch, bool()); 86 MOCK_METHOD0(ShouldSendToggleVoiceSearch, bool());
85 MOCK_METHOD0(ShouldSubmitQuery, bool()); 87 MOCK_METHOD0(ShouldSubmitQuery, bool());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 GURL destination_url("www.foo.com"); 206 GURL destination_url("www.foo.com");
205 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, 207 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
206 true)).Times(0); 208 true)).Times(0);
207 content::WebContents* contents = web_contents(); 209 content::WebContents* contents = web_contents();
208 bool is_active_tab = IsActiveTab(contents); 210 bool is_active_tab = IsActiveTab(contents);
209 EXPECT_TRUE(is_active_tab); 211 EXPECT_TRUE(is_active_tab);
210 212
211 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 213 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
212 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); 214 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
213 215
214 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 216 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
215 contents->GetRoutingID(), 217 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
216 GetSearchIPCRouterSeqNo(), 218 CURRENT_TAB, true));
217 destination_url, CURRENT_TAB, true));
218 OnMessageReceived(*message);
219 } 219 }
220 220
221 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) { 221 TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) {
222 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 222 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
223 SetupMockDelegateAndPolicy(); 223 SetupMockDelegateAndPolicy();
224 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 224 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
225 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1); 225 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(1);
226 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1) 226 EXPECT_CALL(*(policy), ShouldProcessSetVoiceSearchSupport()).Times(1)
227 .WillOnce(testing::Return(true)); 227 .WillOnce(testing::Return(true));
228 228
229 content::WebContents* contents = web_contents(); 229 content::WebContents* contents = web_contents();
230 scoped_ptr<IPC::Message> message( 230 OnMessageReceived(ChromeViewHostMsg_SetVoiceSearchSupported(
231 new ChromeViewHostMsg_SetVoiceSearchSupported( 231 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
232 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
233 OnMessageReceived(*message);
234 } 232 }
235 233
236 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) { 234 TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) {
237 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 235 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
238 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0); 236 EXPECT_CALL(*mock_delegate(), OnSetVoiceSearchSupport(true)).Times(0);
239 SetupMockDelegateAndPolicy(); 237 SetupMockDelegateAndPolicy();
240 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 238 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
241 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1) 239 EXPECT_CALL(*policy, ShouldProcessSetVoiceSearchSupport()).Times(1)
242 .WillOnce(testing::Return(false)); 240 .WillOnce(testing::Return(false));
243 241
244 content::WebContents* contents = web_contents(); 242 content::WebContents* contents = web_contents();
245 scoped_ptr<IPC::Message> message( 243 OnMessageReceived(ChromeViewHostMsg_SetVoiceSearchSupported(
246 new ChromeViewHostMsg_SetVoiceSearchSupported( 244 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
247 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), true));
248 OnMessageReceived(*message);
249 } 245 }
250 246
251 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { 247 TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) {
252 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 248 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
253 SetupMockDelegateAndPolicy(); 249 SetupMockDelegateAndPolicy();
254 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 250 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
255 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1); 251 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(1);
256 252
257 content::WebContents* contents = web_contents(); 253 content::WebContents* contents = web_contents();
258 bool is_active_tab = IsActiveTab(contents); 254 bool is_active_tab = IsActiveTab(contents);
259 EXPECT_TRUE(is_active_tab); 255 EXPECT_TRUE(is_active_tab);
260 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 256 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
261 .WillOnce(testing::Return(true)); 257 .WillOnce(testing::Return(true));
262 258
263 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( 259 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
264 contents->GetRoutingID(), 260 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
265 GetSearchIPCRouterSeqNo(),
266 OMNIBOX_FOCUS_VISIBLE)); 261 OMNIBOX_FOCUS_VISIBLE));
267 OnMessageReceived(*message);
268 } 262 }
269 263
270 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) { 264 TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) {
271 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 265 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
272 SetupMockDelegateAndPolicy(); 266 SetupMockDelegateAndPolicy();
273 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 267 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
274 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 268 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
275 269
276 content::WebContents* contents = web_contents(); 270 content::WebContents* contents = web_contents();
277 bool is_active_tab = IsActiveTab(contents); 271 bool is_active_tab = IsActiveTab(contents);
278 EXPECT_TRUE(is_active_tab); 272 EXPECT_TRUE(is_active_tab);
279 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1) 273 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(1)
280 .WillOnce(testing::Return(false)); 274 .WillOnce(testing::Return(false));
281 275
282 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( 276 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
283 contents->GetRoutingID(), 277 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(),
284 GetSearchIPCRouterSeqNo(),
285 OMNIBOX_FOCUS_VISIBLE)); 278 OMNIBOX_FOCUS_VISIBLE));
286 OnMessageReceived(*message);
287 } 279 }
288 280
289 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) { 281 TEST_F(SearchIPCRouterTest, HandleTabChangedEvents) {
290 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 282 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
291 content::WebContents* contents = web_contents(); 283 content::WebContents* contents = web_contents();
292 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents)); 284 EXPECT_EQ(0, browser()->tab_strip_model()->GetIndexOfWebContents(contents));
293 EXPECT_TRUE(IsActiveTab(contents)); 285 EXPECT_TRUE(IsActiveTab(contents));
294 286
295 // Add a new tab to deactivate the current tab. 287 // Add a new tab to deactivate the current tab.
296 AddTab(browser(), GURL(url::kAboutBlankURL)); 288 AddTab(browser(), GURL(url::kAboutBlankURL));
(...skipping 16 matching lines...) Expand all
313 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, 305 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
314 true)).Times(1); 306 true)).Times(1);
315 content::WebContents* contents = web_contents(); 307 content::WebContents* contents = web_contents();
316 bool is_active_tab = IsActiveTab(contents); 308 bool is_active_tab = IsActiveTab(contents);
317 EXPECT_TRUE(is_active_tab); 309 EXPECT_TRUE(is_active_tab);
318 310
319 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 311 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
320 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 312 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
321 .WillOnce(testing::Return(true)); 313 .WillOnce(testing::Return(true));
322 314
323 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 315 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
324 contents->GetRoutingID(), 316 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
325 GetSearchIPCRouterSeqNo(), 317 CURRENT_TAB, true));
326 destination_url, CURRENT_TAB, true));
327 OnMessageReceived(*message);
328 } 318 }
329 319
330 TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) { 320 TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) {
331 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 321 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
332 SetupMockDelegateAndPolicy(); 322 SetupMockDelegateAndPolicy();
333 GURL destination_url("www.foo.com"); 323 GURL destination_url("www.foo.com");
334 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB, 324 EXPECT_CALL(*mock_delegate(), NavigateToURL(destination_url, CURRENT_TAB,
335 true)).Times(0); 325 true)).Times(0);
336 content::WebContents* contents = web_contents(); 326 content::WebContents* contents = web_contents();
337 bool is_active_tab = IsActiveTab(contents); 327 bool is_active_tab = IsActiveTab(contents);
338 EXPECT_TRUE(is_active_tab); 328 EXPECT_TRUE(is_active_tab);
339 329
340 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 330 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
341 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1) 331 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(1)
342 .WillOnce(testing::Return(false)); 332 .WillOnce(testing::Return(false));
343 333
344 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 334 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
345 contents->GetRoutingID(), 335 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url,
346 GetSearchIPCRouterSeqNo(), 336 CURRENT_TAB, true));
347 destination_url, CURRENT_TAB, true));
348 OnMessageReceived(*message);
349 } 337 }
350 338
351 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) { 339 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) {
352 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 340 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
353 SetupMockDelegateAndPolicy(); 341 SetupMockDelegateAndPolicy();
354 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 342 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
355 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(1); 343 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(1);
356 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 344 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
357 .WillOnce(testing::Return(true)); 345 .WillOnce(testing::Return(true));
358 346
359 content::WebContents* contents = web_contents(); 347 content::WebContents* contents = web_contents();
360 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( 348 OnMessageReceived(ChromeViewHostMsg_LogEvent(
361 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 349 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), NTP_MOUSEOVER));
362 NTP_MOUSEOVER));
363 OnMessageReceived(*message);
364 } 350 }
365 351
366 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) { 352 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) {
367 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 353 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
368 SetupMockDelegateAndPolicy(); 354 SetupMockDelegateAndPolicy();
369 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 355 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
370 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); 356 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0);
371 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 357 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
372 .WillOnce(testing::Return(false)); 358 .WillOnce(testing::Return(false));
373 359
374 content::WebContents* contents = web_contents(); 360 content::WebContents* contents = web_contents();
375 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( 361 OnMessageReceived(ChromeViewHostMsg_LogEvent(
376 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 362 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), NTP_MOUSEOVER));
377 NTP_MOUSEOVER));
378 OnMessageReceived(*message);
379 } 363 }
380 364
381 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) { 365 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) {
382 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 366 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
383 SetupMockDelegateAndPolicy(); 367 SetupMockDelegateAndPolicy();
384 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 368 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
385 EXPECT_CALL(*mock_delegate(), 369 EXPECT_CALL(*mock_delegate(),
386 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1); 370 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1);
387 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 371 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
388 .WillOnce(testing::Return(true)); 372 .WillOnce(testing::Return(true));
389 373
390 content::WebContents* contents = web_contents(); 374 content::WebContents* contents = web_contents();
391 scoped_ptr<IPC::Message> message( 375 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedImpression(
392 new ChromeViewHostMsg_LogMostVisitedImpression( 376 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 3,
393 contents->GetRoutingID(),
394 GetSearchIPCRouterSeqNo(),
395 3,
396 base::ASCIIToUTF16("Server"))); 377 base::ASCIIToUTF16("Server")));
397 OnMessageReceived(*message);
398 } 378 }
399 379
400 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) { 380 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) {
401 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 381 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
402 SetupMockDelegateAndPolicy(); 382 SetupMockDelegateAndPolicy();
403 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 383 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
404 EXPECT_CALL(*mock_delegate(), 384 EXPECT_CALL(*mock_delegate(),
405 OnLogMostVisitedNavigation(3, base::ASCIIToUTF16("Server"))).Times(1); 385 OnLogMostVisitedNavigation(3, base::ASCIIToUTF16("Server"))).Times(1);
406 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) 386 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1)
407 .WillOnce(testing::Return(true)); 387 .WillOnce(testing::Return(true));
408 388
409 content::WebContents* contents = web_contents(); 389 content::WebContents* contents = web_contents();
410 scoped_ptr<IPC::Message> message( 390 OnMessageReceived(ChromeViewHostMsg_LogMostVisitedNavigation(
411 new ChromeViewHostMsg_LogMostVisitedNavigation( 391 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), 3,
412 contents->GetRoutingID(),
413 GetSearchIPCRouterSeqNo(),
414 3,
415 base::ASCIIToUTF16("Server"))); 392 base::ASCIIToUTF16("Server")));
416 OnMessageReceived(*message);
417 } 393 }
418 394
419 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) { 395 TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) {
420 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 396 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
421 SetupMockDelegateAndPolicy(); 397 SetupMockDelegateAndPolicy();
422 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 398 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
423 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 399 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
424 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1); 400 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(1);
425 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 401 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
426 .WillOnce(testing::Return(true)); 402 .WillOnce(testing::Return(true));
427 403
428 content::WebContents* contents = web_contents(); 404 content::WebContents* contents = web_contents();
429 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( 405 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck(
430 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); 406 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
431 OnMessageReceived(*message);
432 } 407 }
433 408
434 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) { 409 TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) {
435 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 410 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
436 SetupMockDelegateAndPolicy(); 411 SetupMockDelegateAndPolicy();
437 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 412 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
438 413
439 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); 414 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com");
440 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0); 415 EXPECT_CALL(*mock_delegate(), OnChromeIdentityCheck(test_identity)).Times(0);
441 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1) 416 EXPECT_CALL(*policy, ShouldProcessChromeIdentityCheck()).Times(1)
442 .WillOnce(testing::Return(false)); 417 .WillOnce(testing::Return(false));
443 418
444 content::WebContents* contents = web_contents(); 419 content::WebContents* contents = web_contents();
445 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( 420 OnMessageReceived(ChromeViewHostMsg_ChromeIdentityCheck(
446 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); 421 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity));
447 OnMessageReceived(*message); 422 }
423
424 TEST_F(SearchIPCRouterTest, ProcessHistorySyncCheckMsg) {
425 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
426 SetupMockDelegateAndPolicy();
427 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
428 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(1);
429 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1)
430 .WillOnce(testing::Return(true));
431
432 content::WebContents* contents = web_contents();
433 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck(
434 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
435 }
436
437 TEST_F(SearchIPCRouterTest, IgnoreHistorySyncCheckMsg) {
438 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
439 SetupMockDelegateAndPolicy();
440 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
441
442 EXPECT_CALL(*mock_delegate(), OnHistorySyncCheck()).Times(0);
443 EXPECT_CALL(*policy, ShouldProcessHistorySyncCheck()).Times(1)
444 .WillOnce(testing::Return(false));
445
446 content::WebContents* contents = web_contents();
447 OnMessageReceived(ChromeViewHostMsg_HistorySyncCheck(
448 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
448 } 449 }
449 450
450 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) { 451 TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) {
451 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 452 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
452 SetupMockDelegateAndPolicy(); 453 SetupMockDelegateAndPolicy();
453 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 454 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
454 GURL item_url("www.foo.com"); 455 GURL item_url("www.foo.com");
455 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1); 456 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(1);
456 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 457 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
457 .WillOnce(testing::Return(true)); 458 .WillOnce(testing::Return(true));
458 459
459 content::WebContents* contents = web_contents(); 460 content::WebContents* contents = web_contents();
460 scoped_ptr<IPC::Message> message( 461 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
461 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 462 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
462 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
463 OnMessageReceived(*message);
464 } 463 }
465 464
466 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) { 465 TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) {
467 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 466 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
468 SetupMockDelegateAndPolicy(); 467 SetupMockDelegateAndPolicy();
469 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 468 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
470 GURL item_url("www.foo.com"); 469 GURL item_url("www.foo.com");
471 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 470 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
472 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1) 471 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(1)
473 .WillOnce(testing::Return(false)); 472 .WillOnce(testing::Return(false));
474 473
475 content::WebContents* contents = web_contents(); 474 content::WebContents* contents = web_contents();
476 scoped_ptr<IPC::Message> message( 475 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
477 new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 476 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
478 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
479 OnMessageReceived(*message);
480 } 477 }
481 478
482 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) { 479 TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) {
483 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 480 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
484 SetupMockDelegateAndPolicy(); 481 SetupMockDelegateAndPolicy();
485 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 482 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
486 GURL item_url("www.foo.com"); 483 GURL item_url("www.foo.com");
487 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1); 484 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(1);
488 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 485 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
489 .WillOnce(testing::Return(true)); 486 .WillOnce(testing::Return(true));
490 487
491 content::WebContents* contents = web_contents(); 488 content::WebContents* contents = web_contents();
492 scoped_ptr<IPC::Message> message( 489 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
493 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 490 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
494 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
495 OnMessageReceived(*message);
496 } 491 }
497 492
498 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) { 493 TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) {
499 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 494 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
500 SetupMockDelegateAndPolicy(); 495 SetupMockDelegateAndPolicy();
501 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 496 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
502 GURL item_url("www.foo.com"); 497 GURL item_url("www.foo.com");
503 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 498 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
504 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1) 499 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(1)
505 .WillOnce(testing::Return(false)); 500 .WillOnce(testing::Return(false));
506 501
507 content::WebContents* contents = web_contents(); 502 content::WebContents* contents = web_contents();
508 scoped_ptr<IPC::Message> message( 503 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
509 new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 504 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
510 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), item_url));
511 OnMessageReceived(*message);
512 } 505 }
513 506
514 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) { 507 TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) {
515 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 508 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
516 SetupMockDelegateAndPolicy(); 509 SetupMockDelegateAndPolicy();
517 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 510 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
518 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1); 511 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(1);
519 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 512 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
520 .WillOnce(testing::Return(true)); 513 .WillOnce(testing::Return(true));
521 514
522 content::WebContents* contents = web_contents(); 515 content::WebContents* contents = web_contents();
523 scoped_ptr<IPC::Message> message( 516 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
524 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 517 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
525 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
526 OnMessageReceived(*message);
527 } 518 }
528 519
529 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) { 520 TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) {
530 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 521 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
531 SetupMockDelegateAndPolicy(); 522 SetupMockDelegateAndPolicy();
532 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 523 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
533 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 524 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
534 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1) 525 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(1)
535 .WillOnce(testing::Return(false)); 526 .WillOnce(testing::Return(false));
536 527
537 content::WebContents* contents = web_contents(); 528 content::WebContents* contents = web_contents();
538 scoped_ptr<IPC::Message> message( 529 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
539 new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 530 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
540 contents->GetRoutingID(), GetSearchIPCRouterSeqNo()));
541 OnMessageReceived(*message);
542 } 531 }
543 532
544 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) { 533 TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) {
545 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 534 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
546 SetupMockDelegateAndPolicy(); 535 SetupMockDelegateAndPolicy();
547 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 536 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
548 int page_seq_no = GetSearchIPCRouterSeqNo(); 537 int page_seq_no = GetSearchIPCRouterSeqNo();
549 538
550 content::WebContents* contents = web_contents(); 539 content::WebContents* contents = web_contents();
551 bool is_active_tab = IsActiveTab(contents); 540 bool is_active_tab = IsActiveTab(contents);
552 GURL item_url("www.foo.com"); 541 GURL item_url("www.foo.com");
553 EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB, 542 EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB,
554 true)).Times(0); 543 true)).Times(0);
555 // At this point, in a real test, the navigation would cause the 544 // 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 545 // 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. 546 // we'll decrement the sequence number on this side to simulate it.
558 --page_seq_no; 547 --page_seq_no;
559 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); 548 EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0);
560 549 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate(
561 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( 550 contents->GetRoutingID(), page_seq_no, item_url, CURRENT_TAB, true));
562 contents->GetRoutingID(), page_seq_no, item_url,
563 CURRENT_TAB, true));
564 OnMessageReceived(*message);
565 551
566 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); 552 EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0);
567 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0); 553 EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0);
568 message.reset(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 554 OnMessageReceived(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
569 contents->GetRoutingID(), page_seq_no, item_url)); 555 contents->GetRoutingID(), page_seq_no, item_url));
570 OnMessageReceived(*message);
571 556
572 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); 557 EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0);
573 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0); 558 EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0);
574 message.reset(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( 559 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
575 contents->GetRoutingID(), page_seq_no, item_url)); 560 contents->GetRoutingID(), page_seq_no, item_url));
576 OnMessageReceived(*message);
577 561
578 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); 562 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0);
579 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); 563 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0);
580 message.reset(new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( 564 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
581 contents->GetRoutingID(), page_seq_no)); 565 contents->GetRoutingID(), page_seq_no));
582 OnMessageReceived(*message);
583 566
584 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); 567 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0);
585 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); 568 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0);
586 message.reset(new ChromeViewHostMsg_FocusOmnibox( 569 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox(
587 contents->GetRoutingID(), page_seq_no, 570 contents->GetRoutingID(), page_seq_no, OMNIBOX_FOCUS_VISIBLE));
588 OMNIBOX_FOCUS_VISIBLE));
589 OnMessageReceived(*message);
590 571
591 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); 572 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0);
592 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); 573 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0);
593 message.reset(new ChromeViewHostMsg_LogEvent(contents->GetRoutingID(), 574 OnMessageReceived(ChromeViewHostMsg_LogEvent(
594 page_seq_no, 575 contents->GetRoutingID(), page_seq_no, NTP_MOUSEOVER));
595 NTP_MOUSEOVER));
596 OnMessageReceived(*message);
597 576
598 base::string16 text; 577 base::string16 text;
599 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 578 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
600 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); 579 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0);
601 message.reset(new ChromeViewHostMsg_PasteAndOpenDropdown( 580 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
602 contents->GetRoutingID(), page_seq_no, text)); 581 contents->GetRoutingID(), page_seq_no, text));
603 OnMessageReceived(*message);
604 } 582 }
605 583
606 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { 584 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) {
607 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); 585 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl));
608 SetupMockDelegateAndPolicy(); 586 SetupMockDelegateAndPolicy();
609 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 587 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
610 588
611 content::WebContents* contents = web_contents(); 589 content::WebContents* contents = web_contents();
612 bool is_active_tab = IsActiveTab(contents); 590 bool is_active_tab = IsActiveTab(contents);
613 EXPECT_TRUE(is_active_tab); 591 EXPECT_TRUE(is_active_tab);
614 592
615 base::string16 text; 593 base::string16 text;
616 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1); 594 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(1);
617 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 595 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
618 .WillOnce(testing::Return(true)); 596 .WillOnce(testing::Return(true));
619 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( 597 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
620 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text)); 598 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
621 OnMessageReceived(*message);
622 } 599 }
623 600
624 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) { 601 TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) {
625 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 602 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
626 SetupMockDelegateAndPolicy(); 603 SetupMockDelegateAndPolicy();
627 base::string16 text; 604 base::string16 text;
628 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); 605 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0);
629 606
630 content::WebContents* contents = web_contents(); 607 content::WebContents* contents = web_contents();
631 bool is_active_tab = IsActiveTab(contents); 608 bool is_active_tab = IsActiveTab(contents);
632 EXPECT_TRUE(is_active_tab); 609 EXPECT_TRUE(is_active_tab);
633 610
634 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 611 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
635 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) 612 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1)
636 .WillOnce(testing::Return(false)); 613 .WillOnce(testing::Return(false));
637 614
638 scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( 615 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown(
639 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text)); 616 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text));
640 OnMessageReceived(*message);
641 } 617 }
642 618
643 TEST_F(SearchIPCRouterTest, SendSetPromoInformationMsg) { 619 TEST_F(SearchIPCRouterTest, SendSetPromoInformationMsg) {
644 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 620 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
645 SetupMockDelegateAndPolicy(); 621 SetupMockDelegateAndPolicy();
646 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 622 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
647 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1) 623 EXPECT_CALL(*policy, ShouldSendSetPromoInformation()).Times(1)
648 .WillOnce(testing::Return(true)); 624 .WillOnce(testing::Return(true));
649 625
650 GetSearchIPCRouter().SetPromoInformation(true); 626 GetSearchIPCRouter().SetPromoInformation(true);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); 879 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar"));
904 SetupMockDelegateAndPolicy(); 880 SetupMockDelegateAndPolicy();
905 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); 881 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy();
906 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1) 882 EXPECT_CALL(*policy, ShouldSendToggleVoiceSearch()).Times(1)
907 .WillOnce(testing::Return(false)); 883 .WillOnce(testing::Return(false));
908 884
909 process()->sink().ClearMessages(); 885 process()->sink().ClearMessages();
910 GetSearchIPCRouter().ToggleVoiceSearch(); 886 GetSearchIPCRouter().ToggleVoiceSearch();
911 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID)); 887 EXPECT_FALSE(MessageWasSent(ChromeViewMsg_SearchBoxToggleVoiceSearch::ID));
912 } 888 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698