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

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

Issue 5771001: Fixes bug where we would show an instant preview when we thought the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_view.h" 8 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
11 #include "chrome/browser/instant/instant_controller.h" 11 #include "chrome/browser/instant/instant_controller.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/renderer_host/render_view_host.h" 13 #include "chrome/browser/renderer_host/render_view_host.h"
14 #include "chrome/browser/renderer_host/render_widget_host_view.h"
14 #include "chrome/browser/search_engines/template_url.h" 15 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/search_engines/template_url_model.h" 16 #include "chrome/browser/search_engines/template_url_model.h"
16 #include "chrome/browser/tab_contents/tab_contents.h" 17 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/omnibox/location_bar.h" 19 #include "chrome/browser/ui/omnibox/location_bar.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/in_process_browser_test.h" 22 #include "chrome/test/in_process_browser_test.h"
22 #include "chrome/test/ui_test_utils.h" 23 #include "chrome/test/ui_test_utils.h"
23 24
(...skipping 27 matching lines...) Expand all
51 page.c_str()); 52 page.c_str());
52 template_url->SetURL(url, 0, 0); 53 template_url->SetURL(url, 0, 0);
53 template_url->SetInstantURL(url, 0, 0); 54 template_url->SetInstantURL(url, 0, 0);
54 template_url->set_keyword(UTF8ToWide("foo")); 55 template_url->set_keyword(UTF8ToWide("foo"));
55 template_url->set_short_name(UTF8ToWide("foo")); 56 template_url->set_short_name(UTF8ToWide("foo"));
56 57
57 model->Add(template_url); 58 model->Add(template_url);
58 model->SetDefaultSearchProvider(template_url); 59 model->SetDefaultSearchProvider(template_url);
59 } 60 }
60 61
62 virtual void FindLocationBar() {
63 if (location_bar_)
64 return;
65 location_bar_ = browser()->window()->GetLocationBar();
66 ASSERT_TRUE(location_bar_);
67 }
68
61 // Type a character to get instant to trigger. 69 // Type a character to get instant to trigger.
62 void SetupLocationBar() { 70 void SetupLocationBar() {
63 location_bar_ = browser()->window()->GetLocationBar(); 71 FindLocationBar();
64 ASSERT_TRUE(location_bar_);
65 location_bar_->location_entry()->SetUserText(L"a"); 72 location_bar_->location_entry()->SetUserText(L"a");
66 } 73 }
67 74
68 // Wait for instant to load and ensure it is in the state we expect. 75 // Wait for instant to load and ensure it is in the state we expect.
69 void SetupPreview() { 76 void SetupPreview() {
70 preview_ = browser()->instant()->GetPreviewContents()->tab_contents(); 77 preview_ = browser()->instant()->GetPreviewContents()->tab_contents();
71 ASSERT_TRUE(preview_); 78 ASSERT_TRUE(preview_);
72 ui_test_utils::WaitForNavigation(&preview_->controller()); 79 ui_test_utils::WaitForNavigation(&preview_->controller());
73 80
74 // Verify the initial setup of the search box. 81 // Verify the initial setup of the search box.
(...skipping 13 matching lines...) Expand all
88 0, "window.onchangecalls", preview_)); 95 0, "window.onchangecalls", preview_));
89 EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript( 96 EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
90 0, "window.onresizecalls", preview_)); 97 0, "window.onresizecalls", preview_));
91 EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript( 98 EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript(
92 "a", "window.chrome.searchBox.value", preview_)); 99 "a", "window.chrome.searchBox.value", preview_));
93 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript( 100 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
94 false, "window.chrome.searchBox.verbatim", preview_)); 101 false, "window.chrome.searchBox.verbatim", preview_));
95 } 102 }
96 103
97 void SetLocationBarText(const std::wstring& text) { 104 void SetLocationBarText(const std::wstring& text) {
98 ASSERT_TRUE(location_bar_); 105 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
99 location_bar_->location_entry()->SetUserText(text); 106 location_bar_->location_entry()->SetUserText(text);
100 ui_test_utils::WaitForNotification( 107 ui_test_utils::WaitForNotification(
101 NotificationType::INSTANT_CONTROLLER_SHOWN); 108 NotificationType::INSTANT_CONTROLLER_SHOWN);
102 } 109 }
103 110
104 void SendKey(app::KeyboardCode key) { 111 void SendKey(app::KeyboardCode key) {
105 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 112 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
106 browser(), key, false, false, false, false)); 113 browser(), key, false, false, false, false));
107 } 114 }
108 115
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 178
172 // Check that the value is reflected and onchange is called. 179 // Check that the value is reflected and onchange is called.
173 EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript( 180 EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript(
174 "abc", "window.chrome.searchBox.value", preview_)); 181 "abc", "window.chrome.searchBox.value", preview_));
175 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript( 182 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
176 false, "window.chrome.searchBox.verbatim", preview_)); 183 false, "window.chrome.searchBox.verbatim", preview_));
177 EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript( 184 EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
178 1, "window.onchangecalls", preview_)); 185 1, "window.onchangecalls", preview_));
179 } 186 }
180 187
188 // Makes sure that if the server doesn't support the instant API we don't show
189 // anything.
190 IN_PROC_BROWSER_TEST_F(InstantTest, SearchServerDoesntSupportInstant) {
191 ASSERT_TRUE(test_server()->Start());
192 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
193 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
194 location_bar_->location_entry()->SetUserText(L"a");
195 ASSERT_TRUE(browser()->instant());
196 // Because we typed in a search string we should think we're showing instant
197 // results.
198 EXPECT_TRUE(browser()->instant()->IsShowingInstant());
199 // But because we're waiting to determine if the page really supports instant
200 // we shouldn't be showing the preview.
201 EXPECT_FALSE(browser()->instant()->is_active());
202
203 // When the response comes back that the page doesn't support instant the tab
204 // should be closed.
205 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED);
206 EXPECT_FALSE(browser()->instant()->IsShowingInstant());
207 EXPECT_FALSE(browser()->instant()->is_active());
208 }
209
210 // Verifies transitioning from loading a non-search string to a search string
211 // with the provider not supporting instant works (meaning we don't display
212 // anything).
213 IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearchDoesntSupportInstant) {
214 ASSERT_TRUE(test_server()->Start());
215 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
216 GURL url(test_server()->GetURL("files/instant/empty.html"));
217 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec())));
218 // The preview should be active and showing.
219 ASSERT_TRUE(browser()->instant()->is_active());
220 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents();
221 ASSERT_TRUE(initial_tab);
222 RenderWidgetHostView* rwhv =
223 initial_tab->tab_contents()->GetRenderWidgetHostView();
224 ASSERT_TRUE(rwhv);
225 ASSERT_TRUE(rwhv->IsShowing());
226
227 // Now type in some search text.
228 location_bar_->location_entry()->SetUserText(L"a");
229
230 // Instant should still be live.
231 ASSERT_TRUE(browser()->instant()->is_active());
232 // Because we typed in a search string we should think we're showing instant
233 // results.
234 EXPECT_TRUE(browser()->instant()->MightSupportInstant());
235 // Instant should not be current (it's still loading).
236 EXPECT_FALSE(browser()->instant()->IsCurrent());
237
238 // When the response comes back that the page doesn't support instant the tab
239 // should be closed.
240 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED);
241 EXPECT_FALSE(browser()->instant()->IsShowingInstant());
242 EXPECT_FALSE(browser()->instant()->is_active());
243 }
244
181 // Verify that the onsubmit event is dispatched upon pressing enter. 245 // Verify that the onsubmit event is dispatched upon pressing enter.
182 // TODO(sky): Disabled, http://crbug.com/62940. 246 // TODO(sky): Disabled, http://crbug.com/62940.
183 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnSubmitEvent) { 247 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnSubmitEvent) {
184 ASSERT_TRUE(test_server()->Start()); 248 ASSERT_TRUE(test_server()->Start());
185 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); 249 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
186 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 250 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
187 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 251 ASSERT_NO_FATAL_FAILURE(SetupPreview());
188 252
189 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); 253 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
190 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN)); 254 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // Check that the value is reflected and oncancel is called. 294 // Check that the value is reflected and oncancel is called.
231 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript( 295 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
232 true, "window.chrome.sv", contents)); 296 true, "window.chrome.sv", contents));
233 EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript( 297 EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript(
234 "abc", "window.chrome.searchBox.value", contents)); 298 "abc", "window.chrome.searchBox.value", contents));
235 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript( 299 EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
236 false, "window.chrome.searchBox.verbatim", contents)); 300 false, "window.chrome.searchBox.verbatim", contents));
237 EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript( 301 EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
238 1, "window.oncancelcalls", contents)); 302 1, "window.oncancelcalls", contents));
239 } 303 }
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