Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/instant/instant_browsertest.cc

Issue 8370020: Add a new field trial for Instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed @sky's comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/instant/instant_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 const string16& GetSuggestion() const { 202 const string16& GetSuggestion() const {
203 return browser()->instant()->loader_->complete_suggested_text_; 203 return browser()->instant()->loader_->complete_suggested_text_;
204 } 204 }
205 205
206 GURL GetCurrentURL() { 206 GURL GetCurrentURL() {
207 return browser()->instant()->loader_.get() ? 207 return browser()->instant()->loader_.get() ?
208 browser()->instant()->loader_.get()->url() : GURL(); 208 browser()->instant()->loader_.get()->url() : GURL();
209 } 209 }
210 210
211 bool LoaderIsReady() const {
212 return browser()->instant()->loader_->ready();
213 }
214
215 const string16& GetUserText() const {
216 return browser()->instant()->loader_->user_text();
217 }
218
211 void SendKey(ui::KeyboardCode key) { 219 void SendKey(ui::KeyboardCode key) {
212 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 220 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
213 browser(), key, false, false, false, false)); 221 browser(), key, false, false, false, false));
214 } 222 }
215 223
216 void SetSuggestionsJavascriptArgument(TabContents* tab_contents, 224 void SetSuggestionsJavascriptArgument(TabContents* tab_contents,
217 const std::string& argument) { 225 const std::string& argument) {
218 std::string script = StringPrintf( 226 std::string script = StringPrintf(
219 "window.setSuggestionsArgument = %s;", argument.c_str()); 227 "window.setSuggestionsArgument = %s;", argument.c_str());
220 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 228 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def")); 992 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def"));
985 993
986 // Check that instant is active, but the preview is not showing. 994 // Check that instant is active, but the preview is not showing.
987 EXPECT_TRUE(HasPreview()); 995 EXPECT_TRUE(HasPreview());
988 EXPECT_FALSE(browser()->instant()->is_displayable()); 996 EXPECT_FALSE(browser()->instant()->is_displayable());
989 EXPECT_FALSE(browser()->instant()->IsCurrent()); 997 EXPECT_FALSE(browser()->instant()->IsCurrent());
990 998
991 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); 999 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
992 EXPECT_TRUE(tab_contents); 1000 EXPECT_TRUE(tab_contents);
993 1001
1002 // Wait for the underlying loader to finish processing.
1003 WaitForMessageToBeProcessedByRenderer(tab_contents);
1004
1005 EXPECT_STR_EQ("def", location_bar_->location_entry()->GetText());
1006 EXPECT_STR_EQ("defghi", GetUserText());
1007 EXPECT_TRUE(LoaderIsReady());
1008
994 // Press <Enter> in the omnibox, causing the preview to be committed. 1009 // Press <Enter> in the omnibox, causing the preview to be committed.
995 SendKey(ui::VKEY_RETURN); 1010 SendKey(ui::VKEY_RETURN);
996 1011
1012 // The preview contents should now be the active tab contents.
1013 EXPECT_FALSE(browser()->instant()->GetPreviewContents());
1014 EXPECT_FALSE(HasPreview());
1015 EXPECT_FALSE(browser()->instant()->is_displayable());
1016 EXPECT_FALSE(browser()->instant()->IsCurrent());
1017 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper());
1018 }
1019
1020 // Tests the SILENT experiment of the field trial.
1021 class InstantFieldTrialSilentTest : public InstantTest {
1022 public:
1023 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1024 command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
1025 switches::kInstantFieldTrialSilent);
1026 }
1027 };
1028
1029 // Tests that instant is active, even without calling EnableInstant().
1030 IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE_ExperimentEnabled) {
1031 // Check that instant is enabled, despite not setting the preference.
1032 Profile* profile = browser()->profile();
1033 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled));
1034 EXPECT_TRUE(InstantController::IsEnabled(profile));
1035
1036 ASSERT_TRUE(test_server()->Start());
1037 SetupInstantProvider("search.html");
1038 ui_test_utils::WindowedNotificationObserver instant_support_observer(
1039 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
1040 content::NotificationService::AllSources());
1041 SetupLocationBar();
1042 WaitForPreviewToNavigate();
1043 instant_support_observer.Wait();
1044
1045 // Type into the omnibox, but don't press <Enter> yet.
1046 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def"));
1047
1048 // Check that instant is active, but the preview is not showing.
1049 EXPECT_TRUE(HasPreview());
1050 EXPECT_FALSE(browser()->instant()->is_displayable());
1051 EXPECT_FALSE(browser()->instant()->IsCurrent());
1052
1053 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
1054 EXPECT_TRUE(tab_contents);
1055
1056 // Wait for the underlying loader to finish processing.
1057 WaitForMessageToBeProcessedByRenderer(tab_contents);
1058
1059 EXPECT_STR_EQ("def", location_bar_->location_entry()->GetText());
1060 EXPECT_STR_EQ("", GetUserText());
1061 EXPECT_FALSE(LoaderIsReady());
1062
1063 // Press <Enter> in the omnibox, causing the preview to be committed.
1064 SendKey(ui::VKEY_RETURN);
1065
997 // The preview contents should now be the active tab contents. 1066 // The preview contents should now be the active tab contents.
998 EXPECT_FALSE(browser()->instant()->GetPreviewContents()); 1067 EXPECT_FALSE(browser()->instant()->GetPreviewContents());
999 EXPECT_FALSE(HasPreview()); 1068 EXPECT_FALSE(HasPreview());
1000 EXPECT_FALSE(browser()->instant()->is_displayable()); 1069 EXPECT_FALSE(browser()->instant()->is_displayable());
1001 EXPECT_FALSE(browser()->instant()->IsCurrent()); 1070 EXPECT_FALSE(browser()->instant()->IsCurrent());
1002 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper()); 1071 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper());
1003 } 1072 }
1004 1073
1005 // Tests the SearchToNonSearch scenario under the HIDDEN field trial. 1074 // Tests the SearchToNonSearch scenario under the SILENT field trial.
1006 IN_PROC_BROWSER_TEST_F(InstantFieldTrialHiddenTest, MAYBE_SearchToNonSearch) { 1075 IN_PROC_BROWSER_TEST_F(InstantFieldTrialSilentTest, MAYBE_SearchToNonSearch) {
1007 ASSERT_TRUE(test_server()->Start()); 1076 ASSERT_TRUE(test_server()->Start());
1008 ui_test_utils::WindowedNotificationObserver instant_support_observer( 1077 ui_test_utils::WindowedNotificationObserver instant_support_observer(
1009 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, 1078 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
1010 content::NotificationService::AllSources()); 1079 content::NotificationService::AllSources());
1011 1080
1012 // Type in some search text. 1081 // Type in some search text.
1013 SetupInstantProvider("search.html"); 1082 SetupInstantProvider("search.html");
1014 SetupLocationBar(); 1083 SetupLocationBar();
1015 1084
1016 // Load a non-search URL; don't wait for the preview to navigate. 1085 // Load a non-search URL; don't wait for the preview to navigate.
1017 GURL url(test_server()->GetURL("files/instant/empty.html")); 1086 GURL url(test_server()->GetURL("files/instant/empty.html"));
1018 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); 1087 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
1019 1088
1020 // Wait for the preview to navigate. 1089 // Wait for the preview to navigate.
1021 WaitForPreviewToNavigate(); 1090 WaitForPreviewToNavigate();
1022 instant_support_observer.Wait(); 1091 instant_support_observer.Wait();
1023 1092
1024 // Instant should be active, but not displayable or committable. 1093 // Instant should be active, but not displayable or committable.
1025 EXPECT_TRUE(HasPreview()); 1094 EXPECT_TRUE(HasPreview());
1026 EXPECT_FALSE(browser()->instant()->is_displayable()); 1095 EXPECT_FALSE(browser()->instant()->is_displayable());
1027 EXPECT_FALSE(browser()->instant()->PrepareForCommit()); 1096 EXPECT_FALSE(browser()->instant()->PrepareForCommit());
1028 } 1097 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/instant/instant_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698