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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 first_most_visited_item_id_(0), | 139 first_most_visited_item_id_(0), |
140 on_native_suggestions_calls_(0), | 140 on_native_suggestions_calls_(0), |
141 on_change_calls_(0), | 141 on_change_calls_(0), |
142 submit_count_(0), | 142 submit_count_(0), |
143 on_esc_key_press_event_calls_(0), | 143 on_esc_key_press_event_calls_(0), |
144 on_focus_changed_calls_(0), | 144 on_focus_changed_calls_(0), |
145 is_focused_(false) {} | 145 is_focused_(false) {} |
146 | 146 |
147 protected: | 147 protected: |
148 void SetUpInProcessBrowserTestFixture() override { | 148 void SetUpInProcessBrowserTestFixture() override { |
149 search::EnableQueryExtractionForTesting(); | |
150 ASSERT_TRUE(https_test_server().Start()); | 149 ASSERT_TRUE(https_test_server().Start()); |
151 GURL instant_url = | 150 GURL instant_url = |
152 https_test_server().GetURL("/instant_extended.html?strk=1&"); | 151 https_test_server().GetURL("/instant_extended.html?strk=1&"); |
153 GURL ntp_url = | 152 GURL ntp_url = |
154 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&"); | 153 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&"); |
155 InstantTestBase::Init(instant_url, ntp_url, false); | 154 InstantTestBase::Init(instant_url, ntp_url, false); |
156 } | 155 } |
157 | 156 |
158 int64_t GetHistogramCount(const char* name) { | 157 int64_t GetHistogramCount(const char* name) { |
159 base::HistogramBase* histogram = | 158 base::HistogramBase* histogram = |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 }; | 249 }; |
251 | 250 |
252 class InstantExtendedPrefetchTest : public InstantExtendedTest { | 251 class InstantExtendedPrefetchTest : public InstantExtendedTest { |
253 public: | 252 public: |
254 InstantExtendedPrefetchTest() | 253 InstantExtendedPrefetchTest() |
255 : factory_(new net::URLFetcherImplFactory()), | 254 : factory_(new net::URLFetcherImplFactory()), |
256 fake_factory_(new net::FakeURLFetcherFactory(factory_.get())) { | 255 fake_factory_(new net::FakeURLFetcherFactory(factory_.get())) { |
257 } | 256 } |
258 | 257 |
259 void SetUpInProcessBrowserTestFixture() override { | 258 void SetUpInProcessBrowserTestFixture() override { |
260 search::EnableQueryExtractionForTesting(); | |
261 ASSERT_TRUE(https_test_server().Start()); | 259 ASSERT_TRUE(https_test_server().Start()); |
262 GURL instant_url = | 260 GURL instant_url = |
263 https_test_server().GetURL("/instant_extended.html?strk=1&"); | 261 https_test_server().GetURL("/instant_extended.html?strk=1&"); |
264 GURL ntp_url = | 262 GURL ntp_url = |
265 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&"); | 263 https_test_server().GetURL("/instant_extended_ntp.html?strk=1&"); |
266 InstantTestBase::Init(instant_url, ntp_url, true); | 264 InstantTestBase::Init(instant_url, ntp_url, true); |
267 } | 265 } |
268 | 266 |
269 net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); } | 267 net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); } |
270 | 268 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 ThemeServiceFactory::GetThemeForProfile( | 314 ThemeServiceFactory::GetThemeForProfile( |
317 ExtensionBrowserTest::browser()->profile()); | 315 ExtensionBrowserTest::browser()->profile()); |
318 ASSERT_NE(static_cast<extensions::Extension*>(NULL), new_theme); | 316 ASSERT_NE(static_cast<extensions::Extension*>(NULL), new_theme); |
319 ASSERT_EQ(new_theme->name(), theme_name); | 317 ASSERT_EQ(new_theme->name(), theme_name); |
320 } | 318 } |
321 | 319 |
322 private: | 320 private: |
323 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); | 321 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); |
324 }; | 322 }; |
325 | 323 |
326 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { | 324 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchDoesntReuseInstantTab) { |
327 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 325 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
328 FocusOmnibox(); | 326 FocusOmnibox(); |
329 | 327 |
330 content::WindowedNotificationObserver observer( | |
331 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
332 content::NotificationService::AllSources()); | |
333 SetOmniboxText("flowers"); | 328 SetOmniboxText("flowers"); |
334 PressEnterAndWaitForFrameLoad(); | 329 PressEnterAndWaitForFrameLoad(); |
335 observer.Wait(); | |
336 | 330 |
337 // Just did a regular search. | 331 // Just did a regular search. |
338 content::WebContents* active_tab = | 332 content::WebContents* active_tab = |
339 browser()->tab_strip_model()->GetActiveWebContents(); | 333 browser()->tab_strip_model()->GetActiveWebContents(); |
340 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); | 334 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); |
341 ASSERT_TRUE(UpdateSearchState(active_tab)); | 335 ASSERT_TRUE(UpdateSearchState(active_tab)); |
342 ASSERT_EQ(0, submit_count_); | 336 ASSERT_EQ(0, submit_count_); |
343 | 337 |
344 SetOmniboxText("puppies"); | 338 SetOmniboxText("puppies"); |
345 PressEnterAndWaitForNavigation(); | 339 PressEnterAndWaitForNavigation(); |
346 | 340 |
347 // Should have reused the tab and sent an onsubmit message. | 341 // Should not have reused the tab. |
348 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 342 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
349 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); | 343 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); |
350 ASSERT_TRUE(UpdateSearchState(active_tab)); | 344 ASSERT_TRUE(UpdateSearchState(active_tab)); |
351 EXPECT_EQ(1, submit_count_); | 345 EXPECT_EQ(0, submit_count_); |
352 } | 346 } |
353 | 347 |
354 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 348 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
355 SearchDoesntReuseInstantTabWithoutSupport) { | 349 SearchDoesntReuseInstantTabWithoutSupport) { |
356 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 350 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
357 FocusOmnibox(); | 351 FocusOmnibox(); |
358 | 352 |
359 // Don't wait for the navigation to complete. | 353 // Don't wait for the navigation to complete. |
360 SetOmniboxText("flowers"); | 354 SetOmniboxText("flowers"); |
361 browser()->window()->GetLocationBar()->AcceptInput(); | 355 browser()->window()->GetLocationBar()->AcceptInput(); |
362 | 356 |
363 SetOmniboxText("puppies"); | 357 SetOmniboxText("puppies"); |
364 browser()->window()->GetLocationBar()->AcceptInput(); | 358 browser()->window()->GetLocationBar()->AcceptInput(); |
365 | 359 |
366 // Should not have reused the tab. | 360 // Should not have reused the tab. |
367 ASSERT_THAT( | 361 ASSERT_THAT( |
368 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), | 362 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), |
369 HasSubstr("q=puppies")); | 363 HasSubstr("q=puppies")); |
370 } | 364 } |
371 | 365 |
372 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 366 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
373 TypedSearchURLDoesntReuseInstantTab) { | 367 TypedSearchURLDoesntReuseInstantTab) { |
374 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 368 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
375 FocusOmnibox(); | 369 FocusOmnibox(); |
376 | 370 |
377 // Create an observer to wait for the instant tab to support Instant. | |
378 content::WindowedNotificationObserver observer_1( | |
379 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
380 content::NotificationService::AllSources()); | |
381 SetOmniboxText("flowers"); | 371 SetOmniboxText("flowers"); |
382 PressEnterAndWaitForFrameLoad(); | 372 PressEnterAndWaitForFrameLoad(); |
383 observer_1.Wait(); | |
384 | 373 |
385 // Just did a regular search. | 374 // Just did a regular search. |
386 content::WebContents* active_tab = | 375 content::WebContents* active_tab = |
387 browser()->tab_strip_model()->GetActiveWebContents(); | 376 browser()->tab_strip_model()->GetActiveWebContents(); |
388 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); | 377 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); |
389 ASSERT_TRUE(UpdateSearchState(active_tab)); | 378 ASSERT_TRUE(UpdateSearchState(active_tab)); |
390 ASSERT_EQ(0, submit_count_); | 379 ASSERT_EQ(0, submit_count_); |
391 | 380 |
392 // Typed in a search URL "by hand". | 381 // Typed in a search URL "by hand". |
393 content::WindowedNotificationObserver observer_2( | |
394 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
395 content::NotificationService::AllSources()); | |
396 SetOmniboxText(instant_url().Resolve("#q=puppies").spec()); | 382 SetOmniboxText(instant_url().Resolve("#q=puppies").spec()); |
397 PressEnterAndWaitForNavigation(); | 383 PressEnterAndWaitForNavigation(); |
398 observer_2.Wait(); | |
399 | 384 |
400 // Should not have reused the tab. | 385 // Should not have reused the tab. |
401 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 386 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
402 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); | 387 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); |
403 } | 388 } |
404 | 389 |
405 // Test to verify that switching tabs should not dispatch onmostvisitedchanged | 390 // Test to verify that switching tabs should not dispatch onmostvisitedchanged |
406 // events. | 391 // events. |
407 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { | 392 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { |
408 // Initialize Instant. | 393 // Initialize Instant. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // Install a new theme. | 520 // Install a new theme. |
536 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme2", "snowflake theme")); | 521 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme2", "snowflake theme")); |
537 | 522 |
538 // Confirm that new tab is notified about the theme changed event. | 523 // Confirm that new tab is notified about the theme changed event. |
539 on_theme_changed_calls = 0; | 524 on_theme_changed_calls = 0; |
540 EXPECT_TRUE(GetIntFromJS(active_tab, "onThemeChangedCalls", | 525 EXPECT_TRUE(GetIntFromJS(active_tab, "onThemeChangedCalls", |
541 &on_theme_changed_calls)); | 526 &on_theme_changed_calls)); |
542 EXPECT_EQ(2, on_theme_changed_calls); | 527 EXPECT_EQ(2, on_theme_changed_calls); |
543 } | 528 } |
544 | 529 |
545 // Flaky on all bots. http://crbug.com/253092 | |
546 // Test to verify that the omnibox search query is updated on browser | |
547 // back button press event. | |
548 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | |
549 DISABLED_UpdateSearchQueryOnBackNavigation) { | |
550 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
551 | |
552 // Focus omnibox and confirm overlay isn't shown. | |
553 FocusOmnibox(); | |
554 | |
555 // Create an observer to wait for the instant tab to support Instant. | |
556 content::WindowedNotificationObserver observer( | |
557 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
558 content::NotificationService::AllSources()); | |
559 | |
560 SetOmniboxText("flowers"); | |
561 // Commit the search by pressing 'Enter'. | |
562 PressEnterAndWaitForNavigation(); | |
563 observer.Wait(); | |
564 | |
565 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
566 | |
567 // Typing in the new search query in omnibox. | |
568 SetOmniboxText("cattles"); | |
569 // Commit the search by pressing 'Enter'. | |
570 PressEnterAndWaitForNavigation(); | |
571 // 'Enter' commits the query as it was typed. This creates a navigation entry | |
572 // in the history. | |
573 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
574 | |
575 content::WebContents* active_tab = | |
576 browser()->tab_strip_model()->GetActiveWebContents(); | |
577 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
578 content::WindowedNotificationObserver load_stop_observer( | |
579 content::NOTIFICATION_LOAD_STOP, | |
580 content::Source<content::NavigationController>( | |
581 &active_tab->GetController())); | |
582 active_tab->GetController().GoBack(); | |
583 load_stop_observer.Wait(); | |
584 | |
585 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
586 // Commit the search by pressing 'Enter'. | |
587 FocusOmnibox(); | |
588 PressEnterAndWaitForNavigation(); | |
589 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
590 } | |
591 | |
592 // Flaky: crbug.com/253092. | |
593 // Test to verify that the omnibox search query is updated on browser | |
594 // forward button press events. | |
595 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | |
596 DISABLED_UpdateSearchQueryOnForwardNavigation) { | |
597 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
598 | |
599 // Focus omnibox and confirm overlay isn't shown. | |
600 FocusOmnibox(); | |
601 | |
602 // Create an observer to wait for the instant tab to support Instant. | |
603 content::WindowedNotificationObserver observer( | |
604 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
605 content::NotificationService::AllSources()); | |
606 | |
607 SetOmniboxText("flowers"); | |
608 // Commit the search by pressing 'Enter'. | |
609 PressEnterAndWaitForNavigation(); | |
610 observer.Wait(); | |
611 | |
612 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
613 | |
614 // Typing in the new search query in omnibox. | |
615 SetOmniboxText("cattles"); | |
616 // Commit the search by pressing 'Enter'. | |
617 PressEnterAndWaitForNavigation(); | |
618 // 'Enter' commits the query as it was typed. This creates a navigation entry | |
619 // in the history. | |
620 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
621 | |
622 content::WebContents* active_tab = | |
623 browser()->tab_strip_model()->GetActiveWebContents(); | |
624 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
625 content::WindowedNotificationObserver load_stop_observer( | |
626 content::NOTIFICATION_LOAD_STOP, | |
627 content::Source<content::NavigationController>( | |
628 &active_tab->GetController())); | |
629 active_tab->GetController().GoBack(); | |
630 load_stop_observer.Wait(); | |
631 | |
632 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
633 | |
634 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
635 EXPECT_TRUE(active_tab->GetController().CanGoForward()); | |
636 content::WindowedNotificationObserver load_stop_observer_2( | |
637 content::NOTIFICATION_LOAD_STOP, | |
638 content::Source<content::NavigationController>( | |
639 &active_tab->GetController())); | |
640 active_tab->GetController().GoForward(); | |
641 load_stop_observer_2.Wait(); | |
642 | |
643 // Commit the search by pressing 'Enter'. | |
644 FocusOmnibox(); | |
645 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
646 PressEnterAndWaitForNavigation(); | |
647 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
648 } | |
649 | |
650 // Flaky on all bots since re-enabled in r208032, crbug.com/253092 | 530 // Flaky on all bots since re-enabled in r208032, crbug.com/253092 |
651 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NavigateBackToNTP) { | 531 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NavigateBackToNTP) { |
652 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 532 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
653 FocusOmnibox(); | 533 FocusOmnibox(); |
654 | 534 |
655 // Open a new tab page. | 535 // Open a new tab page. |
656 ui_test_utils::NavigateToURLWithDisposition( | 536 ui_test_utils::NavigateToURLWithDisposition( |
657 browser(), | 537 browser(), |
658 GURL(chrome::kChromeUINewTabURL), | 538 GURL(chrome::kChromeUINewTabURL), |
659 NEW_FOREGROUND_TAB, | 539 NEW_FOREGROUND_TAB, |
660 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | 540 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
661 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 541 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
662 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 542 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
663 | 543 |
664 content::WindowedNotificationObserver observer( | |
665 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
666 content::NotificationService::AllSources()); | |
667 SetOmniboxText("flowers"); | 544 SetOmniboxText("flowers"); |
668 PressEnterAndWaitForNavigation(); | 545 PressEnterAndWaitForNavigation(); |
669 observer.Wait(); | |
670 | 546 |
671 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | 547 // Navigate back to NTP. |
672 | |
673 // Typing in the new search query in omnibox. | |
674 // Commit the search by pressing 'Enter'. | |
675 SetOmniboxText("cattles"); | |
676 PressEnterAndWaitForNavigation(); | |
677 | |
678 // 'Enter' commits the query as it was typed. This creates a navigation entry | |
679 // in the history. | |
680 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
681 | |
682 // Navigate back to "flowers" search result page. | |
683 content::WebContents* active_tab = | 548 content::WebContents* active_tab = |
684 browser()->tab_strip_model()->GetActiveWebContents(); | 549 browser()->tab_strip_model()->GetActiveWebContents(); |
685 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | 550 EXPECT_TRUE(active_tab->GetController().CanGoBack()); |
686 content::WindowedNotificationObserver load_stop_observer( | 551 content::WindowedNotificationObserver load_stop_observer( |
687 content::NOTIFICATION_LOAD_STOP, | 552 content::NOTIFICATION_LOAD_STOP, |
688 content::Source<content::NavigationController>( | 553 content::Source<content::NavigationController>( |
689 &active_tab->GetController())); | 554 &active_tab->GetController())); |
690 active_tab->GetController().GoBack(); | 555 active_tab->GetController().GoBack(); |
691 load_stop_observer.Wait(); | 556 load_stop_observer.Wait(); |
692 | 557 |
693 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
694 | |
695 // Navigate back to NTP. | |
696 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
697 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
698 content::WindowedNotificationObserver load_stop_observer_2( | |
699 content::NOTIFICATION_LOAD_STOP, | |
700 content::Source<content::NavigationController>( | |
701 &active_tab->GetController())); | |
702 active_tab->GetController().GoBack(); | |
703 load_stop_observer_2.Wait(); | |
704 | |
705 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 558 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
706 EXPECT_TRUE(search::IsInstantNTP(active_tab)); | 559 EXPECT_TRUE(search::IsInstantNTP(active_tab)); |
707 } | 560 } |
708 | 561 |
709 // Flaky: crbug.com/267119 | 562 // Flaky: crbug.com/267119 |
710 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 563 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
711 DISABLED_DispatchMVChangeEventWhileNavigatingBackToNTP) { | 564 DISABLED_DispatchMVChangeEventWhileNavigatingBackToNTP) { |
712 // Setup Instant. | 565 // Setup Instant. |
713 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 566 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
714 FocusOmnibox(); | 567 FocusOmnibox(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 | 627 |
775 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0; | 628 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0; |
776 | 629 |
777 // Set the fake response for search query. | 630 // Set the fake response for search query. |
778 fake_factory()->SetFakeResponse(instant_url().Resolve("#q=flowers"), | 631 fake_factory()->SetFakeResponse(instant_url().Resolve("#q=flowers"), |
779 "", | 632 "", |
780 net::HTTP_OK, | 633 net::HTTP_OK, |
781 net::URLRequestStatus::SUCCESS); | 634 net::URLRequestStatus::SUCCESS); |
782 | 635 |
783 // Navigate to a search results page. | 636 // Navigate to a search results page. |
784 content::WindowedNotificationObserver observer( | |
785 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
786 content::NotificationService::AllSources()); | |
787 SetOmniboxText("flowers"); | 637 SetOmniboxText("flowers"); |
788 PressEnterAndWaitForNavigation(); | 638 PressEnterAndWaitForNavigation(); |
789 observer.Wait(); | |
790 | 639 |
791 // Set the fake response for suggest request. Response has prefetch details. | 640 // Set the fake response for suggest request. Response has prefetch details. |
792 // Ensure that the page received the suggest response, then add another | 641 // Ensure that the page received the suggest response, then add another |
793 // keystroke to allow the asynchronously-received inline autocomplete | 642 // keystroke to allow the asynchronously-received inline autocomplete |
794 // suggestion to actually be inlined (which in turn triggers it to prefetch). | 643 // suggestion to actually be inlined (which in turn triggers it to prefetch). |
795 fake_factory()->SetFakeResponse( | 644 fake_factory()->SetFakeResponse( |
796 instant_url().Resolve("#q=pup"), | 645 instant_url().Resolve("#q=pup"), |
797 "[\"pup\",[\"puppy\", \"puppies\"],[],[]," | 646 "[\"pup\",[\"puppy\", \"puppies\"],[],[]," |
798 "{\"google:clientdata\":{\"phi\": 0}," | 647 "{\"google:clientdata\":{\"phi\": 0}," |
799 "\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," | 648 "\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 | 693 |
845 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0; | 694 OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs = 0; |
846 | 695 |
847 // Set the fake response for search query. | 696 // Set the fake response for search query. |
848 fake_factory()->SetFakeResponse(instant_url().Resolve("#q=flowers"), | 697 fake_factory()->SetFakeResponse(instant_url().Resolve("#q=flowers"), |
849 "", | 698 "", |
850 net::HTTP_OK, | 699 net::HTTP_OK, |
851 net::URLRequestStatus::SUCCESS); | 700 net::URLRequestStatus::SUCCESS); |
852 | 701 |
853 // Navigate to a search results page. | 702 // Navigate to a search results page. |
854 content::WindowedNotificationObserver observer( | |
855 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
856 content::NotificationService::AllSources()); | |
857 SetOmniboxText("flowers"); | 703 SetOmniboxText("flowers"); |
858 PressEnterAndWaitForNavigation(); | 704 PressEnterAndWaitForNavigation(); |
859 observer.Wait(); | |
860 | 705 |
861 // Set the fake response for suggest request. Response has no prefetch | 706 // Set the fake response for suggest request. Response has no prefetch |
862 // details. Ensure that the page received a blank query to clear the | 707 // details. Ensure that the page received a blank query to clear the |
863 // prefetched results. | 708 // prefetched results. |
864 fake_factory()->SetFakeResponse( | 709 fake_factory()->SetFakeResponse( |
865 instant_url().Resolve("#q=dogs"), | 710 instant_url().Resolve("#q=dogs"), |
866 "[\"dogs\",[\"https://dogs.com\"],[],[]," | 711 "[\"dogs\",[\"https://dogs.com\"],[],[]," |
867 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 712 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
868 "\"google:suggestrelevance\":[2]}]", | 713 "\"google:suggestrelevance\":[2]}]", |
869 net::HTTP_OK, | 714 net::HTTP_OK, |
(...skipping 10 matching lines...) Expand all Loading... |
880 | 725 |
881 ASSERT_EQ(2, CountSearchProviderSuggestions()); | 726 ASSERT_EQ(2, CountSearchProviderSuggestions()); |
882 ASSERT_FALSE(SearchProvider::ShouldPrefetch(*( | 727 ASSERT_FALSE(SearchProvider::ShouldPrefetch(*( |
883 omnibox()->model()->result().default_match()))); | 728 omnibox()->model()->result().default_match()))); |
884 content::WebContents* active_tab = | 729 content::WebContents* active_tab = |
885 browser()->tab_strip_model()->GetActiveWebContents(); | 730 browser()->tab_strip_model()->GetActiveWebContents(); |
886 ASSERT_TRUE(UpdateSearchState(active_tab)); | 731 ASSERT_TRUE(UpdateSearchState(active_tab)); |
887 ASSERT_EQ("", prefetch_query_value_); | 732 ASSERT_EQ("", prefetch_query_value_); |
888 } | 733 } |
889 | 734 |
890 #if defined(OS_LINUX) && defined(ADDRESS_SANITIZER) | |
891 // Flaky timeouts at shutdown on Linux ASan; http://crbug.com/505478. | |
892 #define MAYBE_ShowURL DISABLED_ShowURL | |
893 #else | |
894 #define MAYBE_ShowURL ShowURL | |
895 #endif | |
896 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_ShowURL) { | |
897 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
898 FocusOmnibox(); | |
899 | |
900 // Create an observer to wait for the instant tab to support Instant. | |
901 content::WindowedNotificationObserver observer( | |
902 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
903 content::NotificationService::AllSources()); | |
904 | |
905 // Do a search and commit it. The omnibox should show the search terms. | |
906 SetOmniboxText("foo"); | |
907 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); | |
908 browser()->window()->GetLocationBar()->AcceptInput(); | |
909 observer.Wait(); | |
910 EXPECT_FALSE(omnibox()->model()->user_input_in_progress()); | |
911 EXPECT_TRUE(browser()->toolbar_model()->WouldPerformSearchTermReplacement( | |
912 false)); | |
913 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); | |
914 | |
915 // Calling ShowURL() should disable search term replacement and show the URL. | |
916 omnibox()->ShowURL(); | |
917 EXPECT_FALSE(browser()->toolbar_model()->WouldPerformSearchTermReplacement( | |
918 false)); | |
919 // Don't bother looking for a specific URL; ensuring we're no longer showing | |
920 // the search terms is sufficient. | |
921 EXPECT_NE(ASCIIToUTF16("foo"), omnibox()->GetText()); | |
922 } | |
923 | |
924 // Check that clicking on a result sends the correct referrer. | 735 // Check that clicking on a result sends the correct referrer. |
925 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { | 736 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, Referrer) { |
926 ASSERT_TRUE(embedded_test_server()->Start()); | 737 ASSERT_TRUE(embedded_test_server()->Start()); |
927 GURL result_url = embedded_test_server()->GetURL( | 738 GURL result_url = embedded_test_server()->GetURL( |
928 "/referrer_policy/referrer-policy-log.html"); | 739 "/referrer_policy/referrer-policy-log.html"); |
929 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 740 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
930 FocusOmnibox(); | 741 FocusOmnibox(); |
931 | 742 |
932 // Type a query and press enter to get results. | 743 // Type a query and press enter to get results. |
933 SetOmniboxText("query"); | 744 SetOmniboxText("query"); |
934 PressEnterAndWaitForFrameLoad(); | 745 PressEnterAndWaitForFrameLoad(); |
935 | 746 |
936 // Simulate going to a result. | 747 // Simulate going to a result. |
937 content::WebContents* contents = | 748 content::WebContents* contents = |
938 browser()->tab_strip_model()->GetActiveWebContents(); | 749 browser()->tab_strip_model()->GetActiveWebContents(); |
939 std::ostringstream stream; | 750 std::ostringstream stream; |
940 stream << "var link = document.createElement('a');"; | 751 stream << "var link = document.createElement('a');"; |
941 stream << "link.href = \"" << result_url.spec() << "\";"; | 752 stream << "link.href = \"" << result_url.spec() << "\";"; |
942 stream << "document.body.appendChild(link);"; | 753 stream << "document.body.appendChild(link);"; |
943 stream << "link.click();"; | 754 stream << "link.click();"; |
944 EXPECT_TRUE(content::ExecuteScript(contents, stream.str())); | 755 EXPECT_TRUE(content::ExecuteScript(contents, stream.str())); |
945 | 756 |
946 content::WaitForLoadStop(contents); | 757 content::WaitForLoadStop(contents); |
947 std::string expected_title = | 758 std::string expected_title = |
948 "Referrer is " + instant_url().GetWithEmptyPath().spec(); | 759 "Referrer is " + instant_url().GetWithEmptyPath().spec(); |
949 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle()); | 760 EXPECT_EQ(ASCIIToUTF16(expected_title), contents->GetTitle()); |
950 } | 761 } |
OLD | NEW |