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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
| 10 #include <tuple> |
10 | 11 |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "chrome/browser/prerender/prerender_manager.h" | 17 #include "chrome/browser/prerender/prerender_manager.h" |
17 #include "chrome/browser/prerender/prerender_manager_factory.h" | 18 #include "chrome/browser/prerender/prerender_manager_factory.h" |
18 #include "chrome/browser/search/instant_unittest_base.h" | 19 #include "chrome/browser/search/instant_unittest_base.h" |
19 #include "chrome/browser/search/search.h" | 20 #include "chrome/browser/search/search.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 187 |
187 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); | 188 const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); |
188 search_tab_helper->OnChromeIdentityCheck(test_identity); | 189 search_tab_helper->OnChromeIdentityCheck(test_identity); |
189 | 190 |
190 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 191 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
191 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 192 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
192 ASSERT_TRUE(message != NULL); | 193 ASSERT_TRUE(message != NULL); |
193 | 194 |
194 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 195 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
195 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 196 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
196 EXPECT_EQ(test_identity, base::get<0>(params)); | 197 EXPECT_EQ(test_identity, std::get<0>(params)); |
197 ASSERT_TRUE(base::get<1>(params)); | 198 ASSERT_TRUE(std::get<1>(params)); |
198 } | 199 } |
199 | 200 |
200 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchSlightlyDifferentGmail) { | 201 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchSlightlyDifferentGmail) { |
201 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 202 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
202 CreateSigninManager(std::string("foobar123@gmail.com")); | 203 CreateSigninManager(std::string("foobar123@gmail.com")); |
203 SearchTabHelper* search_tab_helper = | 204 SearchTabHelper* search_tab_helper = |
204 SearchTabHelper::FromWebContents(web_contents()); | 205 SearchTabHelper::FromWebContents(web_contents()); |
205 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 206 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
206 | 207 |
207 // For gmail, canonicalization is done so that email addresses have a | 208 // For gmail, canonicalization is done so that email addresses have a |
208 // standard form. | 209 // standard form. |
209 const base::string16 test_identity = | 210 const base::string16 test_identity = |
210 base::ASCIIToUTF16("Foo.Bar.123@gmail.com"); | 211 base::ASCIIToUTF16("Foo.Bar.123@gmail.com"); |
211 search_tab_helper->OnChromeIdentityCheck(test_identity); | 212 search_tab_helper->OnChromeIdentityCheck(test_identity); |
212 | 213 |
213 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 214 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
214 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 215 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
215 ASSERT_TRUE(message != NULL); | 216 ASSERT_TRUE(message != NULL); |
216 | 217 |
217 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 218 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
218 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 219 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
219 EXPECT_EQ(test_identity, base::get<0>(params)); | 220 EXPECT_EQ(test_identity, std::get<0>(params)); |
220 ASSERT_TRUE(base::get<1>(params)); | 221 ASSERT_TRUE(std::get<1>(params)); |
221 } | 222 } |
222 | 223 |
223 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchSlightlyDifferentGmail2) { | 224 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchSlightlyDifferentGmail2) { |
224 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 225 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
225 // | 226 // |
226 CreateSigninManager(std::string("chrome.guy.7FOREVER")); | 227 CreateSigninManager(std::string("chrome.guy.7FOREVER")); |
227 SearchTabHelper* search_tab_helper = | 228 SearchTabHelper* search_tab_helper = |
228 SearchTabHelper::FromWebContents(web_contents()); | 229 SearchTabHelper::FromWebContents(web_contents()); |
229 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 230 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
230 | 231 |
231 // For gmail/googlemail, canonicalization is done so that email addresses have | 232 // For gmail/googlemail, canonicalization is done so that email addresses have |
232 // a standard form. | 233 // a standard form. |
233 const base::string16 test_identity = | 234 const base::string16 test_identity = |
234 base::ASCIIToUTF16("chromeguy7forever@googlemail.com"); | 235 base::ASCIIToUTF16("chromeguy7forever@googlemail.com"); |
235 search_tab_helper->OnChromeIdentityCheck(test_identity); | 236 search_tab_helper->OnChromeIdentityCheck(test_identity); |
236 | 237 |
237 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 238 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
238 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 239 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
239 ASSERT_TRUE(message != NULL); | 240 ASSERT_TRUE(message != NULL); |
240 | 241 |
241 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 242 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
242 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 243 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
243 EXPECT_EQ(test_identity, base::get<0>(params)); | 244 EXPECT_EQ(test_identity, std::get<0>(params)); |
244 ASSERT_TRUE(base::get<1>(params)); | 245 ASSERT_TRUE(std::get<1>(params)); |
245 } | 246 } |
246 | 247 |
247 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMismatch) { | 248 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMismatch) { |
248 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 249 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
249 CreateSigninManager(std::string("foo@bar.com")); | 250 CreateSigninManager(std::string("foo@bar.com")); |
250 SearchTabHelper* search_tab_helper = | 251 SearchTabHelper* search_tab_helper = |
251 SearchTabHelper::FromWebContents(web_contents()); | 252 SearchTabHelper::FromWebContents(web_contents()); |
252 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 253 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
253 | 254 |
254 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); | 255 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); |
255 search_tab_helper->OnChromeIdentityCheck(test_identity); | 256 search_tab_helper->OnChromeIdentityCheck(test_identity); |
256 | 257 |
257 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 258 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
258 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 259 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
259 ASSERT_TRUE(message != NULL); | 260 ASSERT_TRUE(message != NULL); |
260 | 261 |
261 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 262 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
262 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 263 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
263 EXPECT_EQ(test_identity, base::get<0>(params)); | 264 EXPECT_EQ(test_identity, std::get<0>(params)); |
264 ASSERT_FALSE(base::get<1>(params)); | 265 ASSERT_FALSE(std::get<1>(params)); |
265 } | 266 } |
266 | 267 |
267 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMismatch) { | 268 TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMismatch) { |
268 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 269 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
269 // This test does not sign in. | 270 // This test does not sign in. |
270 SearchTabHelper* search_tab_helper = | 271 SearchTabHelper* search_tab_helper = |
271 SearchTabHelper::FromWebContents(web_contents()); | 272 SearchTabHelper::FromWebContents(web_contents()); |
272 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 273 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
273 | 274 |
274 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); | 275 const base::string16 test_identity = base::ASCIIToUTF16("bar@foo.com"); |
275 search_tab_helper->OnChromeIdentityCheck(test_identity); | 276 search_tab_helper->OnChromeIdentityCheck(test_identity); |
276 | 277 |
277 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 278 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
278 ChromeViewMsg_ChromeIdentityCheckResult::ID); | 279 ChromeViewMsg_ChromeIdentityCheckResult::ID); |
279 ASSERT_TRUE(message != NULL); | 280 ASSERT_TRUE(message != NULL); |
280 | 281 |
281 ChromeViewMsg_ChromeIdentityCheckResult::Param params; | 282 ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
282 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); | 283 ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
283 EXPECT_EQ(test_identity, base::get<0>(params)); | 284 EXPECT_EQ(test_identity, std::get<0>(params)); |
284 ASSERT_FALSE(base::get<1>(params)); | 285 ASSERT_FALSE(std::get<1>(params)); |
285 } | 286 } |
286 | 287 |
287 TEST_F(SearchTabHelperTest, OnHistorySyncCheckSyncing) { | 288 TEST_F(SearchTabHelperTest, OnHistorySyncCheckSyncing) { |
288 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 289 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
289 SetHistorySync(true); | 290 SetHistorySync(true); |
290 SearchTabHelper* search_tab_helper = | 291 SearchTabHelper* search_tab_helper = |
291 SearchTabHelper::FromWebContents(web_contents()); | 292 SearchTabHelper::FromWebContents(web_contents()); |
292 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 293 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
293 | 294 |
294 search_tab_helper->OnHistorySyncCheck(); | 295 search_tab_helper->OnHistorySyncCheck(); |
295 | 296 |
296 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 297 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
297 ChromeViewMsg_HistorySyncCheckResult::ID); | 298 ChromeViewMsg_HistorySyncCheckResult::ID); |
298 ASSERT_TRUE(message != NULL); | 299 ASSERT_TRUE(message != NULL); |
299 | 300 |
300 ChromeViewMsg_HistorySyncCheckResult::Param params; | 301 ChromeViewMsg_HistorySyncCheckResult::Param params; |
301 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); | 302 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); |
302 ASSERT_TRUE(base::get<0>(params)); | 303 ASSERT_TRUE(std::get<0>(params)); |
303 } | 304 } |
304 | 305 |
305 TEST_F(SearchTabHelperTest, OnHistorySyncCheckNotSyncing) { | 306 TEST_F(SearchTabHelperTest, OnHistorySyncCheckNotSyncing) { |
306 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 307 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
307 SetHistorySync(false); | 308 SetHistorySync(false); |
308 SearchTabHelper* search_tab_helper = | 309 SearchTabHelper* search_tab_helper = |
309 SearchTabHelper::FromWebContents(web_contents()); | 310 SearchTabHelper::FromWebContents(web_contents()); |
310 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); | 311 ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
311 | 312 |
312 search_tab_helper->OnHistorySyncCheck(); | 313 search_tab_helper->OnHistorySyncCheck(); |
313 | 314 |
314 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( | 315 const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
315 ChromeViewMsg_HistorySyncCheckResult::ID); | 316 ChromeViewMsg_HistorySyncCheckResult::ID); |
316 ASSERT_TRUE(message != NULL); | 317 ASSERT_TRUE(message != NULL); |
317 | 318 |
318 ChromeViewMsg_HistorySyncCheckResult::Param params; | 319 ChromeViewMsg_HistorySyncCheckResult::Param params; |
319 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); | 320 ChromeViewMsg_HistorySyncCheckResult::Read(message, ¶ms); |
320 ASSERT_FALSE(base::get<0>(params)); | 321 ASSERT_FALSE(std::get<0>(params)); |
321 } | 322 } |
322 | 323 |
323 TEST_F(SearchTabHelperTest, OnMostVisitedItemsChangedFromServer) { | 324 TEST_F(SearchTabHelperTest, OnMostVisitedItemsChangedFromServer) { |
324 InstantMostVisitedItem item; | 325 InstantMostVisitedItem item; |
325 item.is_server_side_suggestion = true; | 326 item.is_server_side_suggestion = true; |
326 std::vector<InstantMostVisitedItem> items; | 327 std::vector<InstantMostVisitedItem> items; |
327 items.push_back(item); | 328 items.push_back(item); |
328 | 329 |
329 SearchTabHelper* search_tab_helper = | 330 SearchTabHelper* search_tab_helper = |
330 SearchTabHelper::FromWebContents(web_contents()); | 331 SearchTabHelper::FromWebContents(web_contents()); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 454 } |
454 | 455 |
455 TEST_F(SearchTabHelperPrerenderTest, | 456 TEST_F(SearchTabHelperPrerenderTest, |
456 OnTabActivatedNoPrerenderIfOmniboxBlurred) { | 457 OnTabActivatedNoPrerenderIfOmniboxBlurred) { |
457 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false; | 458 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false; |
458 SearchTabHelper* search_tab_helper = | 459 SearchTabHelper* search_tab_helper = |
459 SearchTabHelper::FromWebContents(web_contents()); | 460 SearchTabHelper::FromWebContents(web_contents()); |
460 search_tab_helper->OnTabActivated(); | 461 search_tab_helper->OnTabActivated(); |
461 ASSERT_FALSE(IsInstantURLMarkedForPrerendering()); | 462 ASSERT_FALSE(IsInstantURLMarkedForPrerendering()); |
462 } | 463 } |
OLD | NEW |