| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 11 #include "chrome/browser/instant/instant_controller.h" | 11 #include "chrome/browser/instant/instant_controller.h" |
| 12 #include "chrome/browser/instant/instant_loader.h" | 12 #include "chrome/browser/instant/instant_loader.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/browser/search_engines/template_url_service.h" | 16 #include "chrome/browser/search_engines/template_url_service.h" |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "chrome/browser/task_manager/task_manager.h" | 18 #include "chrome/browser/task_manager/task_manager.h" |
| 19 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 19 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/omnibox/location_bar.h" | 22 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 23 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 23 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "chrome/test/base/in_process_browser_test.h" | 29 #include "chrome/test/base/in_process_browser_test.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
| 32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
| 34 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 InstantController* instant() const { | 115 InstantController* instant() const { |
| 116 return browser()->instant(); | 116 return browser()->instant(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 OmniboxView* omnibox() const { | 119 OmniboxView* omnibox() const { |
| 120 return browser()->window()->GetLocationBar()->GetLocationEntry(); | 120 return browser()->window()->GetLocationBar()->GetLocationEntry(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TabContentsWrapper* preview() const { | 123 TabContents* preview() const { |
| 124 return instant()->GetPreviewContents(); | 124 return instant()->GetPreviewContents(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 InstantLoader* loader() const { | 127 InstantLoader* loader() const { |
| 128 return instant()->loader_.get(); | 128 return instant()->loader_.get(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 std::string GetSuggestion() const { | 131 std::string GetSuggestion() const { |
| 132 return UTF16ToUTF8(loader()->complete_suggested_text_); | 132 return UTF16ToUTF8(loader()->complete_suggested_text_); |
| 133 } | 133 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 WebContents* preview_tab = preview()->web_contents(); | 314 WebContents* preview_tab = preview()->web_contents(); |
| 315 EXPECT_TRUE(preview_tab); | 315 EXPECT_TRUE(preview_tab); |
| 316 | 316 |
| 317 ASSERT_TRUE(PressEnter()); | 317 ASSERT_TRUE(PressEnter()); |
| 318 | 318 |
| 319 // Check that the preview has been committed. | 319 // Check that the preview has been committed. |
| 320 EXPECT_FALSE(preview()); | 320 EXPECT_FALSE(preview()); |
| 321 EXPECT_FALSE(instant()->is_displayable()); | 321 EXPECT_FALSE(instant()->is_displayable()); |
| 322 EXPECT_FALSE(instant()->IsCurrent()); | 322 EXPECT_FALSE(instant()->IsCurrent()); |
| 323 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents()); | 323 EXPECT_EQ(preview_tab, browser()->GetActiveWebContents()); |
| 324 | 324 |
| 325 // We should have two entries. One corresponding to the page the user was | 325 // We should have two entries. One corresponding to the page the user was |
| 326 // first on, and one for the search page. | 326 // first on, and one for the search page. |
| 327 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); | 327 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); |
| 328 | 328 |
| 329 // Check that the value is reflected and onsubmit is called. | 329 // Check that the value is reflected and onsubmit is called. |
| 330 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", | 330 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", |
| 331 GetSearchStateAsString(preview_tab, true)); | 331 GetSearchStateAsString(preview_tab, true)); |
| 332 | 332 |
| 333 // Make sure the searchbox values were reset. | 333 // Make sure the searchbox values were reset. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 351 WebContents* preview_tab = preview()->web_contents(); | 351 WebContents* preview_tab = preview()->web_contents(); |
| 352 EXPECT_TRUE(preview_tab); | 352 EXPECT_TRUE(preview_tab); |
| 353 | 353 |
| 354 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 354 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 355 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 355 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 356 | 356 |
| 357 // Check that the preview has been committed. | 357 // Check that the preview has been committed. |
| 358 EXPECT_FALSE(preview()); | 358 EXPECT_FALSE(preview()); |
| 359 EXPECT_FALSE(instant()->is_displayable()); | 359 EXPECT_FALSE(instant()->is_displayable()); |
| 360 EXPECT_FALSE(instant()->IsCurrent()); | 360 EXPECT_FALSE(instant()->IsCurrent()); |
| 361 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents()); | 361 EXPECT_EQ(preview_tab, browser()->GetActiveWebContents()); |
| 362 | 362 |
| 363 // Check that the value is reflected and oncancel is called. | 363 // Check that the value is reflected and oncancel is called. |
| 364 EXPECT_EQ("true 0 1 1 true d false def false 3 3", | 364 EXPECT_EQ("true 0 1 1 true d false def false 3 3", |
| 365 GetSearchStateAsString(preview_tab, true)); | 365 GetSearchStateAsString(preview_tab, true)); |
| 366 | 366 |
| 367 // Make sure the searchbox values were reset. | 367 // Make sure the searchbox values were reset. |
| 368 EXPECT_EQ("true 0 1 1 true d false false 0 0", | 368 EXPECT_EQ("true 0 1 1 true d false false 0 0", |
| 369 GetSearchStateAsString(preview_tab, false)); | 369 GetSearchStateAsString(preview_tab, false)); |
| 370 } | 370 } |
| 371 | 371 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 std::string value; | 714 std::string value; |
| 715 ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(), | 715 ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(), |
| 716 "window.chrome.searchBox.value", &value)); | 716 "window.chrome.searchBox.value", &value)); |
| 717 EXPECT_EQ("def", value); | 717 EXPECT_EQ("def", value); |
| 718 | 718 |
| 719 // Commit the preview. | 719 // Commit the preview. |
| 720 ASSERT_TRUE(PressEnter()); | 720 ASSERT_TRUE(PressEnter()); |
| 721 EXPECT_FALSE(preview()); | 721 EXPECT_FALSE(preview()); |
| 722 | 722 |
| 723 // The searchBox actually gets cleared on commit. | 723 // The searchBox actually gets cleared on commit. |
| 724 ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedWebContents(), | 724 ASSERT_TRUE(GetStringFromJavascript(browser()->GetActiveWebContents(), |
| 725 "window.chrome.searchBox.value", &value)); | 725 "window.chrome.searchBox.value", &value)); |
| 726 EXPECT_EQ("", value); | 726 EXPECT_EQ("", value); |
| 727 | 727 |
| 728 // Navigate to a new URL. The searchBox values should stay cleared. | 728 // Navigate to a new URL. The searchBox values should stay cleared. |
| 729 ui_test_utils::NavigateToURL( | 729 ui_test_utils::NavigateToURL( |
| 730 browser(), test_server()->GetURL("files/empty.html")); | 730 browser(), test_server()->GetURL("files/empty.html")); |
| 731 | 731 |
| 732 ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedWebContents(), | 732 ASSERT_TRUE(GetStringFromJavascript(browser()->GetActiveWebContents(), |
| 733 "window.chrome.searchBox.value", &value)); | 733 "window.chrome.searchBox.value", &value)); |
| 734 EXPECT_EQ("", value); | 734 EXPECT_EQ("", value); |
| 735 } | 735 } |
| 736 | 736 |
| 737 // Tests that instant search is preloaded whenever the omnibox gets focus. | 737 // Tests that instant search is preloaded whenever the omnibox gets focus. |
| 738 // PreloadsInstant fails on linux_chromeos trybots all the time, possibly | 738 // PreloadsInstant fails on linux_chromeos trybots all the time, possibly |
| 739 // because of http://crbug.com/80118. | 739 // because of http://crbug.com/80118. |
| 740 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) | 740 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
| 741 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PreloadsInstant) { | 741 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PreloadsInstant) { |
| 742 #else | 742 #else |
| (...skipping 19 matching lines...) Expand all Loading... |
| 762 content::NotificationService::AllSources()); | 762 content::NotificationService::AllSources()); |
| 763 browser()->window()->GetLocationBar()->FocusLocation(false); | 763 browser()->window()->GetLocationBar()->FocusLocation(false); |
| 764 instant_support_observer.Wait(); | 764 instant_support_observer.Wait(); |
| 765 | 765 |
| 766 // Instant should have a preview, but not display it. | 766 // Instant should have a preview, but not display it. |
| 767 EXPECT_TRUE(preview()); | 767 EXPECT_TRUE(preview()); |
| 768 EXPECT_FALSE(instant()->is_displayable()); | 768 EXPECT_FALSE(instant()->is_displayable()); |
| 769 EXPECT_FALSE(instant()->IsCurrent()); | 769 EXPECT_FALSE(instant()->IsCurrent()); |
| 770 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false)); | 770 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false)); |
| 771 | 771 |
| 772 // Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper. | 772 // Adding a new tab shouldn't delete (or recreate) the TabContents. |
| 773 TabContentsWrapper* preview_tab = preview(); | 773 TabContents* preview_tab = preview(); |
| 774 AddBlankTabAndShow(browser()); | 774 AddBlankTabAndShow(browser()); |
| 775 EXPECT_EQ(preview_tab, preview()); | 775 EXPECT_EQ(preview_tab, preview()); |
| 776 | 776 |
| 777 // Doing a search should still use the same loader for the preview. | 777 // Doing a search should still use the same loader for the preview. |
| 778 SearchAndWaitForPreviewToShow(); | 778 SearchAndWaitForPreviewToShow(); |
| 779 EXPECT_EQ(preview_tab, preview()); | 779 EXPECT_EQ(preview_tab, preview()); |
| 780 | 780 |
| 781 // Verify that the preview is in fact showing instant search. | 781 // Verify that the preview is in fact showing instant search. |
| 782 EXPECT_TRUE(instant()->is_displayable()); | 782 EXPECT_TRUE(instant()->is_displayable()); |
| 783 EXPECT_TRUE(instant()->IsCurrent()); | 783 EXPECT_TRUE(instant()->IsCurrent()); |
| 784 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), true)); | 784 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), true)); |
| 785 } | 785 } |
| 786 | 786 |
| 787 // Tests that the instant search page's visibility is set correctly. | 787 // Tests that the instant search page's visibility is set correctly. |
| 788 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { | 788 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { |
| 789 ASSERT_TRUE(test_server()->Start()); | 789 ASSERT_TRUE(test_server()->Start()); |
| 790 EnableInstant(); | 790 EnableInstant(); |
| 791 SetupInstantProvider("instant.html"); | 791 SetupInstantProvider("instant.html"); |
| 792 | 792 |
| 793 // Initially navigate to the empty page which should be visible. | 793 // Initially navigate to the empty page which should be visible. |
| 794 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); | 794 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); |
| 795 WebContents* initial_contents = browser()->GetSelectedWebContents(); | 795 WebContents* initial_contents = browser()->GetActiveWebContents(); |
| 796 | 796 |
| 797 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); | 797 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
| 798 | 798 |
| 799 // Type a search term and wait for the preview to appear. | 799 // Type a search term and wait for the preview to appear. |
| 800 browser()->window()->GetLocationBar()->FocusLocation(false); | 800 browser()->window()->GetLocationBar()->FocusLocation(false); |
| 801 DetermineInstantSupport(); | 801 DetermineInstantSupport(); |
| 802 SearchAndWaitForPreviewToShow(); | 802 SearchAndWaitForPreviewToShow(); |
| 803 WebContents* preview_contents = preview()->web_contents(); | 803 WebContents* preview_contents = preview()->web_contents(); |
| 804 | 804 |
| 805 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 805 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
| 806 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); | 806 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
| 807 | 807 |
| 808 // Deleting the user text should hide the preview. | 808 // Deleting the user text should hide the preview. |
| 809 omnibox()->SetUserText(string16()); | 809 omnibox()->SetUserText(string16()); |
| 810 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); | 810 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); |
| 811 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); | 811 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
| 812 | 812 |
| 813 // Set the user text back and we should see the preview again. | 813 // Set the user text back and we should see the preview again. |
| 814 omnibox()->SetUserText(ASCIIToUTF16("def")); | 814 omnibox()->SetUserText(ASCIIToUTF16("def")); |
| 815 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 815 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
| 816 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); | 816 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
| 817 | 817 |
| 818 // Commit the preview. | 818 // Commit the preview. |
| 819 ASSERT_TRUE(PressEnter()); | 819 ASSERT_TRUE(PressEnter()); |
| 820 EXPECT_EQ(preview_contents, browser()->GetSelectedWebContents()); | 820 EXPECT_EQ(preview_contents, browser()->GetActiveWebContents()); |
| 821 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 821 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
| 822 } | 822 } |
| 823 | 823 |
| 824 // Tests that the task manager identifies instant's preview tab correctly. | 824 // Tests that the task manager identifies instant's preview tab correctly. |
| 825 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) { | 825 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) { |
| 826 // The browser starts with one new tab, so the task manager should have two | 826 // The browser starts with one new tab, so the task manager should have two |
| 827 // rows initially, one for the browser process and one for tab's renderer. | 827 // rows initially, one for the browser process and one for tab's renderer. |
| 828 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); | 828 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); |
| 829 task_manager->StartUpdating(); | 829 task_manager->StartUpdating(); |
| 830 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 830 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 831 | 831 |
| 832 ASSERT_TRUE(test_server()->Start()); | 832 ASSERT_TRUE(test_server()->Start()); |
| 833 EnableInstant(); | 833 EnableInstant(); |
| 834 SetupInstantProvider("instant.html"); | 834 SetupInstantProvider("instant.html"); |
| 835 DetermineInstantSupport(); | 835 DetermineInstantSupport(); |
| 836 SearchAndWaitForPreviewToShow(); | 836 SearchAndWaitForPreviewToShow(); |
| 837 | 837 |
| 838 // Now there should be three rows, the third being the instant preview. | 838 // Now there should be three rows, the third being the instant preview. |
| 839 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 839 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 840 string16 prefix = l10n_util::GetStringFUTF16( | 840 string16 prefix = l10n_util::GetStringFUTF16( |
| 841 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); | 841 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
| 842 string16 title = task_manager->GetResourceTitle(2); | 842 string16 title = task_manager->GetResourceTitle(2); |
| 843 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; | 843 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
| 844 } | 844 } |
| OLD | NEW |