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

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

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