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_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 MockSearchIPCRouterDelegate delegate_; | 96 MockSearchIPCRouterDelegate delegate_; |
97 }; | 97 }; |
98 | 98 |
99 TEST_F(SearchTabHelperTest, DetermineIfPageSupportsInstant_Local) { | 99 TEST_F(SearchTabHelperTest, DetermineIfPageSupportsInstant_Local) { |
100 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 100 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
101 EXPECT_CALL(*mock_delegate(), OnInstantSupportDetermined(true)).Times(0); | 101 EXPECT_CALL(*mock_delegate(), OnInstantSupportDetermined(true)).Times(0); |
102 | 102 |
103 SearchTabHelper* search_tab_helper = | 103 SearchTabHelper* search_tab_helper = |
104 SearchTabHelper::FromWebContents(web_contents()); | 104 SearchTabHelper::FromWebContents(web_contents()); |
105 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 105 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
106 search_tab_helper->ipc_router().set_delegate(mock_delegate()); | 106 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate()); |
107 search_tab_helper->DetermineIfPageSupportsInstant(); | 107 search_tab_helper->DetermineIfPageSupportsInstant(); |
108 } | 108 } |
109 | 109 |
110 TEST_F(SearchTabHelperTest, DetermineIfPageSupportsInstant_NonLocal) { | 110 TEST_F(SearchTabHelperTest, DetermineIfPageSupportsInstant_NonLocal) { |
111 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 111 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
112 process()->sink().ClearMessages(); | 112 process()->sink().ClearMessages(); |
113 EXPECT_CALL(*mock_delegate(), OnInstantSupportDetermined(true)).Times(1); | 113 EXPECT_CALL(*mock_delegate(), OnInstantSupportDetermined(true)).Times(1); |
114 | 114 |
115 SearchTabHelper* search_tab_helper = | 115 SearchTabHelper* search_tab_helper = |
116 SearchTabHelper::FromWebContents(web_contents()); | 116 SearchTabHelper::FromWebContents(web_contents()); |
117 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 117 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
118 search_tab_helper->ipc_router().set_delegate(mock_delegate()); | 118 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate()); |
119 search_tab_helper->DetermineIfPageSupportsInstant(); | 119 search_tab_helper->DetermineIfPageSupportsInstant(); |
120 ASSERT_TRUE(MessageWasSent(ChromeViewMsg_DetermineIfPageSupportsInstant::ID)); | 120 ASSERT_TRUE(MessageWasSent(ChromeViewMsg_DetermineIfPageSupportsInstant::ID)); |
121 | 121 |
122 scoped_ptr<IPC::Message> response( | 122 scoped_ptr<IPC::Message> response( |
123 new ChromeViewHostMsg_InstantSupportDetermined( | 123 new ChromeViewHostMsg_InstantSupportDetermined( |
124 web_contents()->GetRoutingID(), | 124 web_contents()->GetRoutingID(), |
125 web_contents()->GetController().GetVisibleEntry()->GetPageID(), | 125 search_tab_helper->ipc_router().page_seq_no_for_testing(), |
126 true)); | 126 true)); |
127 search_tab_helper->ipc_router().OnMessageReceived(*response); | 127 search_tab_helper->ipc_router().OnMessageReceived(*response); |
128 } | 128 } |
129 | 129 |
130 TEST_F(SearchTabHelperTest, PageURLDoesntBelongToInstantRenderer) { | 130 TEST_F(SearchTabHelperTest, PageURLDoesntBelongToInstantRenderer) { |
131 // Navigate to a page URL that doesn't belong to Instant renderer. | 131 // Navigate to a page URL that doesn't belong to Instant renderer. |
132 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return | 132 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return |
133 // immediately without dispatching any message to the renderer. | 133 // immediately without dispatching any message to the renderer. |
134 NavigateAndCommit(GURL("http://www.example.com")); | 134 NavigateAndCommit(GURL("http://www.example.com")); |
135 process()->sink().ClearMessages(); | 135 process()->sink().ClearMessages(); |
136 EXPECT_CALL(*mock_delegate(), OnInstantSupportDetermined(false)).Times(0); | 136 EXPECT_CALL(*mock_delegate(), OnInstantSupportDetermined(false)).Times(0); |
137 | 137 |
138 SearchTabHelper* search_tab_helper = | 138 SearchTabHelper* search_tab_helper = |
139 SearchTabHelper::FromWebContents(web_contents()); | 139 SearchTabHelper::FromWebContents(web_contents()); |
140 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 140 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
141 search_tab_helper->ipc_router().set_delegate(mock_delegate()); | 141 search_tab_helper->ipc_router().set_delegate_for_testing(mock_delegate()); |
142 search_tab_helper->DetermineIfPageSupportsInstant(); | 142 search_tab_helper->DetermineIfPageSupportsInstant(); |
143 ASSERT_FALSE(MessageWasSent( | 143 ASSERT_FALSE(MessageWasSent( |
144 ChromeViewMsg_DetermineIfPageSupportsInstant::ID)); | 144 ChromeViewMsg_DetermineIfPageSupportsInstant::ID)); |
145 } | 145 } |
146 | 146 |
147 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatch) { | 147 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatch) { |
148 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 148 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
149 CreateSigninManager(std::string("foo@bar.com")); | 149 CreateSigninManager(std::string("foo@bar.com")); |
150 SearchTabHelper* search_tab_helper = | 150 SearchTabHelper* search_tab_helper = |
151 SearchTabHelper::FromWebContents(web_contents()); | 151 SearchTabHelper::FromWebContents(web_contents()); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 SearchTabHelper::FromWebContents(contents); | 338 SearchTabHelper::FromWebContents(contents); |
339 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 339 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
340 | 340 |
341 // Any other web page shouldn't be redirected when provisional load fails. | 341 // Any other web page shouldn't be redirected when provisional load fails. |
342 search_tab_helper->DidFailProvisionalLoad(1, base::string16(), true, | 342 search_tab_helper->DidFailProvisionalLoad(1, base::string16(), true, |
343 GURL("http://www.example.com"), 1, base::string16(), NULL); | 343 GURL("http://www.example.com"), 1, base::string16(), NULL); |
344 CommitPendingLoad(controller); | 344 CommitPendingLoad(controller); |
345 EXPECT_NE(GURL(chrome::kChromeSearchLocalNtpUrl), | 345 EXPECT_NE(GURL(chrome::kChromeSearchLocalNtpUrl), |
346 controller->GetLastCommittedEntry()->GetURL()); | 346 controller->GetLastCommittedEntry()->GetURL()); |
347 } | 347 } |
OLD | NEW |