| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(OnSetVoiceSearchSupport, void(bool supports_voice_search)); |
| 50 MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state)); | 50 MOCK_METHOD1(FocusOmnibox, void(OmniboxFocusState state)); |
| 51 MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool)); | 51 MOCK_METHOD3(NavigateToURL, void(const GURL&, WindowOpenDisposition, bool)); |
| 52 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); | 52 MOCK_METHOD1(OnDeleteMostVisitedItem, void(const GURL& url)); |
| 53 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); | 53 MOCK_METHOD1(OnUndoMostVisitedDeletion, void(const GURL& url)); |
| 54 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); | 54 MOCK_METHOD0(OnUndoAllMostVisitedDeletions, void()); |
| 55 MOCK_METHOD1(OnLogEvent, void(NTPLoggingEventType event)); | 55 MOCK_METHOD2(OnLogEvent, void(NTPLoggingEventType event, int64 time)); |
| 56 MOCK_METHOD2(OnLogMostVisitedImpression, | 56 MOCK_METHOD2(OnLogMostVisitedImpression, |
| 57 void(int position, const base::string16& provider)); | 57 void(int position, const base::string16& provider)); |
| 58 MOCK_METHOD2(OnLogMostVisitedNavigation, | 58 MOCK_METHOD2(OnLogMostVisitedNavigation, |
| 59 void(int position, const base::string16& provider)); | 59 void(int position, const base::string16& provider)); |
| 60 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); | 60 MOCK_METHOD1(PasteIntoOmnibox, void(const base::string16&)); |
| 61 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); | 61 MOCK_METHOD1(OnChromeIdentityCheck, void(const base::string16& identity)); |
| 62 MOCK_METHOD0(OnHistorySyncCheck, void()); | 62 MOCK_METHOD0(OnHistorySyncCheck, void()); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { | 65 class MockSearchIPCRouterPolicy : public SearchIPCRouter::Policy { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 338 |
| 339 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate( | 339 OnMessageReceived(ChromeViewHostMsg_SearchBoxNavigate( |
| 340 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url, | 340 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), destination_url, |
| 341 CURRENT_TAB, true)); | 341 CURRENT_TAB, true)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) { | 344 TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) { |
| 345 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 345 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 346 SetupMockDelegateAndPolicy(); | 346 SetupMockDelegateAndPolicy(); |
| 347 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 347 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 348 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(1); | 348 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER, 123)).Times(1); |
| 349 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) | 349 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) |
| 350 .WillOnce(testing::Return(true)); | 350 .WillOnce(testing::Return(true)); |
| 351 | 351 |
| 352 content::WebContents* contents = web_contents(); | 352 content::WebContents* contents = web_contents(); |
| 353 OnMessageReceived(ChromeViewHostMsg_LogEvent( | 353 OnMessageReceived(ChromeViewHostMsg_LogEvent( |
| 354 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), NTP_MOUSEOVER)); | 354 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), NTP_MOUSEOVER, 123)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) { | 357 TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) { |
| 358 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); | 358 NavigateAndCommitActiveTab(GURL("chrome-search://foo/bar")); |
| 359 SetupMockDelegateAndPolicy(); | 359 SetupMockDelegateAndPolicy(); |
| 360 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 360 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 361 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); | 361 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER, 123)).Times(0); |
| 362 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) | 362 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) |
| 363 .WillOnce(testing::Return(false)); | 363 .WillOnce(testing::Return(false)); |
| 364 | 364 |
| 365 content::WebContents* contents = web_contents(); | 365 content::WebContents* contents = web_contents(); |
| 366 OnMessageReceived(ChromeViewHostMsg_LogEvent( | 366 OnMessageReceived(ChromeViewHostMsg_LogEvent( |
| 367 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), NTP_MOUSEOVER)); | 367 contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), NTP_MOUSEOVER, 123)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) { | 370 TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) { |
| 371 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 371 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 372 SetupMockDelegateAndPolicy(); | 372 SetupMockDelegateAndPolicy(); |
| 373 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); | 373 MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| 374 EXPECT_CALL(*mock_delegate(), | 374 EXPECT_CALL(*mock_delegate(), |
| 375 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1); | 375 OnLogMostVisitedImpression(3, base::ASCIIToUTF16("Server"))).Times(1); |
| 376 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) | 376 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(1) |
| 377 .WillOnce(testing::Return(true)); | 377 .WillOnce(testing::Return(true)); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); | 567 EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); |
| 568 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); | 568 EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); |
| 569 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( | 569 OnMessageReceived(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( |
| 570 contents->GetRoutingID(), page_seq_no)); | 570 contents->GetRoutingID(), page_seq_no)); |
| 571 | 571 |
| 572 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); | 572 EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); |
| 573 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); | 573 EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); |
| 574 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox( | 574 OnMessageReceived(ChromeViewHostMsg_FocusOmnibox( |
| 575 contents->GetRoutingID(), page_seq_no, OMNIBOX_FOCUS_VISIBLE)); | 575 contents->GetRoutingID(), page_seq_no, OMNIBOX_FOCUS_VISIBLE)); |
| 576 | 576 |
| 577 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); | 577 EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER, 12)).Times(0); |
| 578 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); | 578 EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); |
| 579 OnMessageReceived(ChromeViewHostMsg_LogEvent( | 579 OnMessageReceived(ChromeViewHostMsg_LogEvent(contents->GetRoutingID(), |
| 580 contents->GetRoutingID(), page_seq_no, NTP_MOUSEOVER)); | 580 page_seq_no, NTP_MOUSEOVER, 12)); |
| 581 | 581 |
| 582 base::string16 text; | 582 base::string16 text; |
| 583 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); | 583 EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); |
| 584 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); | 584 EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); |
| 585 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown( | 585 OnMessageReceived(ChromeViewHostMsg_PasteAndOpenDropdown( |
| 586 contents->GetRoutingID(), page_seq_no, text)); | 586 contents->GetRoutingID(), page_seq_no, text)); |
| 587 } | 587 } |
| 588 | 588 |
| 589 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { | 589 TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { |
| 590 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); | 590 NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 | 899 |
| 900 // Construct a series of synthetic messages for each valid IPC message type, | 900 // Construct a series of synthetic messages for each valid IPC message type, |
| 901 // ensuring the router ignores them all. | 901 // ensuring the router ignores them all. |
| 902 for (int i = 0; i < LastIPCMsgStart; ++i) { | 902 for (int i = 0; i < LastIPCMsgStart; ++i) { |
| 903 const int message_id = i << 16; | 903 const int message_id = i << 16; |
| 904 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); | 904 ASSERT_EQ(IPC_MESSAGE_ID_CLASS(message_id), i); |
| 905 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); | 905 IPC::Message msg(routing_id, message_id, IPC::Message::PRIORITY_LOW); |
| 906 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; | 906 EXPECT_FALSE(OnSpuriousMessageReceived(msg)) << i; |
| 907 } | 907 } |
| 908 } | 908 } |
| OLD | NEW |