| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 const string16& GetSuggestion() const { | 200 const string16& GetSuggestion() const { |
| 201 return browser()->instant()->loader_->complete_suggested_text_; | 201 return browser()->instant()->loader_->complete_suggested_text_; |
| 202 } | 202 } |
| 203 | 203 |
| 204 GURL GetCurrentURL() { | 204 GURL GetCurrentURL() { |
| 205 return browser()->instant()->loader_.get() ? | 205 return browser()->instant()->loader_.get() ? |
| 206 browser()->instant()->loader_.get()->url() : GURL(); | 206 browser()->instant()->loader_.get()->url() : GURL(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool LoaderIsReady() const { |
| 210 return browser()->instant()->loader_->ready(); |
| 211 } |
| 212 |
| 213 const string16& GetUserText() const { |
| 214 return browser()->instant()->loader_->user_text(); |
| 215 } |
| 216 |
| 209 void SendKey(ui::KeyboardCode key) { | 217 void SendKey(ui::KeyboardCode key) { |
| 210 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 218 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 211 browser(), key, false, false, false, false)); | 219 browser(), key, false, false, false, false)); |
| 212 } | 220 } |
| 213 | 221 |
| 214 void SetSuggestionsJavascriptArgument(TabContents* tab_contents, | 222 void SetSuggestionsJavascriptArgument(TabContents* tab_contents, |
| 215 const std::string& argument) { | 223 const std::string& argument) { |
| 216 std::string script = StringPrintf( | 224 std::string script = StringPrintf( |
| 217 "window.setSuggestionsArgument = %s;", argument.c_str()); | 225 "window.setSuggestionsArgument = %s;", argument.c_str()); |
| 218 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 226 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def")); | 968 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def")); |
| 961 | 969 |
| 962 // Check that instant is active, but the preview is not showing. | 970 // Check that instant is active, but the preview is not showing. |
| 963 EXPECT_TRUE(HasPreview()); | 971 EXPECT_TRUE(HasPreview()); |
| 964 EXPECT_FALSE(browser()->instant()->is_displayable()); | 972 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 965 EXPECT_FALSE(browser()->instant()->IsCurrent()); | 973 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
| 966 | 974 |
| 967 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); | 975 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); |
| 968 EXPECT_TRUE(tab_contents); | 976 EXPECT_TRUE(tab_contents); |
| 969 | 977 |
| 978 // Wait for the underlying loader to finish processing. |
| 979 WaitForMessageToBeProcessedByRenderer(tab_contents); |
| 980 |
| 981 EXPECT_STR_EQ("def", location_bar_->location_entry()->GetText()); |
| 982 EXPECT_STR_EQ("defghi", GetUserText()); |
| 983 EXPECT_TRUE(LoaderIsReady()); |
| 984 |
| 970 // Press <Enter> in the omnibox, causing the preview to be committed. | 985 // Press <Enter> in the omnibox, causing the preview to be committed. |
| 971 SendKey(ui::VKEY_RETURN); | 986 SendKey(ui::VKEY_RETURN); |
| 972 | 987 |
| 988 // The preview contents should now be the active tab contents. |
| 989 EXPECT_FALSE(browser()->instant()->GetPreviewContents()); |
| 990 EXPECT_FALSE(HasPreview()); |
| 991 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 992 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
| 993 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper()); |
| 994 } |
| 995 |
| 996 // Tests the SILENT experiment of the field trial. |
| 997 class InstantFieldTrialSilentTest : public InstantTest { |
| 998 public: |
| 999 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 1000 command_line->AppendSwitchASCII(switches::kInstantFieldTrial, |
| 1001 switches::kInstantFieldTrialSilent); |
| 1002 } |
| 1003 }; |
| 1004 |
| 1005 // Tests that instant is active, even without calling EnableInstant(). |
| 1006 IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE_ExperimentEnabled) { |
| 1007 // Check that instant is enabled, despite not setting the preference. |
| 1008 Profile* profile = browser()->profile(); |
| 1009 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); |
| 1010 EXPECT_TRUE(InstantController::IsEnabled(profile)); |
| 1011 |
| 1012 ASSERT_TRUE(test_server()->Start()); |
| 1013 SetupInstantProvider("search.html"); |
| 1014 ui_test_utils::WindowedNotificationObserver instant_support_observer( |
| 1015 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 1016 content::NotificationService::AllSources()); |
| 1017 SetupLocationBar(); |
| 1018 WaitForPreviewToNavigate(); |
| 1019 instant_support_observer.Wait(); |
| 1020 |
| 1021 // Type into the omnibox, but don't press <Enter> yet. |
| 1022 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def")); |
| 1023 |
| 1024 // Check that instant is active, but the preview is not showing. |
| 1025 EXPECT_TRUE(HasPreview()); |
| 1026 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 1027 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
| 1028 |
| 1029 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); |
| 1030 EXPECT_TRUE(tab_contents); |
| 1031 |
| 1032 // Wait for the underlying loader to finish processing. |
| 1033 WaitForMessageToBeProcessedByRenderer(tab_contents); |
| 1034 |
| 1035 EXPECT_STR_EQ("def", location_bar_->location_entry()->GetText()); |
| 1036 EXPECT_STR_EQ("", GetUserText()); |
| 1037 EXPECT_FALSE(LoaderIsReady()); |
| 1038 |
| 1039 // Press <Enter> in the omnibox, causing the preview to be committed. |
| 1040 SendKey(ui::VKEY_RETURN); |
| 1041 |
| 973 // The preview contents should now be the active tab contents. | 1042 // The preview contents should now be the active tab contents. |
| 974 EXPECT_FALSE(browser()->instant()->GetPreviewContents()); | 1043 EXPECT_FALSE(browser()->instant()->GetPreviewContents()); |
| 975 EXPECT_FALSE(HasPreview()); | 1044 EXPECT_FALSE(HasPreview()); |
| 976 EXPECT_FALSE(browser()->instant()->is_displayable()); | 1045 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 977 EXPECT_FALSE(browser()->instant()->IsCurrent()); | 1046 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
| 978 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper()); | 1047 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper()); |
| 979 } | 1048 } |
| 980 | 1049 |
| 981 // Tests the SearchToNonSearch scenario under the HIDDEN field trial. | 1050 // Tests the SearchToNonSearch scenario under the SILENT field trial. |
| 982 IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_SearchToNonSearch) { | 1051 IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE_SearchToNonSearch) { |
| 983 ASSERT_TRUE(test_server()->Start()); | 1052 ASSERT_TRUE(test_server()->Start()); |
| 984 ui_test_utils::WindowedNotificationObserver instant_support_observer( | 1053 ui_test_utils::WindowedNotificationObserver instant_support_observer( |
| 985 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 1054 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 986 content::NotificationService::AllSources()); | 1055 content::NotificationService::AllSources()); |
| 987 | 1056 |
| 988 // Type in some search text. | 1057 // Type in some search text. |
| 989 SetupInstantProvider("search.html"); | 1058 SetupInstantProvider("search.html"); |
| 990 SetupLocationBar(); | 1059 SetupLocationBar(); |
| 991 | 1060 |
| 992 // Load a non-search URL; don't wait for the preview to navigate. | 1061 // Load a non-search URL; don't wait for the preview to navigate. |
| 993 GURL url(test_server()->GetURL("files/instant/empty.html")); | 1062 GURL url(test_server()->GetURL("files/instant/empty.html")); |
| 994 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); | 1063 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
| 995 | 1064 |
| 996 // Wait for the preview to navigate. | 1065 // Wait for the preview to navigate. |
| 997 WaitForPreviewToNavigate(); | 1066 WaitForPreviewToNavigate(); |
| 998 instant_support_observer.Wait(); | 1067 instant_support_observer.Wait(); |
| 999 | 1068 |
| 1000 // Instant should be active, but not displayable or committable. | 1069 // Instant should be active, but not displayable or committable. |
| 1001 EXPECT_TRUE(HasPreview()); | 1070 EXPECT_TRUE(HasPreview()); |
| 1002 EXPECT_FALSE(browser()->instant()->is_displayable()); | 1071 EXPECT_FALSE(browser()->instant()->is_displayable()); |
| 1003 EXPECT_FALSE(browser()->instant()->PrepareForCommit()); | 1072 EXPECT_FALSE(browser()->instant()->PrepareForCommit()); |
| 1004 } | 1073 } |
| OLD | NEW |