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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); | 183 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); |
184 search_tab_helper->OnChromeIdentityCheck(test_identity); | 184 search_tab_helper->OnChromeIdentityCheck(test_identity); |
185 | 185 |
186 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 186 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
187 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 187 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
188 ASSERT_TRUE(message != NULL); | 188 ASSERT_TRUE(message != NULL); |
189 | 189 |
190 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 190 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
191 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 191 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
192 EXPECT_EQ(test_identity, params.a); | 192 EXPECT_EQ(test_identity, get<0>(params)); |
193 ASSERT_TRUE(params.b); | 193 ASSERT_TRUE(get<1>(params)); |
194 } | 194 } |
195 | 195 |
196 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMismatch) { | 196 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMismatch) { |
197 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 197 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
198 CreateSigninManager(std::string("foo@bar.com")); | 198 CreateSigninManager(std::string("foo@bar.com")); |
199 SearchTabHelper* search_tab_helper = | 199 SearchTabHelper* search_tab_helper = |
200 SearchTabHelper::FromWebContents(web_contents()); | 200 SearchTabHelper::FromWebContents(web_contents()); |
201 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 201 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
202 | 202 |
203 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); | 203 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); |
204 search_tab_helper->OnChromeIdentityCheck(test_identity); | 204 search_tab_helper->OnChromeIdentityCheck(test_identity); |
205 | 205 |
206 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 206 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
207 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 207 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
208 ASSERT_TRUE(message != NULL); | 208 ASSERT_TRUE(message != NULL); |
209 | 209 |
210 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 210 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
211 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 211 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
212 EXPECT_EQ(test_identity, params.a); | 212 EXPECT_EQ(test_identity, get<0>(params)); |
213 ASSERT_FALSE(params.b); | 213 ASSERT_FALSE(get<1>(params)); |
214 } | 214 } |
215 | 215 |
216 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMismatch) { | 216 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMismatch) { |
217 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 217 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
218 // This test does not sign in. | 218 // This test does not sign in. |
219 SearchTabHelper* search_tab_helper = | 219 SearchTabHelper* search_tab_helper = |
220 SearchTabHelper::FromWebContents(web_contents()); | 220 SearchTabHelper::FromWebContents(web_contents()); |
221 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 221 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
222 | 222 |
223 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); | 223 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); |
224 search_tab_helper->OnChromeIdentityCheck(test_identity); | 224 search_tab_helper->OnChromeIdentityCheck(test_identity); |
225 | 225 |
226 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 226 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
227 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 227 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
228 ASSERT_TRUE(message != NULL); | 228 ASSERT_TRUE(message != NULL); |
229 | 229 |
230 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 230 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
231 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 231 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
232 EXPECT_EQ(test_identity, params.a); | 232 EXPECT_EQ(test_identity, get<0>(params)); |
233 ASSERT_FALSE(params.b); | 233 ASSERT_FALSE(get<1>(params)); |
234 } | 234 } |
235 | 235 |
236 TEST_F(SearchTabHelperTest, OnHistorySyncCheckSyncInactive) { | 236 TEST_F(SearchTabHelperTest, OnHistorySyncCheckSyncInactive) { |
237 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 237 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
238 ProfileSyncServiceMock* sync_service = static_cast<ProfileSyncServiceMock*>( | 238 ProfileSyncServiceMock* sync_service = static_cast<ProfileSyncServiceMock*>( |
239 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile())); | 239 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile())); |
240 EXPECT_CALL(*sync_service, SyncActive()).WillRepeatedly(Return(false)); | 240 EXPECT_CALL(*sync_service, SyncActive()).WillRepeatedly(Return(false)); |
241 SearchTabHelper* search_tab_helper = | 241 SearchTabHelper* search_tab_helper = |
242 SearchTabHelper::FromWebContents(web_contents()); | 242 SearchTabHelper::FromWebContents(web_contents()); |
243 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 243 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
244 | 244 |
245 search_tab_helper->OnHistorySyncCheck(); | 245 search_tab_helper->OnHistorySyncCheck(); |
246 | 246 |
247 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 247 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
248 ChromeViewMsg_HistorySyncCheckResult::ID); | 248 ChromeViewMsg_HistorySyncCheckResult::ID); |
249 ASSERT_TRUE(message != NULL); | 249 ASSERT_TRUE(message != NULL); |
250 | 250 |
251 ChromeViewMsg_HistorySyncCheckResult::Param params; | 251 ChromeViewMsg_HistorySyncCheckResult::Param params; |
252 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); | 252 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); |
253 ASSERT_FALSE(params.a); | 253 ASSERT_FALSE(get<0>(params)); |
254 } | 254 } |
255 | 255 |
256 TEST_F(SearchTabHelperTest, OnHistorySyncCheckSyncing) { | 256 TEST_F(SearchTabHelperTest, OnHistorySyncCheckSyncing) { |
257 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 257 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
258 SetHistorySync(true); | 258 SetHistorySync(true); |
259 SearchTabHelper* search_tab_helper = | 259 SearchTabHelper* search_tab_helper = |
260 SearchTabHelper::FromWebContents(web_contents()); | 260 SearchTabHelper::FromWebContents(web_contents()); |
261 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 261 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
262 | 262 |
263 search_tab_helper->OnHistorySyncCheck(); | 263 search_tab_helper->OnHistorySyncCheck(); |
264 | 264 |
265 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 265 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
266 ChromeViewMsg_HistorySyncCheckResult::ID); | 266 ChromeViewMsg_HistorySyncCheckResult::ID); |
267 ASSERT_TRUE(message != NULL); | 267 ASSERT_TRUE(message != NULL); |
268 | 268 |
269 ChromeViewMsg_HistorySyncCheckResult::Param params; | 269 ChromeViewMsg_HistorySyncCheckResult::Param params; |
270 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); | 270 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); |
271 ASSERT_TRUE(params.a); | 271 ASSERT_TRUE(get<0>(params)); |
272 } | 272 } |
273 | 273 |
274 TEST_F(SearchTabHelperTest, OnHistorySyncCheckNotSyncing) { | 274 TEST_F(SearchTabHelperTest, OnHistorySyncCheckNotSyncing) { |
275 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 275 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
276 SetHistorySync(false); | 276 SetHistorySync(false); |
277 SearchTabHelper* search_tab_helper = | 277 SearchTabHelper* search_tab_helper = |
278 SearchTabHelper::FromWebContents(web_contents()); | 278 SearchTabHelper::FromWebContents(web_contents()); |
279 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 279 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
280 | 280 |
281 search_tab_helper->OnHistorySyncCheck(); | 281 search_tab_helper->OnHistorySyncCheck(); |
282 | 282 |
283 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 283 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
284 ChromeViewMsg_HistorySyncCheckResult::ID); | 284 ChromeViewMsg_HistorySyncCheckResult::ID); |
285 ASSERT_TRUE(message != NULL); | 285 ASSERT_TRUE(message != NULL); |
286 | 286 |
287 ChromeViewMsg_HistorySyncCheckResult::Param params; | 287 ChromeViewMsg_HistorySyncCheckResult::Param params; |
288 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); | 288 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); |
289 ASSERT_FALSE(params.a); | 289 ASSERT_FALSE(get<0>(params)); |
290 } | 290 } |
291 | 291 |
292 class TabTitleObserver : public content::WebContentsObserver { | 292 class TabTitleObserver : public content::WebContentsObserver { |
293 public: | 293 public: |
294 explicit TabTitleObserver(content::WebContents* contents) | 294 explicit TabTitleObserver(content::WebContents* contents) |
295 : WebContentsObserver(contents) {} | 295 : WebContentsObserver(contents) {} |
296 | 296 |
297 base::string16 title_on_start() { return title_on_start_; } | 297 base::string16 title_on_start() { return title_on_start_; } |
298 base::string16 title_on_commit() { return title_on_commit_; } | 298 base::string16 title_on_commit() { return title_on_commit_; } |
299 | 299 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 471 } |
472 | 472 |
473 TEST_F(SearchTabHelperPrerenderTest, | 473 TEST_F(SearchTabHelperPrerenderTest, |
474 OnTabActivatedNoPrerenderIfOmniboxBlurred) { | 474 OnTabActivatedNoPrerenderIfOmniboxBlurred) { |
475 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false; | 475 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false; |
476 SearchTabHelper* search_tab_helper = | 476 SearchTabHelper* search_tab_helper = |
477 SearchTabHelper::FromWebContents(web_contents()); | 477 SearchTabHelper::FromWebContents(web_contents()); |
478 search_tab_helper->OnTabActivated(); | 478 search_tab_helper->OnTabActivated(); |
479 ASSERT_FALSE(IsInstantURLMarkedForPrerendering()); | 479 ASSERT_FALSE(IsInstantURLMarkedForPrerendering()); |
480 } | 480 } |
OLD | NEW |