| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 6 #include "base/stringprintf.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 8 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/instant/instant_controller.h" | 10 #include "chrome/browser/instant/instant_controller.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "chrome/test/test_navigation_observer.h" | 29 #include "chrome/test/test_navigation_observer.h" |
| 30 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
| 31 #include "content/browser/renderer_host/render_widget_host_view.h" | 31 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 32 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
| 33 #include "content/public/browser/notification_service.h" |
| 33 | 34 |
| 34 #define EXPECT_STR_EQ(ascii, utf16) \ | 35 #define EXPECT_STR_EQ(ascii, utf16) \ |
| 35 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 36 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
| 36 | 37 |
| 37 #if defined(OS_LINUX) | 38 #if defined(OS_LINUX) |
| 38 // These tests are disabled on linux because of http://crbug.com/80118 . | 39 // These tests are disabled on linux because of http://crbug.com/80118 . |
| 39 #define MAYBE_OnChangeEvent DISABLED_OnChangeEvent | 40 #define MAYBE_OnChangeEvent DISABLED_OnChangeEvent |
| 40 #define MAYBE_SetSuggestionsArrayOfStrings DISABLED_SetSuggestionsArrayOfStrings | 41 #define MAYBE_SetSuggestionsArrayOfStrings DISABLED_SetSuggestionsArrayOfStrings |
| 41 #define MAYBE_SetSuggestionsEmptyArray DISABLED_SetSuggestionsEmptyArray | 42 #define MAYBE_SetSuggestionsEmptyArray DISABLED_SetSuggestionsEmptyArray |
| 42 #define MAYBE_SetSuggestionsValidJson DISABLED_SetSuggestionsValidJson | 43 #define MAYBE_SetSuggestionsValidJson DISABLED_SetSuggestionsValidJson |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 InstantController::Enable(browser()->profile()); | 112 InstantController::Enable(browser()->profile()); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void SetupInstantProvider(const std::string& page) { | 115 void SetupInstantProvider(const std::string& page) { |
| 115 TemplateURLService* model = | 116 TemplateURLService* model = |
| 116 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 117 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
| 117 ASSERT_TRUE(model); | 118 ASSERT_TRUE(model); |
| 118 | 119 |
| 119 ui_test_utils::WindowedNotificationObserver service_loaded_observer( | 120 ui_test_utils::WindowedNotificationObserver service_loaded_observer( |
| 120 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 121 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 121 NotificationService::AllSources()); | 122 content::NotificationService::AllSources()); |
| 122 if (!model->loaded()) { | 123 if (!model->loaded()) { |
| 123 model->Load(); | 124 model->Load(); |
| 124 service_loaded_observer.Wait(); | 125 service_loaded_observer.Wait(); |
| 125 } | 126 } |
| 126 ASSERT_TRUE(model->loaded()); | 127 ASSERT_TRUE(model->loaded()); |
| 127 | 128 |
| 128 // TemplateURLService takes ownership of this. | 129 // TemplateURLService takes ownership of this. |
| 129 TemplateURL* template_url = new TemplateURL(); | 130 TemplateURL* template_url = new TemplateURL(); |
| 130 | 131 |
| 131 std::string url = StringPrintf( | 132 std::string url = StringPrintf( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // When the page loads, the initial searchBox values are set and only a | 185 // When the page loads, the initial searchBox values are set and only a |
| 185 // resize will have been sent. | 186 // resize will have been sent. |
| 186 ASSERT_EQ("true 0 0 0 true d false d false 1 1", | 187 ASSERT_EQ("true 0 0 0 true d false d false 1 1", |
| 187 GetSearchStateAsString(preview_, false)); | 188 GetSearchStateAsString(preview_, false)); |
| 188 } | 189 } |
| 189 | 190 |
| 190 void SetLocationBarText(const std::string& text) { | 191 void SetLocationBarText(const std::string& text) { |
| 191 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 192 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
| 192 ui_test_utils::WindowedNotificationObserver controller_shown_observer( | 193 ui_test_utils::WindowedNotificationObserver controller_shown_observer( |
| 193 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, | 194 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
| 194 NotificationService::AllSources()); | 195 content::NotificationService::AllSources()); |
| 195 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(text)); | 196 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(text)); |
| 196 controller_shown_observer.Wait(); | 197 controller_shown_observer.Wait(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 const string16& GetSuggestion() const { | 200 const string16& GetSuggestion() const { |
| 200 return browser()->instant()->loader_->complete_suggested_text_; | 201 return browser()->instant()->loader_->complete_suggested_text_; |
| 201 } | 202 } |
| 202 | 203 |
| 203 GURL GetCurrentURL() { | 204 GURL GetCurrentURL() { |
| 204 return browser()->instant()->loader_.get() ? | 205 return browser()->instant()->loader_.get() ? |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 // Makes sure that if the server doesn't support the instant API we don't show | 612 // Makes sure that if the server doesn't support the instant API we don't show |
| 612 // anything. | 613 // anything. |
| 613 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { | 614 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { |
| 614 ASSERT_TRUE(test_server()->Start()); | 615 ASSERT_TRUE(test_server()->Start()); |
| 615 EnableInstant(); | 616 EnableInstant(); |
| 616 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); | 617 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); |
| 617 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 618 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
| 618 | 619 |
| 619 ui_test_utils::WindowedNotificationObserver tab_closed_observer( | 620 ui_test_utils::WindowedNotificationObserver tab_closed_observer( |
| 620 content::NOTIFICATION_TAB_CLOSED, | 621 content::NOTIFICATION_TAB_CLOSED, |
| 621 NotificationService::AllSources()); | 622 content::NotificationService::AllSources()); |
| 622 | 623 |
| 623 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); | 624 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); |
| 624 ASSERT_TRUE(browser()->instant()); | 625 ASSERT_TRUE(browser()->instant()); |
| 625 // But because we're waiting to determine if the page really supports instant | 626 // But because we're waiting to determine if the page really supports instant |
| 626 // we shouldn't be showing the preview. | 627 // we shouldn't be showing the preview. |
| 627 EXPECT_FALSE(browser()->instant()->is_displayable()); | 628 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 628 // But instant should still be active. | 629 // But instant should still be active. |
| 629 EXPECT_TRUE(HasPreview()); | 630 EXPECT_TRUE(HasPreview()); |
| 630 | 631 |
| 631 // When the response comes back that the page doesn't support instant the tab | 632 // When the response comes back that the page doesn't support instant the tab |
| (...skipping 25 matching lines...) Expand all Loading... |
| 657 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); | 658 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); |
| 658 GURL url(test_server()->GetURL("files/instant/empty.html")); | 659 GURL url(test_server()->GetURL("files/instant/empty.html")); |
| 659 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 660 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
| 660 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); | 661 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
| 661 // The preview should not be showing or active. | 662 // The preview should not be showing or active. |
| 662 EXPECT_FALSE(browser()->instant()->is_displayable()); | 663 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 663 EXPECT_FALSE(HasPreview()); | 664 EXPECT_FALSE(HasPreview()); |
| 664 | 665 |
| 665 ui_test_utils::WindowedNotificationObserver tab_closed_observer( | 666 ui_test_utils::WindowedNotificationObserver tab_closed_observer( |
| 666 content::NOTIFICATION_TAB_CLOSED, | 667 content::NOTIFICATION_TAB_CLOSED, |
| 667 NotificationService::AllSources()); | 668 content::NotificationService::AllSources()); |
| 668 | 669 |
| 669 // Now type in some search text. | 670 // Now type in some search text. |
| 670 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); | 671 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); |
| 671 | 672 |
| 672 // Instant should be active. | 673 // Instant should be active. |
| 673 ASSERT_TRUE(HasPreview()); | 674 ASSERT_TRUE(HasPreview()); |
| 674 // Instant should not be current (it's still loading). | 675 // Instant should not be current (it's still loading). |
| 675 EXPECT_FALSE(browser()->instant()->IsCurrent()); | 676 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
| 676 | 677 |
| 677 // When the response comes back that the page doesn't support instant the tab | 678 // When the response comes back that the page doesn't support instant the tab |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 } | 806 } |
| 806 | 807 |
| 807 // Make sure the renderer doesn't crash if javascript is blocked. | 808 // Make sure the renderer doesn't crash if javascript is blocked. |
| 808 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontCrashOnBlockedJS) { | 809 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_DontCrashOnBlockedJS) { |
| 809 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 810 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 810 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 811 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| 811 ASSERT_TRUE(test_server()->Start()); | 812 ASSERT_TRUE(test_server()->Start()); |
| 812 | 813 |
| 813 ui_test_utils::WindowedNotificationObserver instant_support_observer( | 814 ui_test_utils::WindowedNotificationObserver instant_support_observer( |
| 814 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 815 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 815 NotificationService::AllSources()); | 816 content::NotificationService::AllSources()); |
| 816 | 817 |
| 817 EnableInstant(); | 818 EnableInstant(); |
| 818 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 819 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
| 819 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 820 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
| 820 // Wait for notification that the instant API has been determined. | 821 // Wait for notification that the instant API has been determined. |
| 821 instant_support_observer.Wait(); | 822 instant_support_observer.Wait(); |
| 822 // As long as we get the notification we're good (the renderer didn't crash). | 823 // As long as we get the notification we're good (the renderer didn't crash). |
| 823 } | 824 } |
| 824 | 825 |
| 825 // Makes sure window.chrome.searchbox doesn't persist when a new page is loaded. | 826 // Makes sure window.chrome.searchbox doesn't persist when a new page is loaded. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 EnableInstant(); | 868 EnableInstant(); |
| 868 SetupInstantProvider("search.html"); | 869 SetupInstantProvider("search.html"); |
| 869 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 870 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 870 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 871 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 871 | 872 |
| 872 // Verify that there is no previews contents. | 873 // Verify that there is no previews contents. |
| 873 EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents()); | 874 EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents()); |
| 874 | 875 |
| 875 ui_test_utils::WindowedNotificationObserver instant_support_observer( | 876 ui_test_utils::WindowedNotificationObserver instant_support_observer( |
| 876 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 877 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 877 NotificationService::AllSources()); | 878 content::NotificationService::AllSources()); |
| 878 | 879 |
| 879 // Focusing the omnibox should cause instant to be preloaded. | 880 // Focusing the omnibox should cause instant to be preloaded. |
| 880 FindLocationBar(); | 881 FindLocationBar(); |
| 881 location_bar_->FocusLocation(false); | 882 location_bar_->FocusLocation(false); |
| 882 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); | 883 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); |
| 883 EXPECT_TRUE(tab_contents); | 884 EXPECT_TRUE(tab_contents); |
| 884 | 885 |
| 885 instant_support_observer.Wait(); | 886 instant_support_observer.Wait(); |
| 886 | 887 |
| 887 // Instant should have a preview, but not display it. | 888 // Instant should have a preview, but not display it. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_ExperimentEnabled) { | 944 IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_ExperimentEnabled) { |
| 944 // Check that instant is enabled, despite not setting the preference. | 945 // Check that instant is enabled, despite not setting the preference. |
| 945 Profile* profile = browser()->profile(); | 946 Profile* profile = browser()->profile(); |
| 946 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); | 947 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); |
| 947 EXPECT_TRUE(InstantController::IsEnabled(profile)); | 948 EXPECT_TRUE(InstantController::IsEnabled(profile)); |
| 948 | 949 |
| 949 ASSERT_TRUE(test_server()->Start()); | 950 ASSERT_TRUE(test_server()->Start()); |
| 950 SetupInstantProvider("search.html"); | 951 SetupInstantProvider("search.html"); |
| 951 ui_test_utils::WindowedNotificationObserver instant_support_observer( | 952 ui_test_utils::WindowedNotificationObserver instant_support_observer( |
| 952 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 953 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 953 NotificationService::AllSources()); | 954 content::NotificationService::AllSources()); |
| 954 SetupLocationBar(); | 955 SetupLocationBar(); |
| 955 WaitForPreviewToNavigate(); | 956 WaitForPreviewToNavigate(); |
| 956 instant_support_observer.Wait(); | 957 instant_support_observer.Wait(); |
| 957 | 958 |
| 958 // Type into the omnibox, but don't press <Enter> yet. | 959 // Type into the omnibox, but don't press <Enter> yet. |
| 959 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def")); | 960 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def")); |
| 960 | 961 |
| 961 // Check that instant is active, but the preview is not showing. | 962 // Check that instant is active, but the preview is not showing. |
| 962 EXPECT_TRUE(HasPreview()); | 963 EXPECT_TRUE(HasPreview()); |
| 963 EXPECT_FALSE(browser()->instant()->is_displayable()); | 964 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 975 EXPECT_FALSE(browser()->instant()->is_displayable()); | 976 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 976 EXPECT_FALSE(browser()->instant()->IsCurrent()); | 977 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
| 977 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper()); | 978 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper()); |
| 978 } | 979 } |
| 979 | 980 |
| 980 // Tests the SearchToNonSearch scenario under the HIDDEN field trial. | 981 // Tests the SearchToNonSearch scenario under the HIDDEN field trial. |
| 981 IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_SearchToNonSearch) { | 982 IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_SearchToNonSearch) { |
| 982 ASSERT_TRUE(test_server()->Start()); | 983 ASSERT_TRUE(test_server()->Start()); |
| 983 ui_test_utils::WindowedNotificationObserver instant_support_observer( | 984 ui_test_utils::WindowedNotificationObserver instant_support_observer( |
| 984 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 985 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 985 NotificationService::AllSources()); | 986 content::NotificationService::AllSources()); |
| 986 | 987 |
| 987 // Type in some search text. | 988 // Type in some search text. |
| 988 SetupInstantProvider("search.html"); | 989 SetupInstantProvider("search.html"); |
| 989 SetupLocationBar(); | 990 SetupLocationBar(); |
| 990 | 991 |
| 991 // Load a non-search URL; don't wait for the preview to navigate. | 992 // Load a non-search URL; don't wait for the preview to navigate. |
| 992 GURL url(test_server()->GetURL("files/instant/empty.html")); | 993 GURL url(test_server()->GetURL("files/instant/empty.html")); |
| 993 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); | 994 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
| 994 | 995 |
| 995 // Wait for the preview to navigate. | 996 // Wait for the preview to navigate. |
| 996 WaitForPreviewToNavigate(); | 997 WaitForPreviewToNavigate(); |
| 997 instant_support_observer.Wait(); | 998 instant_support_observer.Wait(); |
| 998 | 999 |
| 999 // Instant should be active, but not displayable or committable. | 1000 // Instant should be active, but not displayable or committable. |
| 1000 EXPECT_TRUE(HasPreview()); | 1001 EXPECT_TRUE(HasPreview()); |
| 1001 EXPECT_FALSE(browser()->instant()->is_displayable()); | 1002 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 1002 EXPECT_FALSE(browser()->instant()->PrepareForCommit()); | 1003 EXPECT_FALSE(browser()->instant()->PrepareForCommit()); |
| 1003 } | 1004 } |
| OLD | NEW |