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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram_base.h" | 8 #include "base/metrics/histogram_base.h" |
9 #include "base/metrics/histogram_samples.h" | 9 #include "base/metrics/histogram_samples.h" |
10 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "chrome/browser/search/search.h" | 39 #include "chrome/browser/search/search.h" |
40 #include "chrome/browser/search_engines/template_url_service.h" | 40 #include "chrome/browser/search_engines/template_url_service.h" |
41 #include "chrome/browser/search_engines/template_url_service_factory.h" | 41 #include "chrome/browser/search_engines/template_url_service_factory.h" |
42 #include "chrome/browser/task_manager/task_manager.h" | 42 #include "chrome/browser/task_manager/task_manager.h" |
43 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 43 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
44 #include "chrome/browser/themes/theme_service.h" | 44 #include "chrome/browser/themes/theme_service.h" |
45 #include "chrome/browser/themes/theme_service_factory.h" | 45 #include "chrome/browser/themes/theme_service_factory.h" |
46 #include "chrome/browser/ui/browser_list.h" | 46 #include "chrome/browser/ui/browser_list.h" |
47 #include "chrome/browser/ui/browser_tabstrip.h" | 47 #include "chrome/browser/ui/browser_tabstrip.h" |
48 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 48 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
49 #include "chrome/browser/ui/search/instant_ntp.h" | |
50 #include "chrome/browser/ui/search/instant_ntp_prerenderer.h" | |
51 #include "chrome/browser/ui/search/instant_tab.h" | 49 #include "chrome/browser/ui/search/instant_tab.h" |
52 #include "chrome/browser/ui/search/instant_test_utils.h" | 50 #include "chrome/browser/ui/search/instant_test_utils.h" |
53 #include "chrome/browser/ui/search/search_tab_helper.h" | 51 #include "chrome/browser/ui/search/search_tab_helper.h" |
54 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 52 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
55 #include "chrome/browser/ui/webui/theme_source.h" | 53 #include "chrome/browser/ui/webui/theme_source.h" |
56 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
57 #include "chrome/common/instant_types.h" | 55 #include "chrome/common/instant_types.h" |
58 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
59 #include "chrome/common/thumbnail_score.h" | 57 #include "chrome/common/thumbnail_score.h" |
60 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 base::HistogramBase* histogram = | 158 base::HistogramBase* histogram = |
161 base::StatisticsRecorder::FindHistogram(name); | 159 base::StatisticsRecorder::FindHistogram(name); |
162 if (!histogram) { | 160 if (!histogram) { |
163 // If no histogram is found, it's possible that no values have been | 161 // If no histogram is found, it's possible that no values have been |
164 // recorded yet. Assume that the value is zero. | 162 // recorded yet. Assume that the value is zero. |
165 return 0; | 163 return 0; |
166 } | 164 } |
167 return histogram->SnapshotSamples()->TotalCount(); | 165 return histogram->SnapshotSamples()->TotalCount(); |
168 } | 166 } |
169 | 167 |
170 void SendDownArrow() { | |
171 omnibox()->model()->OnUpOrDownKeyPressed(1); | |
172 // Wait for JavaScript to run the key handler by executing a blank script. | |
173 EXPECT_TRUE(ExecuteScript(std::string())); | |
174 } | |
175 | |
176 void SendUpArrow() { | |
177 omnibox()->model()->OnUpOrDownKeyPressed(-1); | |
178 // Wait for JavaScript to run the key handler by executing a blank script. | |
179 EXPECT_TRUE(ExecuteScript(std::string())); | |
180 } | |
181 | |
182 void SendEscape() { | |
183 omnibox()->model()->OnEscapeKeyPressed(); | |
184 // Wait for JavaScript to run the key handler by executing a blank script. | |
185 EXPECT_TRUE(ExecuteScript(std::string())); | |
186 } | |
187 | |
188 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { | 168 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { |
189 return GetIntFromJS(contents, "onMostVisitedChangedCalls", | 169 return GetIntFromJS(contents, "onMostVisitedChangedCalls", |
190 &on_most_visited_change_calls_) && | 170 &on_most_visited_change_calls_) && |
191 GetIntFromJS(contents, "mostVisitedItemsCount", | 171 GetIntFromJS(contents, "mostVisitedItemsCount", |
192 &most_visited_items_count_) && | 172 &most_visited_items_count_) && |
193 GetIntFromJS(contents, "firstMostVisitedItemId", | 173 GetIntFromJS(contents, "firstMostVisitedItemId", |
194 &first_most_visited_item_id_) && | 174 &first_most_visited_item_id_) && |
195 GetIntFromJS(contents, "onNativeSuggestionsCalls", | 175 GetIntFromJS(contents, "onNativeSuggestionsCalls", |
196 &on_native_suggestions_calls_) && | 176 &on_native_suggestions_calls_) && |
197 GetIntFromJS(contents, "onChangeCalls", | 177 GetIntFromJS(contents, "onChangeCalls", |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 ThemeServiceFactory::GetThemeForProfile( | 339 ThemeServiceFactory::GetThemeForProfile( |
360 ExtensionBrowserTest::browser()->profile()); | 340 ExtensionBrowserTest::browser()->profile()); |
361 ASSERT_NE(static_cast<extensions::Extension*>(NULL), new_theme); | 341 ASSERT_NE(static_cast<extensions::Extension*>(NULL), new_theme); |
362 ASSERT_EQ(new_theme->name(), theme_name); | 342 ASSERT_EQ(new_theme->name(), theme_name); |
363 } | 343 } |
364 | 344 |
365 private: | 345 private: |
366 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); | 346 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); |
367 }; | 347 }; |
368 | 348 |
369 IN_PROC_BROWSER_TEST_F(InstantExtendedNetworkTest, NTPReactsToNetworkChanges) { | |
kmadhusu
2014/01/09 23:31:43
Please remove the corresponding friend declaration
samarth
2014/01/10 05:13:32
Done.
| |
370 // Setup Instant. | |
371 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
372 FocusOmniboxAndWaitForInstantNTPSupport(); | |
373 | |
374 InstantService* instant_service = | |
375 InstantServiceFactory::GetForProfile(browser()->profile()); | |
376 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | |
377 | |
378 // The setup first initializes the platform specific NetworkChangeNotifier. | |
379 // The InstantExtendedNetworkTest replaces it with a fake, but by the time, | |
380 // InstantNTPPrerenderer has already registered itself. So the | |
381 // InstantNTPPrerenderer needs to register itself as NetworkChangeObserver | |
382 // again. | |
383 net::NetworkChangeNotifier::AddNetworkChangeObserver( | |
384 instant_service->ntp_prerenderer()); | |
385 | |
386 // The fake network change notifier will provide the network state to be | |
387 // offline, so the ntp will be local. | |
388 ASSERT_NE(static_cast<InstantNTP*>(NULL), | |
389 instant_service->ntp_prerenderer()->ntp()); | |
390 EXPECT_TRUE(instant_service->ntp_prerenderer()->ntp()->IsLocal()); | |
391 | |
392 // Change the connect state, and wait for the notifications to be run, and NTP | |
393 // support to be determined. | |
394 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET); | |
395 FocusOmniboxAndWaitForInstantNTPSupport(); | |
396 | |
397 // Verify the network state is fine, and InstantNTPPrerenderer doesn't want | |
398 // to switch to local NTP anymore. | |
399 EXPECT_FALSE(net::NetworkChangeNotifier::IsOffline()); | |
400 EXPECT_FALSE(instant_service->ntp_prerenderer()->ShouldSwitchToLocalNTP()); | |
401 | |
402 // Open new tab. | |
403 ui_test_utils::NavigateToURLWithDisposition( | |
404 browser(), | |
405 GURL(chrome::kChromeUINewTabURL), | |
406 NEW_FOREGROUND_TAB, | |
407 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | |
408 content::WebContents* active_tab = | |
409 browser()->tab_strip_model()->GetActiveWebContents(); | |
410 | |
411 // Verify new NTP is not local. | |
412 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); | |
413 EXPECT_NE(instant_service->ntp_prerenderer()->GetLocalInstantURL(), | |
414 active_tab->GetURL().spec()); | |
415 ASSERT_NE(static_cast<InstantNTP*>(NULL), | |
416 instant_service->ntp_prerenderer()->ntp()); | |
417 EXPECT_FALSE(instant_service->ntp_prerenderer()->ntp()->IsLocal()); | |
418 | |
419 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE); | |
420 FocusOmniboxAndWaitForInstantNTPSupport(); | |
421 | |
422 // Verify the network state is fine, and InstantNTPPrerenderer doesn't want | |
423 // to switch to local NTP anymore. | |
424 EXPECT_TRUE(net::NetworkChangeNotifier::IsOffline()); | |
425 EXPECT_TRUE(instant_service->ntp_prerenderer()->ShouldSwitchToLocalNTP()); | |
426 | |
427 // Open new tab. Preloaded NTP contents should have been used. | |
428 ui_test_utils::NavigateToURLWithDisposition( | |
429 browser(), | |
430 GURL(chrome::kChromeUINewTabURL), | |
431 NEW_FOREGROUND_TAB, | |
432 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | |
433 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
434 | |
435 // Verify new NTP is not local. | |
436 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); | |
437 EXPECT_EQ(instant_service->ntp_prerenderer()->GetLocalInstantURL(), | |
438 active_tab->GetURL().spec()); | |
439 ASSERT_NE(static_cast<InstantNTP*>(NULL), | |
440 instant_service->ntp_prerenderer()->ntp()); | |
441 EXPECT_TRUE(instant_service->ntp_prerenderer()->ntp()->IsLocal()); | |
442 } | |
443 | |
444 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { | 349 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { |
445 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 350 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
446 FocusOmniboxAndWaitForInstantNTPSupport(); | 351 FocusOmnibox(); |
447 | 352 |
448 content::WindowedNotificationObserver observer( | 353 content::WindowedNotificationObserver observer( |
449 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 354 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
450 content::NotificationService::AllSources()); | 355 content::NotificationService::AllSources()); |
451 SetOmniboxText("flowers"); | 356 SetOmniboxText("flowers"); |
452 PressEnterAndWaitForNavigation(); | 357 PressEnterAndWaitForNavigation(); |
453 observer.Wait(); | 358 observer.Wait(); |
454 | 359 |
455 // Just did a regular search. | 360 // Just did a regular search. |
456 content::WebContents* active_tab = | 361 content::WebContents* active_tab = |
457 browser()->tab_strip_model()->GetActiveWebContents(); | 362 browser()->tab_strip_model()->GetActiveWebContents(); |
458 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); | 363 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); |
459 ASSERT_TRUE(UpdateSearchState(active_tab)); | 364 ASSERT_TRUE(UpdateSearchState(active_tab)); |
460 ASSERT_EQ(0, submit_count_); | 365 ASSERT_EQ(0, submit_count_); |
461 | 366 |
462 SetOmniboxText("puppies"); | 367 SetOmniboxText("puppies"); |
463 PressEnterAndWaitForNavigation(); | 368 PressEnterAndWaitForNavigation(); |
464 | 369 |
465 // Should have reused the tab and sent an onsubmit message. | 370 // Should have reused the tab and sent an onsubmit message. |
466 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 371 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
467 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); | 372 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); |
468 ASSERT_TRUE(UpdateSearchState(active_tab)); | 373 ASSERT_TRUE(UpdateSearchState(active_tab)); |
469 EXPECT_EQ(1, submit_count_); | 374 EXPECT_EQ(1, submit_count_); |
470 } | 375 } |
471 | 376 |
472 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 377 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
473 SearchDoesntReuseInstantTabWithoutSupport) { | 378 SearchDoesntReuseInstantTabWithoutSupport) { |
474 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 379 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
475 FocusOmniboxAndWaitForInstantNTPSupport(); | 380 FocusOmnibox(); |
476 | 381 |
477 // Don't wait for the navigation to complete. | 382 // Don't wait for the navigation to complete. |
478 SetOmniboxText("flowers"); | 383 SetOmniboxText("flowers"); |
479 browser()->window()->GetLocationBar()->AcceptInput(); | 384 browser()->window()->GetLocationBar()->AcceptInput(); |
480 | 385 |
481 SetOmniboxText("puppies"); | 386 SetOmniboxText("puppies"); |
482 browser()->window()->GetLocationBar()->AcceptInput(); | 387 browser()->window()->GetLocationBar()->AcceptInput(); |
483 | 388 |
484 // Should not have reused the tab. | 389 // Should not have reused the tab. |
485 ASSERT_THAT( | 390 ASSERT_THAT( |
486 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), | 391 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), |
487 HasSubstr("q=puppies")); | 392 HasSubstr("q=puppies")); |
488 } | 393 } |
489 | 394 |
490 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 395 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
491 TypedSearchURLDoesntReuseInstantTab) { | 396 TypedSearchURLDoesntReuseInstantTab) { |
492 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 397 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
493 FocusOmniboxAndWaitForInstantNTPSupport(); | 398 FocusOmnibox(); |
494 | 399 |
495 // Create an observer to wait for the instant tab to support Instant. | 400 // Create an observer to wait for the instant tab to support Instant. |
496 content::WindowedNotificationObserver observer_1( | 401 content::WindowedNotificationObserver observer_1( |
497 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 402 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
498 content::NotificationService::AllSources()); | 403 content::NotificationService::AllSources()); |
499 SetOmniboxText("flowers"); | 404 SetOmniboxText("flowers"); |
500 PressEnterAndWaitForNavigation(); | 405 PressEnterAndWaitForNavigation(); |
501 observer_1.Wait(); | 406 observer_1.Wait(); |
502 | 407 |
503 // Just did a regular search. | 408 // Just did a regular search. |
(...skipping 11 matching lines...) Expand all Loading... | |
515 PressEnterAndWaitForNavigation(); | 420 PressEnterAndWaitForNavigation(); |
516 observer_2.Wait(); | 421 observer_2.Wait(); |
517 | 422 |
518 // Should not have reused the tab. | 423 // Should not have reused the tab. |
519 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 424 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
520 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); | 425 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); |
521 } | 426 } |
522 | 427 |
523 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) { | 428 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) { |
524 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 429 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
525 FocusOmniboxAndWaitForInstantNTPSupport(); | 430 FocusOmnibox(); |
526 | 431 |
527 // Create an observer to wait for the instant tab to support Instant. | 432 // Create an observer to wait for the instant tab to support Instant. |
528 content::WindowedNotificationObserver observer( | 433 content::WindowedNotificationObserver observer( |
529 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 434 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
530 content::NotificationService::AllSources()); | 435 content::NotificationService::AllSources()); |
531 | 436 |
532 SetOmniboxText("flowers"); | 437 SetOmniboxText("flowers"); |
533 browser()->window()->GetLocationBar()->AcceptInput(); | 438 browser()->window()->GetLocationBar()->AcceptInput(); |
534 observer.Wait(); | 439 observer.Wait(); |
535 | 440 |
536 const std::string& url = | 441 const std::string& url = |
537 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(); | 442 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(); |
538 // Make sure we actually used search_url, not instant_url. | 443 // Make sure we actually used search_url, not instant_url. |
539 ASSERT_THAT(url, HasSubstr("&is_search")); | 444 ASSERT_THAT(url, HasSubstr("&is_search")); |
540 EXPECT_THAT(url, HasSubstr("&es_sm=")); | 445 EXPECT_THAT(url, HasSubstr("&es_sm=")); |
541 } | 446 } |
542 | 447 |
543 // Test to verify that switching tabs should not dispatch onmostvisitedchanged | 448 // Test to verify that switching tabs should not dispatch onmostvisitedchanged |
544 // events. | 449 // events. |
545 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { | 450 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { |
546 // Initialize Instant. | 451 // Initialize Instant. |
547 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 452 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
548 FocusOmniboxAndWaitForInstantNTPSupport(); | 453 FocusOmnibox(); |
549 | 454 |
550 // Open new tab. Preloaded NTP contents should have been used. | 455 // Open new tab. Preloaded NTP contents should have been used. |
551 ui_test_utils::NavigateToURLWithDisposition( | 456 ui_test_utils::NavigateToURLWithDisposition( |
552 browser(), | 457 browser(), |
553 GURL(chrome::kChromeUINewTabURL), | 458 GURL(chrome::kChromeUINewTabURL), |
554 NEW_FOREGROUND_TAB, | 459 NEW_FOREGROUND_TAB, |
555 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 460 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
556 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 461 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
557 | 462 |
558 // Make sure new tab received the onmostvisitedchanged event once. | 463 // Make sure new tab received the onmostvisitedchanged event once. |
(...skipping 11 matching lines...) Expand all Loading... | |
570 // Confirm that new tab got no onmostvisitedchanged event. | 475 // Confirm that new tab got no onmostvisitedchanged event. |
571 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 476 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
572 EXPECT_TRUE(UpdateSearchState(active_tab)); | 477 EXPECT_TRUE(UpdateSearchState(active_tab)); |
573 EXPECT_EQ(1, on_most_visited_change_calls_); | 478 EXPECT_EQ(1, on_most_visited_change_calls_); |
574 } | 479 } |
575 | 480 |
576 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { | 481 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { |
577 InstallThemeSource(); | 482 InstallThemeSource(); |
578 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); | 483 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); |
579 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 484 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
580 FocusOmniboxAndWaitForInstantNTPSupport(); | 485 FocusOmnibox(); |
581 | 486 |
582 // The "Instant" New Tab should have access to chrome-search: scheme but not | 487 // The "Instant" New Tab should have access to chrome-search: scheme but not |
583 // chrome: scheme. | 488 // chrome: scheme. |
584 ui_test_utils::NavigateToURLWithDisposition( | 489 ui_test_utils::NavigateToURLWithDisposition( |
585 browser(), | 490 browser(), |
586 GURL(chrome::kChromeUINewTabURL), | 491 GURL(chrome::kChromeUINewTabURL), |
587 NEW_FOREGROUND_TAB, | 492 NEW_FOREGROUND_TAB, |
588 ui_test_utils::BROWSER_TEST_NONE); | 493 ui_test_utils::BROWSER_TEST_NONE); |
589 | 494 |
590 content::RenderViewHost* rvh = | 495 content::RenderViewHost* rvh = |
591 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | 496 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
592 | 497 |
593 const std::string chrome_url("chrome://theme/IDR_THEME_NTP_BACKGROUND"); | 498 const std::string chrome_url("chrome://theme/IDR_THEME_NTP_BACKGROUND"); |
594 const std::string search_url( | 499 const std::string search_url( |
595 "chrome-search://theme/IDR_THEME_NTP_BACKGROUND"); | 500 "chrome-search://theme/IDR_THEME_NTP_BACKGROUND"); |
596 bool loaded = false; | 501 bool loaded = false; |
597 ASSERT_TRUE(LoadImage(rvh, chrome_url, &loaded)); | 502 ASSERT_TRUE(LoadImage(rvh, chrome_url, &loaded)); |
598 EXPECT_FALSE(loaded) << chrome_url; | 503 EXPECT_FALSE(loaded) << chrome_url; |
599 ASSERT_TRUE(LoadImage(rvh, search_url, &loaded)); | 504 ASSERT_TRUE(LoadImage(rvh, search_url, &loaded)); |
600 EXPECT_TRUE(loaded) << search_url; | 505 EXPECT_TRUE(loaded) << search_url; |
601 } | 506 } |
602 | 507 |
603 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, | 508 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, |
604 NoThemeBackgroundChangeEventOnTabSwitch) { | 509 NoThemeBackgroundChangeEventOnTabSwitch) { |
605 InstallThemeSource(); | 510 InstallThemeSource(); |
606 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 511 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
607 FocusOmniboxAndWaitForInstantNTPSupport(); | 512 FocusOmnibox(); |
608 | 513 |
609 // Install a theme. | 514 // Install a theme. |
610 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); | 515 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); |
611 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 516 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
612 | 517 |
613 // Open new tab. Preloaded NTP contents should have been used. | 518 // Open new tab. Preloaded NTP contents should have been used. |
614 ui_test_utils::NavigateToURLWithDisposition( | 519 ui_test_utils::NavigateToURLWithDisposition( |
615 browser(), | 520 browser(), |
616 GURL(chrome::kChromeUINewTabURL), | 521 GURL(chrome::kChromeUINewTabURL), |
617 NEW_FOREGROUND_TAB, | 522 NEW_FOREGROUND_TAB, |
(...skipping 28 matching lines...) Expand all Loading... | |
646 // Flaky on Linux: http://crbug.com/265971 | 551 // Flaky on Linux: http://crbug.com/265971 |
647 #if defined(OS_LINUX) | 552 #if defined(OS_LINUX) |
648 #define MAYBE_SendThemeBackgroundChangedEvent DISABLED_SendThemeBackgroundChange dEvent | 553 #define MAYBE_SendThemeBackgroundChangedEvent DISABLED_SendThemeBackgroundChange dEvent |
649 #else | 554 #else |
650 #define MAYBE_SendThemeBackgroundChangedEvent SendThemeBackgroundChangedEvent | 555 #define MAYBE_SendThemeBackgroundChangedEvent SendThemeBackgroundChangedEvent |
651 #endif | 556 #endif |
652 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, | 557 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, |
653 MAYBE_SendThemeBackgroundChangedEvent) { | 558 MAYBE_SendThemeBackgroundChangedEvent) { |
654 InstallThemeSource(); | 559 InstallThemeSource(); |
655 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 560 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
656 FocusOmniboxAndWaitForInstantNTPSupport(); | 561 FocusOmnibox(); |
657 | 562 |
658 // Install a theme. | 563 // Install a theme. |
659 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); | 564 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); |
660 | 565 |
661 // Open new tab. Preloaded NTP contents should have been used. | 566 // Open new tab. Preloaded NTP contents should have been used. |
662 ui_test_utils::NavigateToURLWithDisposition( | 567 ui_test_utils::NavigateToURLWithDisposition( |
663 browser(), | 568 browser(), |
664 GURL(chrome::kChromeUINewTabURL), | 569 GURL(chrome::kChromeUINewTabURL), |
665 NEW_FOREGROUND_TAB, | 570 NEW_FOREGROUND_TAB, |
666 ui_test_utils::BROWSER_TEST_NONE); | 571 ui_test_utils::BROWSER_TEST_NONE); |
(...skipping 24 matching lines...) Expand all Loading... | |
691 #else | 596 #else |
692 #define MAYBE_UpdateSearchQueryOnBackNavigation UpdateSearchQueryOnBackNavigatio n | 597 #define MAYBE_UpdateSearchQueryOnBackNavigation UpdateSearchQueryOnBackNavigatio n |
693 #endif | 598 #endif |
694 // Test to verify that the omnibox search query is updated on browser | 599 // Test to verify that the omnibox search query is updated on browser |
695 // back button press event. | 600 // back button press event. |
696 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 601 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
697 MAYBE_UpdateSearchQueryOnBackNavigation) { | 602 MAYBE_UpdateSearchQueryOnBackNavigation) { |
698 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 603 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
699 | 604 |
700 // Focus omnibox and confirm overlay isn't shown. | 605 // Focus omnibox and confirm overlay isn't shown. |
701 FocusOmniboxAndWaitForInstantNTPSupport(); | 606 FocusOmnibox(); |
702 | 607 |
703 // Create an observer to wait for the instant tab to support Instant. | 608 // Create an observer to wait for the instant tab to support Instant. |
704 content::WindowedNotificationObserver observer( | 609 content::WindowedNotificationObserver observer( |
705 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 610 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
706 content::NotificationService::AllSources()); | 611 content::NotificationService::AllSources()); |
707 | 612 |
708 SetOmniboxText("flowers"); | 613 SetOmniboxText("flowers"); |
709 // Commit the search by pressing 'Enter'. | 614 // Commit the search by pressing 'Enter'. |
710 PressEnterAndWaitForNavigation(); | 615 PressEnterAndWaitForNavigation(); |
711 observer.Wait(); | 616 observer.Wait(); |
(...skipping 26 matching lines...) Expand all Loading... | |
738 } | 643 } |
739 | 644 |
740 // Flaky: crbug.com/253092. | 645 // Flaky: crbug.com/253092. |
741 // Test to verify that the omnibox search query is updated on browser | 646 // Test to verify that the omnibox search query is updated on browser |
742 // forward button press events. | 647 // forward button press events. |
743 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 648 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
744 DISABLED_UpdateSearchQueryOnForwardNavigation) { | 649 DISABLED_UpdateSearchQueryOnForwardNavigation) { |
745 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 650 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
746 | 651 |
747 // Focus omnibox and confirm overlay isn't shown. | 652 // Focus omnibox and confirm overlay isn't shown. |
748 FocusOmniboxAndWaitForInstantNTPSupport(); | 653 FocusOmnibox(); |
749 | 654 |
750 // Create an observer to wait for the instant tab to support Instant. | 655 // Create an observer to wait for the instant tab to support Instant. |
751 content::WindowedNotificationObserver observer( | 656 content::WindowedNotificationObserver observer( |
752 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 657 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
753 content::NotificationService::AllSources()); | 658 content::NotificationService::AllSources()); |
754 | 659 |
755 SetOmniboxText("flowers"); | 660 SetOmniboxText("flowers"); |
756 // Commit the search by pressing 'Enter'. | 661 // Commit the search by pressing 'Enter'. |
757 PressEnterAndWaitForNavigation(); | 662 PressEnterAndWaitForNavigation(); |
758 observer.Wait(); | 663 observer.Wait(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 // Commit the search by pressing 'Enter'. | 696 // Commit the search by pressing 'Enter'. |
792 FocusOmnibox(); | 697 FocusOmnibox(); |
793 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | 698 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); |
794 PressEnterAndWaitForNavigation(); | 699 PressEnterAndWaitForNavigation(); |
795 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | 700 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); |
796 } | 701 } |
797 | 702 |
798 // Flaky on all bots since re-enabled in r208032, crbug.com/253092 | 703 // Flaky on all bots since re-enabled in r208032, crbug.com/253092 |
799 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NavigateBackToNTP) { | 704 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NavigateBackToNTP) { |
800 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 705 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
801 FocusOmniboxAndWaitForInstantNTPSupport(); | 706 FocusOmnibox(); |
802 | 707 |
803 // Open a new tab page. | 708 // Open a new tab page. |
804 ui_test_utils::NavigateToURLWithDisposition( | 709 ui_test_utils::NavigateToURLWithDisposition( |
805 browser(), | 710 browser(), |
806 GURL(chrome::kChromeUINewTabURL), | 711 GURL(chrome::kChromeUINewTabURL), |
807 NEW_FOREGROUND_TAB, | 712 NEW_FOREGROUND_TAB, |
808 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 713 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
809 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 714 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
810 | 715 |
811 content::WindowedNotificationObserver observer( | 716 content::WindowedNotificationObserver observer( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 | 756 |
852 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 757 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
853 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); | 758 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); |
854 } | 759 } |
855 | 760 |
856 // Flaky: crbug.com/267119 | 761 // Flaky: crbug.com/267119 |
857 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 762 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
858 DISABLED_DispatchMVChangeEventWhileNavigatingBackToNTP) { | 763 DISABLED_DispatchMVChangeEventWhileNavigatingBackToNTP) { |
859 // Setup Instant. | 764 // Setup Instant. |
860 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 765 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
861 FocusOmniboxAndWaitForInstantNTPSupport(); | 766 FocusOmnibox(); |
862 | 767 |
863 // Open new tab. Preloaded NTP contents should have been used. | 768 // Open new tab. Preloaded NTP contents should have been used. |
864 ui_test_utils::NavigateToURLWithDisposition( | 769 ui_test_utils::NavigateToURLWithDisposition( |
865 browser(), | 770 browser(), |
866 GURL(chrome::kChromeUINewTabURL), | 771 GURL(chrome::kChromeUINewTabURL), |
867 NEW_FOREGROUND_TAB, | 772 NEW_FOREGROUND_TAB, |
868 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 773 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
869 | 774 |
870 content::WebContents* active_tab = | 775 content::WebContents* active_tab = |
871 browser()->tab_strip_model()->GetActiveWebContents(); | 776 browser()->tab_strip_model()->GetActiveWebContents(); |
(...skipping 20 matching lines...) Expand all Loading... | |
892 | 797 |
893 // Verify that onmostvisitedchange event is dispatched when we navigate from | 798 // Verify that onmostvisitedchange event is dispatched when we navigate from |
894 // SRP to NTP. | 799 // SRP to NTP. |
895 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 800 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
896 EXPECT_TRUE(UpdateSearchState(active_tab)); | 801 EXPECT_TRUE(UpdateSearchState(active_tab)); |
897 EXPECT_EQ(1, on_most_visited_change_calls_); | 802 EXPECT_EQ(1, on_most_visited_change_calls_); |
898 } | 803 } |
899 | 804 |
900 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, SetPrefetchQuery) { | 805 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, SetPrefetchQuery) { |
901 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 806 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
902 FocusOmniboxAndWaitForInstantNTPSupport(); | 807 FocusOmnibox(); |
903 | 808 |
904 content::WindowedNotificationObserver new_tab_observer( | 809 content::WindowedNotificationObserver new_tab_observer( |
905 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 810 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
906 content::NotificationService::AllSources()); | 811 content::NotificationService::AllSources()); |
907 ui_test_utils::NavigateToURLWithDisposition( | 812 ui_test_utils::NavigateToURLWithDisposition( |
908 browser(), | 813 browser(), |
909 GURL(chrome::kChromeUINewTabURL), | 814 GURL(chrome::kChromeUINewTabURL), |
910 CURRENT_TAB, | 815 CURRENT_TAB, |
911 ui_test_utils::BROWSER_TEST_NONE); | 816 ui_test_utils::BROWSER_TEST_NONE); |
912 new_tab_observer.Wait(); | 817 new_tab_observer.Wait(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 content::WebContents* active_tab = | 857 content::WebContents* active_tab = |
953 browser()->tab_strip_model()->GetActiveWebContents(); | 858 browser()->tab_strip_model()->GetActiveWebContents(); |
954 ASSERT_TRUE(UpdateSearchState(active_tab)); | 859 ASSERT_TRUE(UpdateSearchState(active_tab)); |
955 ASSERT_TRUE(SearchProvider::ShouldPrefetch(*( | 860 ASSERT_TRUE(SearchProvider::ShouldPrefetch(*( |
956 omnibox()->model()->result().default_match()))); | 861 omnibox()->model()->result().default_match()))); |
957 ASSERT_EQ("puppy", prefetch_query_value_); | 862 ASSERT_EQ("puppy", prefetch_query_value_); |
958 } | 863 } |
959 | 864 |
960 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, ClearPrefetchedResults) { | 865 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, ClearPrefetchedResults) { |
961 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 866 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
962 FocusOmniboxAndWaitForInstantNTPSupport(); | 867 FocusOmnibox(); |
963 | 868 |
964 content::WindowedNotificationObserver new_tab_observer( | 869 content::WindowedNotificationObserver new_tab_observer( |
965 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 870 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
966 content::NotificationService::AllSources()); | 871 content::NotificationService::AllSources()); |
967 ui_test_utils::NavigateToURLWithDisposition( | 872 ui_test_utils::NavigateToURLWithDisposition( |
968 browser(), | 873 browser(), |
969 GURL(chrome::kChromeUINewTabURL), | 874 GURL(chrome::kChromeUINewTabURL), |
970 CURRENT_TAB, | 875 CURRENT_TAB, |
971 ui_test_utils::BROWSER_TEST_NONE); | 876 ui_test_utils::BROWSER_TEST_NONE); |
972 new_tab_observer.Wait(); | 877 new_tab_observer.Wait(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 // the search terms is sufficient. | 949 // the search terms is sufficient. |
1045 EXPECT_NE(ASCIIToUTF16("foo"), omnibox()->GetText()); | 950 EXPECT_NE(ASCIIToUTF16("foo"), omnibox()->GetText()); |
1046 } | 951 } |
1047 | 952 |
1048 // Check that clicking on a result sends the correct referrer. | 953 // Check that clicking on a result sends the correct referrer. |
1049 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { | 954 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { |
1050 ASSERT_TRUE(test_server()->Start()); | 955 ASSERT_TRUE(test_server()->Start()); |
1051 GURL result_url = | 956 GURL result_url = |
1052 test_server()->GetURL("files/referrer_policy/referrer-policy-log.html"); | 957 test_server()->GetURL("files/referrer_policy/referrer-policy-log.html"); |
1053 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 958 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
1054 FocusOmniboxAndWaitForInstantNTPSupport(); | 959 FocusOmnibox(); |
1055 | 960 |
1056 // Type a query and press enter to get results. | 961 // Type a query and press enter to get results. |
1057 SetOmniboxText("query"); | 962 SetOmniboxText("query"); |
1058 PressEnterAndWaitForNavigation(); | 963 PressEnterAndWaitForNavigation(); |
1059 | 964 |
1060 // Simulate going to a result. | 965 // Simulate going to a result. |
1061 content::WebContents* contents = | 966 content::WebContents* contents = |
1062 browser()->tab_strip_model()->GetActiveWebContents(); | 967 browser()->tab_strip_model()->GetActiveWebContents(); |
1063 std::ostringstream stream; | 968 std::ostringstream stream; |
1064 stream << "var link = document.createElement('a');"; | 969 stream << "var link = document.createElement('a');"; |
1065 stream << "link.href = \"" << result_url.spec() << "\";"; | 970 stream << "link.href = \"" << result_url.spec() << "\";"; |
1066 stream << "document.body.appendChild(link);"; | 971 stream << "document.body.appendChild(link);"; |
1067 stream << "link.click();"; | 972 stream << "link.click();"; |
1068 EXPECT_TRUE(content::ExecuteScript(contents, stream.str())); | 973 EXPECT_TRUE(content::ExecuteScript(contents, stream.str())); |
1069 | 974 |
1070 content::WaitForLoadStop(contents); | 975 content::WaitForLoadStop(contents); |
1071 std::string expected_title = | 976 std::string expected_title = |
1072 "Referrer is " + instant_url().GetWithEmptyPath().spec(); | 977 "Referrer is " + instant_url().GetWithEmptyPath().spec(); |
1073 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle()); | 978 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle()); |
1074 } | 979 } |
OLD | NEW |