Chromium Code Reviews| Index: chrome/browser/ui/search/search_ipc_router_unittest.cc |
| diff --git a/chrome/browser/ui/search/search_ipc_router_unittest.cc b/chrome/browser/ui/search/search_ipc_router_unittest.cc |
| index ca11a804cdb98ca0d4ae6621be6d72c3169584f6..a333ed6bee2a58ef60ab2fb7a60d39ddbf7f59b8 100644 |
| --- a/chrome/browser/ui/search/search_ipc_router_unittest.cc |
| +++ b/chrome/browser/ui/search/search_ipc_router_unittest.cc |
| @@ -138,8 +138,8 @@ class SearchIPCRouterTest : public BrowserWithTestWindowTest { |
| ASSERT_NE(static_cast<content::WebContents*>(NULL), contents); |
| SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); |
| ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| - search_tab_helper->ipc_router().set_delegate(mock_delegate()); |
| - search_tab_helper->ipc_router().set_policy( |
| + search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate()); |
| + search_tab_helper->ipc_router().set_policy_for_testing( |
| make_scoped_ptr(new MockSearchIPCRouterPolicy) |
| .PassAs<SearchIPCRouter::Policy>()); |
| } |
| @@ -172,13 +172,17 @@ class SearchIPCRouterTest : public BrowserWithTestWindowTest { |
| SearchTabHelper* search_tab_helper = GetSearchTabHelper(contents); |
| EXPECT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
| return static_cast<MockSearchIPCRouterPolicy*>( |
| - search_tab_helper->ipc_router().policy()); |
| + search_tab_helper->ipc_router().policy_for_testing()); |
| } |
| SearchIPCRouter& GetSearchIPCRouter() { |
| return GetSearchTabHelper(web_contents())->ipc_router(); |
| } |
| + int GetSearchIPCRouterSeqNo() { |
| + return GetSearchIPCRouter().page_seq_no_for_testing(); |
| + } |
| + |
| void OnMessageReceived(const IPC::Message& message) { |
| GetSearchIPCRouter().OnMessageReceived(message); |
| } |
| @@ -204,7 +208,7 @@ TEST_F(SearchIPCRouterTest, ProcessVoiceSearchSupportMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SetVoiceSearchSupported( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
|
kmadhusu
2014/05/30 18:05:39
style nit: Please move this argument to the previo
Avi (use Gerrit)
2014/05/30 18:10:23
Done.
|
| true)); |
| OnMessageReceived(*message); |
| } |
| @@ -221,7 +225,7 @@ TEST_F(SearchIPCRouterTest, IgnoreVoiceSearchSupportMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SetVoiceSearchSupported( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| true)); |
| OnMessageReceived(*message); |
| } |
| @@ -240,7 +244,7 @@ TEST_F(SearchIPCRouterTest, ProcessFocusOmniboxMsg) { |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| OMNIBOX_FOCUS_VISIBLE)); |
| OnMessageReceived(*message); |
| } |
| @@ -259,7 +263,7 @@ TEST_F(SearchIPCRouterTest, IgnoreFocusOmniboxMsg) { |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_FocusOmnibox( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| OMNIBOX_FOCUS_VISIBLE)); |
| OnMessageReceived(*message); |
| } |
| @@ -300,7 +304,7 @@ TEST_F(SearchIPCRouterTest, ProcessNavigateToURLMsg) { |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| destination_url, CURRENT_TAB, true)); |
| OnMessageReceived(*message); |
| } |
| @@ -321,7 +325,7 @@ TEST_F(SearchIPCRouterTest, IgnoreNavigateToURLMsg) { |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| destination_url, CURRENT_TAB, true)); |
| OnMessageReceived(*message); |
| } |
| @@ -336,8 +340,7 @@ TEST_F(SearchIPCRouterTest, ProcessLogEventMsg) { |
| content::WebContents* contents = web_contents(); |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), |
| NTP_MOUSEOVER)); |
| OnMessageReceived(*message); |
| } |
| @@ -352,8 +355,7 @@ TEST_F(SearchIPCRouterTest, IgnoreLogEventMsg) { |
| content::WebContents* contents = web_contents(); |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_LogEvent( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), |
| NTP_MOUSEOVER)); |
| OnMessageReceived(*message); |
| } |
| @@ -371,7 +373,7 @@ TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedImpressionMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_LogMostVisitedImpression( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| 3, |
| base::ASCIIToUTF16("Server"))); |
| OnMessageReceived(*message); |
| @@ -390,7 +392,7 @@ TEST_F(SearchIPCRouterTest, ProcessLogMostVisitedNavigationMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_LogMostVisitedNavigation( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| 3, |
| base::ASCIIToUTF16("Server"))); |
| OnMessageReceived(*message); |
| @@ -407,9 +409,7 @@ TEST_F(SearchIPCRouterTest, ProcessChromeIdentityCheckMsg) { |
| content::WebContents* contents = web_contents(); |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| - test_identity)); |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); |
| OnMessageReceived(*message); |
| } |
| @@ -425,9 +425,7 @@ TEST_F(SearchIPCRouterTest, IgnoreChromeIdentityCheckMsg) { |
| content::WebContents* contents = web_contents(); |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_ChromeIdentityCheck( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| - test_identity)); |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), test_identity)); |
| OnMessageReceived(*message); |
| } |
| @@ -444,7 +442,7 @@ TEST_F(SearchIPCRouterTest, ProcessDeleteMostVisitedItemMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| item_url)); |
| OnMessageReceived(*message); |
| } |
| @@ -462,7 +460,7 @@ TEST_F(SearchIPCRouterTest, IgnoreDeleteMostVisitedItemMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| item_url)); |
| OnMessageReceived(*message); |
| } |
| @@ -480,7 +478,7 @@ TEST_F(SearchIPCRouterTest, ProcessUndoMostVisitedDeletionMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| item_url)); |
| OnMessageReceived(*message); |
| } |
| @@ -498,7 +496,7 @@ TEST_F(SearchIPCRouterTest, IgnoreUndoMostVisitedDeletionMsg) { |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( |
| contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), |
| + GetSearchIPCRouterSeqNo(), |
| item_url)); |
| OnMessageReceived(*message); |
| } |
| @@ -514,8 +512,7 @@ TEST_F(SearchIPCRouterTest, ProcessUndoAllMostVisitedDeletionsMsg) { |
| content::WebContents* contents = web_contents(); |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID())); |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); |
| OnMessageReceived(*message); |
| } |
| @@ -530,8 +527,7 @@ TEST_F(SearchIPCRouterTest, IgnoreUndoAllMostVisitedDeletionsMsg) { |
| content::WebContents* contents = web_contents(); |
| scoped_ptr<IPC::Message> message( |
| new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID())); |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo())); |
| OnMessageReceived(*message); |
| } |
| @@ -539,55 +535,61 @@ TEST_F(SearchIPCRouterTest, IgnoreMessageIfThePageIsNotActive) { |
| NavigateAndCommitActiveTab(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| SetupMockDelegateAndPolicy(); |
| MockSearchIPCRouterPolicy* policy = GetSearchIPCRouterPolicy(); |
| + int page_seq_no = GetSearchIPCRouterSeqNo(); |
| content::WebContents* contents = web_contents(); |
| bool is_active_tab = IsActiveTab(contents); |
| - int invalid_page_id = 1000; |
| GURL item_url("www.foo.com"); |
| EXPECT_CALL(*mock_delegate(), NavigateToURL(item_url, CURRENT_TAB, |
| true)).Times(0); |
| + // At this point, in a real test, the navigation would cause the |
| + // SearchIPCRouter's page sequence to advance. In this test it doesn't, so |
| + // we'll decrement the sequence number on this side to simulate it. |
| + --page_seq_no; |
| EXPECT_CALL(*policy, ShouldProcessNavigateToURL(is_active_tab)).Times(0); |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_SearchBoxNavigate( |
| - contents->GetRoutingID(), invalid_page_id, item_url, CURRENT_TAB, |
| - true)); |
| + contents->GetRoutingID(), page_seq_no, item_url, |
| + CURRENT_TAB, true)); |
| OnMessageReceived(*message); |
| EXPECT_CALL(*mock_delegate(), OnDeleteMostVisitedItem(item_url)).Times(0); |
| EXPECT_CALL(*policy, ShouldProcessDeleteMostVisitedItem()).Times(0); |
| message.reset(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( |
| - contents->GetRoutingID(), invalid_page_id, item_url)); |
| + contents->GetRoutingID(), page_seq_no, item_url)); |
| OnMessageReceived(*message); |
| EXPECT_CALL(*mock_delegate(), OnUndoMostVisitedDeletion(item_url)).Times(0); |
| EXPECT_CALL(*policy, ShouldProcessUndoMostVisitedDeletion()).Times(0); |
| message.reset(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion( |
| - contents->GetRoutingID(), invalid_page_id, item_url)); |
| + contents->GetRoutingID(), page_seq_no, item_url)); |
| OnMessageReceived(*message); |
| EXPECT_CALL(*mock_delegate(), OnUndoAllMostVisitedDeletions()).Times(0); |
| EXPECT_CALL(*policy, ShouldProcessUndoAllMostVisitedDeletions()).Times(0); |
| message.reset(new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions( |
| - contents->GetRoutingID(), invalid_page_id)); |
| + contents->GetRoutingID(), page_seq_no)); |
| OnMessageReceived(*message); |
| EXPECT_CALL(*mock_delegate(), FocusOmnibox(OMNIBOX_FOCUS_VISIBLE)).Times(0); |
| EXPECT_CALL(*policy, ShouldProcessFocusOmnibox(is_active_tab)).Times(0); |
| message.reset(new ChromeViewHostMsg_FocusOmnibox( |
| - contents->GetRoutingID(), invalid_page_id, OMNIBOX_FOCUS_VISIBLE)); |
| + contents->GetRoutingID(), page_seq_no, |
| + OMNIBOX_FOCUS_VISIBLE)); |
| OnMessageReceived(*message); |
| EXPECT_CALL(*mock_delegate(), OnLogEvent(NTP_MOUSEOVER)).Times(0); |
| EXPECT_CALL(*policy, ShouldProcessLogEvent()).Times(0); |
| message.reset(new ChromeViewHostMsg_LogEvent(contents->GetRoutingID(), |
| - invalid_page_id, NTP_MOUSEOVER)); |
| + page_seq_no, |
| + NTP_MOUSEOVER)); |
| OnMessageReceived(*message); |
| base::string16 text; |
| EXPECT_CALL(*mock_delegate(), PasteIntoOmnibox(text)).Times(0); |
| EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(0); |
| message.reset(new ChromeViewHostMsg_PasteAndOpenDropdown( |
| - contents->GetRoutingID(), invalid_page_id, text)); |
| + contents->GetRoutingID(), page_seq_no, text)); |
| OnMessageReceived(*message); |
| } |
| @@ -605,8 +607,7 @@ TEST_F(SearchIPCRouterTest, ProcessPasteAndOpenDropdownMsg) { |
| EXPECT_CALL(*policy, ShouldProcessPasteIntoOmnibox(is_active_tab)).Times(1) |
| .WillOnce(testing::Return(true)); |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), text)); |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text)); |
| OnMessageReceived(*message); |
| } |
| @@ -625,8 +626,7 @@ TEST_F(SearchIPCRouterTest, IgnorePasteAndOpenDropdownMsg) { |
| .WillOnce(testing::Return(false)); |
| scoped_ptr<IPC::Message> message(new ChromeViewHostMsg_PasteAndOpenDropdown( |
| - contents->GetRoutingID(), |
| - contents->GetController().GetVisibleEntry()->GetPageID(), text)); |
| + contents->GetRoutingID(), GetSearchIPCRouterSeqNo(), text)); |
| OnMessageReceived(*message); |
| } |