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

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

Issue 9015022: Replace most of Browser::GetSelectedTabContents calls into Browser::GetSelectedWebContents. I've ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 | « chrome/browser/gpu_pixel_browsertest.cc ('k') | chrome/browser/magic_iframe_browsertest.cc » ('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/string_util.h" 6 #include "base/string_util.h"
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_edit.h" 9 #include "chrome/browser/autocomplete/autocomplete_edit.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 10 #include "chrome/browser/content_settings/host_content_settings_map.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/ui/omnibox/omnibox_view.h" 23 #include "chrome/browser/ui/omnibox/omnibox_view.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
25 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "chrome/test/base/in_process_browser_test.h" 29 #include "chrome/test/base/in_process_browser_test.h"
30 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
31 #include "content/browser/renderer_host/render_view_host.h" 31 #include "content/browser/renderer_host/render_view_host.h"
32 #include "content/browser/renderer_host/render_widget_host_view.h" 32 #include "content/browser/renderer_host/render_widget_host_view.h"
33 #include "content/browser/tab_contents/tab_contents.h" 33 #include "content/browser/tab_contents/navigation_controller.h"
34 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/web_contents.h"
35 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
37 38
39 using content::WebContents;
40
38 // Tests are flaky on Linux because of http://crbug.com/80118. 41 // Tests are flaky on Linux because of http://crbug.com/80118.
39 #if defined(OS_LINUX) 42 #if defined(OS_LINUX)
40 #define MAYBE(TestName) DISABLED_ ## TestName 43 #define MAYBE(TestName) DISABLED_ ## TestName
41 #else 44 #else
42 #define MAYBE(TestName) TestName 45 #define MAYBE(TestName) TestName
43 #endif 46 #endif
44 47
45 class InstantTest : public InProcessBrowserTest { 48 class InstantTest : public InProcessBrowserTest {
46 public: 49 public:
47 InstantTest() { 50 InstantTest() {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, 102 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN,
100 content::NotificationService::AllSources()); 103 content::NotificationService::AllSources());
101 omnibox()->SetUserText(ASCIIToUTF16("def")); 104 omnibox()->SetUserText(ASCIIToUTF16("def"));
102 observer.Wait(); 105 observer.Wait();
103 } 106 }
104 107
105 // Sends a message to the renderer and waits for the response to come back to 108 // Sends a message to the renderer and waits for the response to come back to
106 // the browser. Returns true on success. 109 // the browser. Returns true on success.
107 bool WaitForMessageToBeProcessedByRenderer() { 110 bool WaitForMessageToBeProcessedByRenderer() {
108 bool result = false; 111 bool result = false;
109 return GetBoolFromJavascript(preview()->tab_contents(), "true", &result) && 112 return GetBoolFromJavascript(preview()->web_contents(), "true", &result) &&
110 result; 113 result;
111 } 114 }
112 115
113 InstantController* instant() const { 116 InstantController* instant() const {
114 return browser()->instant(); 117 return browser()->instant();
115 } 118 }
116 119
117 OmniboxView* omnibox() const { 120 OmniboxView* omnibox() const {
118 return browser()->window()->GetLocationBar()->location_entry(); 121 return browser()->window()->GetLocationBar()->location_entry();
119 } 122 }
(...skipping 11 matching lines...) Expand all
131 } 134 }
132 135
133 bool PressEnter() { 136 bool PressEnter() {
134 return ui_test_utils::SendKeyPressSync( 137 return ui_test_utils::SendKeyPressSync(
135 browser(), ui::VKEY_RETURN, false, false, false, false); 138 browser(), ui::VKEY_RETURN, false, false, false, false);
136 } 139 }
137 140
138 bool SetSuggestionsJavascriptArgument(const std::string& argument) { 141 bool SetSuggestionsJavascriptArgument(const std::string& argument) {
139 std::wstring script = UTF8ToWide(base::StringPrintf( 142 std::wstring script = UTF8ToWide(base::StringPrintf(
140 "window.setSuggestionsArgument = %s;", argument.c_str())); 143 "window.setSuggestionsArgument = %s;", argument.c_str()));
141 RenderViewHost* rvh = preview()->tab_contents()->GetRenderViewHost(); 144 RenderViewHost* rvh = preview()->web_contents()->GetRenderViewHost();
142 return ui_test_utils::ExecuteJavaScript(rvh, std::wstring(), script); 145 return ui_test_utils::ExecuteJavaScript(rvh, std::wstring(), script);
143 } 146 }
144 147
145 std::wstring WrapScript(const std::string& script) { 148 std::wstring WrapScript(const std::string& script) {
146 return UTF8ToWide(base::StringPrintf( 149 return UTF8ToWide(base::StringPrintf(
147 "window.domAutomationController.send(%s)", script.c_str())); 150 "window.domAutomationController.send(%s)", script.c_str()));
148 } 151 }
149 152
150 bool GetStringFromJavascript(TabContents* tab, 153 bool GetStringFromJavascript(WebContents* tab,
151 const std::string& script, 154 const std::string& script,
152 std::string* result) { 155 std::string* result) {
153 return ui_test_utils::ExecuteJavaScriptAndExtractString( 156 return ui_test_utils::ExecuteJavaScriptAndExtractString(
154 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); 157 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result);
155 } 158 }
156 159
157 bool GetIntFromJavascript(TabContents* tab, 160 bool GetIntFromJavascript(WebContents* tab,
158 const std::string& script, 161 const std::string& script,
159 int* result) { 162 int* result) {
160 return ui_test_utils::ExecuteJavaScriptAndExtractInt( 163 return ui_test_utils::ExecuteJavaScriptAndExtractInt(
161 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); 164 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result);
162 } 165 }
163 166
164 bool GetBoolFromJavascript(TabContents* tab, 167 bool GetBoolFromJavascript(WebContents* tab,
165 const std::string& script, 168 const std::string& script,
166 bool* result) { 169 bool* result) {
167 return ui_test_utils::ExecuteJavaScriptAndExtractBool( 170 return ui_test_utils::ExecuteJavaScriptAndExtractBool(
168 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result); 171 tab->GetRenderViewHost(), std::wstring(), WrapScript(script), result);
169 } 172 }
170 173
171 bool CheckVisibilityIs(TabContents* tab, bool visible) { 174 bool CheckVisibilityIs(WebContents* tab, bool visible) {
172 bool hidden = visible; 175 bool hidden = visible;
173 return GetBoolFromJavascript(tab, "document.webkitHidden", &hidden) && 176 return GetBoolFromJavascript(tab, "document.webkitHidden", &hidden) &&
174 hidden != visible; 177 hidden != visible;
175 } 178 }
176 179
177 // Returns the state of the search box as a string. This consists of the 180 // Returns the state of the search box as a string. This consists of the
178 // following: 181 // following:
179 // window.chrome.sv 182 // window.chrome.sv
180 // window.onsubmitcalls 183 // window.onsubmitcalls
181 // window.oncancelcalls 184 // window.oncancelcalls
182 // window.onchangecalls 185 // window.onchangecalls
183 // 'true' if any window.onresize call has been sent, otherwise false. 186 // 'true' if any window.onresize call has been sent, otherwise false.
184 // window.beforeLoadSearchBox.value 187 // window.beforeLoadSearchBox.value
185 // window.beforeLoadSearchBox.verbatim 188 // window.beforeLoadSearchBox.verbatim
186 // window.chrome.searchBox.value 189 // window.chrome.searchBox.value
187 // window.chrome.searchBox.verbatim 190 // window.chrome.searchBox.verbatim
188 // window.chrome.searchBox.selectionStart 191 // window.chrome.searchBox.selectionStart
189 // window.chrome.searchBox.selectionEnd 192 // window.chrome.searchBox.selectionEnd
190 // If determining any of the values fails, the value is 'fail'. 193 // If determining any of the values fails, the value is 'fail'.
191 // 194 //
192 // If |use_last| is true, then the last searchBox values are used instead of 195 // If |use_last| is true, then the last searchBox values are used instead of
193 // the current. Set |use_last| to true when testing OnSubmit/OnCancel. 196 // the current. Set |use_last| to true when testing OnSubmit/OnCancel.
194 std::string GetSearchStateAsString(TabContents* tab, bool use_last) { 197 std::string GetSearchStateAsString(WebContents* tab, bool use_last) {
195 bool sv = false; 198 bool sv = false;
196 int onsubmitcalls = 0; 199 int onsubmitcalls = 0;
197 int oncancelcalls = 0; 200 int oncancelcalls = 0;
198 int onchangecalls = 0; 201 int onchangecalls = 0;
199 int onresizecalls = 0; 202 int onresizecalls = 0;
200 int selection_start = 0; 203 int selection_start = 0;
201 int selection_end = 0; 204 int selection_end = 0;
202 std::string before_load_value; 205 std::string before_load_value;
203 bool before_load_verbatim = false; 206 bool before_load_verbatim = false;
204 std::string value; 207 std::string value;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 TemplateURLServiceFactory::GetForProfile(browser()->profile())-> 281 TemplateURLServiceFactory::GetForProfile(browser()->profile())->
279 GetDefaultSearchProvider(); 282 GetDefaultSearchProvider();
280 EXPECT_TRUE(default_turl); 283 EXPECT_TRUE(default_turl);
281 EXPECT_TRUE(default_turl->url()); 284 EXPECT_TRUE(default_turl->url());
282 EXPECT_EQ(default_turl->url()->ReplaceSearchTerms( 285 EXPECT_EQ(default_turl->url()->ReplaceSearchTerms(
283 *default_turl, ASCIIToUTF16("defghi"), 0, string16()), 286 *default_turl, ASCIIToUTF16("defghi"), 0, string16()),
284 loader()->url().spec()); 287 loader()->url().spec());
285 288
286 // Check that the value is reflected and onchange is called. 289 // Check that the value is reflected and onchange is called.
287 EXPECT_EQ("true 0 0 1 true d false def false 3 3", 290 EXPECT_EQ("true 0 0 1 true d false def false 3 3",
288 GetSearchStateAsString(preview()->tab_contents(), false)); 291 GetSearchStateAsString(preview()->web_contents(), false));
289 } 292 }
290 293
291 // Verify that the onsubmit event is dispatched upon pressing <Enter>. 294 // Verify that the onsubmit event is dispatched upon pressing <Enter>.
292 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnSubmitEvent)) { 295 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnSubmitEvent)) {
293 ASSERT_TRUE(test_server()->Start()); 296 ASSERT_TRUE(test_server()->Start());
294 EnableInstant(); 297 EnableInstant();
295 SetupInstantProvider("instant.html"); 298 SetupInstantProvider("instant.html");
296 DetermineInstantSupport(); 299 DetermineInstantSupport();
297 SearchAndWaitForPreviewToShow(); 300 SearchAndWaitForPreviewToShow();
298 301
299 EXPECT_TRUE(preview()); 302 EXPECT_TRUE(preview());
300 EXPECT_TRUE(instant()->is_displayable()); 303 EXPECT_TRUE(instant()->is_displayable());
301 EXPECT_TRUE(instant()->IsCurrent()); 304 EXPECT_TRUE(instant()->IsCurrent());
302 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); 305 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
303 306
304 TabContents* preview_tab = preview()->tab_contents(); 307 WebContents* preview_tab = preview()->web_contents();
305 EXPECT_TRUE(preview_tab); 308 EXPECT_TRUE(preview_tab);
306 309
307 ASSERT_TRUE(PressEnter()); 310 ASSERT_TRUE(PressEnter());
308 311
309 // Check that the preview has been committed. 312 // Check that the preview has been committed.
310 EXPECT_FALSE(preview()); 313 EXPECT_FALSE(preview());
311 EXPECT_FALSE(instant()->is_displayable()); 314 EXPECT_FALSE(instant()->is_displayable());
312 EXPECT_FALSE(instant()->IsCurrent()); 315 EXPECT_FALSE(instant()->IsCurrent());
313 EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents()); 316 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents());
314 317
315 // We should have two entries. One corresponding to the page the user was 318 // We should have two entries. One corresponding to the page the user was
316 // first on, and one for the search page. 319 // first on, and one for the search page.
317 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); 320 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount());
318 321
319 // Check that the value is reflected and onsubmit is called. 322 // Check that the value is reflected and onsubmit is called.
320 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", 323 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3",
321 GetSearchStateAsString(preview_tab, true)); 324 GetSearchStateAsString(preview_tab, true));
322 325
323 // Make sure the searchbox values were reset. 326 // Make sure the searchbox values were reset.
324 EXPECT_EQ("true 1 0 1 true d false false 0 0", 327 EXPECT_EQ("true 1 0 1 true d false false 0 0",
325 GetSearchStateAsString(preview_tab, false)); 328 GetSearchStateAsString(preview_tab, false));
326 } 329 }
327 330
328 // Verify that the oncancel event is dispatched upon losing focus. 331 // Verify that the oncancel event is dispatched upon losing focus.
329 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnCancelEvent)) { 332 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(OnCancelEvent)) {
330 ASSERT_TRUE(test_server()->Start()); 333 ASSERT_TRUE(test_server()->Start());
331 EnableInstant(); 334 EnableInstant();
332 SetupInstantProvider("instant.html"); 335 SetupInstantProvider("instant.html");
333 DetermineInstantSupport(); 336 DetermineInstantSupport();
334 SearchAndWaitForPreviewToShow(); 337 SearchAndWaitForPreviewToShow();
335 338
336 EXPECT_TRUE(preview()); 339 EXPECT_TRUE(preview());
337 EXPECT_TRUE(instant()->is_displayable()); 340 EXPECT_TRUE(instant()->is_displayable());
338 EXPECT_TRUE(instant()->IsCurrent()); 341 EXPECT_TRUE(instant()->IsCurrent());
339 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); 342 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
340 343
341 TabContents* preview_tab = preview()->tab_contents(); 344 WebContents* preview_tab = preview()->web_contents();
342 EXPECT_TRUE(preview_tab); 345 EXPECT_TRUE(preview_tab);
343 346
344 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 347 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
345 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 348 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
346 349
347 // Check that the preview has been committed. 350 // Check that the preview has been committed.
348 EXPECT_FALSE(preview()); 351 EXPECT_FALSE(preview());
349 EXPECT_FALSE(instant()->is_displayable()); 352 EXPECT_FALSE(instant()->is_displayable());
350 EXPECT_FALSE(instant()->IsCurrent()); 353 EXPECT_FALSE(instant()->IsCurrent());
351 EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents()); 354 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents());
352 355
353 // Check that the value is reflected and oncancel is called. 356 // Check that the value is reflected and oncancel is called.
354 EXPECT_EQ("true 0 1 1 true d false def false 3 3", 357 EXPECT_EQ("true 0 1 1 true d false def false 3 3",
355 GetSearchStateAsString(preview_tab, true)); 358 GetSearchStateAsString(preview_tab, true));
356 359
357 // Make sure the searchbox values were reset. 360 // Make sure the searchbox values were reset.
358 EXPECT_EQ("true 0 1 1 true d false false 0 0", 361 EXPECT_EQ("true 0 1 1 true d false false 0 0",
359 GetSearchStateAsString(preview_tab, false)); 362 GetSearchStateAsString(preview_tab, false));
360 } 363 }
361 364
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // trigger an onchange ourselves. 562 // trigger an onchange ourselves.
560 SearchAndWaitForPreviewToShow(); 563 SearchAndWaitForPreviewToShow();
561 564
562 // We should now be showing the preview. 565 // We should now be showing the preview.
563 EXPECT_TRUE(preview()); 566 EXPECT_TRUE(preview());
564 EXPECT_TRUE(loader()->ready()); 567 EXPECT_TRUE(loader()->ready());
565 EXPECT_TRUE(instant()->is_displayable()); 568 EXPECT_TRUE(instant()->is_displayable());
566 EXPECT_TRUE(instant()->IsCurrent()); 569 EXPECT_TRUE(instant()->IsCurrent());
567 570
568 RenderWidgetHostView* rwhv = 571 RenderWidgetHostView* rwhv =
569 preview()->tab_contents()->GetRenderWidgetHostView(); 572 preview()->web_contents()->GetRenderWidgetHostView();
570 EXPECT_TRUE(rwhv); 573 EXPECT_TRUE(rwhv);
571 EXPECT_TRUE(rwhv->IsShowing()); 574 EXPECT_TRUE(rwhv->IsShowing());
572 } 575 }
573 576
574 // Transition from search to non-search and make sure instant isn't displayable. 577 // Transition from search to non-search and make sure instant isn't displayable.
575 // See bug http://crbug.com/100368 for details. 578 // See bug http://crbug.com/100368 for details.
576 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) { 579 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) {
577 ASSERT_TRUE(test_server()->Start()); 580 ASSERT_TRUE(test_server()->Start());
578 EnableInstant(); 581 EnableInstant();
579 SetupInstantProvider("instant.html"); 582 SetupInstantProvider("instant.html");
(...skipping 14 matching lines...) Expand all
594 597
595 // We should now have a preview, but it shouldn't be showing yet. 598 // We should now have a preview, but it shouldn't be showing yet.
596 EXPECT_TRUE(preview()); 599 EXPECT_TRUE(preview());
597 EXPECT_FALSE(loader()->ready()); 600 EXPECT_FALSE(loader()->ready());
598 EXPECT_FALSE(instant()->is_displayable()); 601 EXPECT_FALSE(instant()->is_displayable());
599 EXPECT_FALSE(instant()->IsCurrent()); 602 EXPECT_FALSE(instant()->IsCurrent());
600 603
601 // Send onchange so that the page sends up suggestions. See the comments in 604 // Send onchange so that the page sends up suggestions. See the comments in
602 // NonSearchToSearch for why this is needed. 605 // NonSearchToSearch for why this is needed.
603 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 606 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
604 preview()->tab_contents()->GetRenderViewHost(), std::wstring(), 607 preview()->web_contents()->GetRenderViewHost(), std::wstring(),
605 L"window.chrome.searchBox.onchange();")); 608 L"window.chrome.searchBox.onchange();"));
606 ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer()); 609 ASSERT_TRUE(WaitForMessageToBeProcessedByRenderer());
607 610
608 // Instant should be active, but not displaying. 611 // Instant should be active, but not displaying.
609 EXPECT_TRUE(preview()); 612 EXPECT_TRUE(preview());
610 EXPECT_TRUE(loader()->ready()); 613 EXPECT_TRUE(loader()->ready());
611 EXPECT_FALSE(instant()->is_displayable()); 614 EXPECT_FALSE(instant()->is_displayable());
612 EXPECT_FALSE(instant()->IsCurrent()); 615 EXPECT_FALSE(instant()->IsCurrent());
613 } 616 }
614 617
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ValidHeight)) { 666 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(ValidHeight)) {
664 ASSERT_TRUE(test_server()->Start()); 667 ASSERT_TRUE(test_server()->Start());
665 EnableInstant(); 668 EnableInstant();
666 SetupInstantProvider("instant.html"); 669 SetupInstantProvider("instant.html");
667 DetermineInstantSupport(); 670 DetermineInstantSupport();
668 SearchAndWaitForPreviewToShow(); 671 SearchAndWaitForPreviewToShow();
669 672
670 int height = -1; 673 int height = -1;
671 674
672 // searchBox height is not yet set during initial load. 675 // searchBox height is not yet set during initial load.
673 ASSERT_TRUE(GetIntFromJavascript(preview()->tab_contents(), 676 ASSERT_TRUE(GetIntFromJavascript(preview()->web_contents(),
674 "window.beforeLoadSearchBox.height", &height)); 677 "window.beforeLoadSearchBox.height", &height));
675 EXPECT_EQ(0, height); 678 EXPECT_EQ(0, height);
676 679
677 // searchBox height is available by the time the page loads. 680 // searchBox height is available by the time the page loads.
678 ASSERT_TRUE(GetIntFromJavascript(preview()->tab_contents(), 681 ASSERT_TRUE(GetIntFromJavascript(preview()->web_contents(),
679 "window.chrome.searchBox.height", &height)); 682 "window.chrome.searchBox.height", &height));
680 EXPECT_GT(height, 0); 683 EXPECT_GT(height, 0);
681 } 684 }
682 685
683 // Make sure the renderer doesn't crash if javascript is blocked. 686 // Make sure the renderer doesn't crash if javascript is blocked.
684 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontCrashOnBlockedJS)) { 687 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontCrashOnBlockedJS)) {
685 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 688 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
686 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 689 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
687 ASSERT_TRUE(test_server()->Start()); 690 ASSERT_TRUE(test_server()->Start());
688 EnableInstant(); 691 EnableInstant();
689 SetupInstantProvider("instant.html"); 692 SetupInstantProvider("instant.html");
690 693
691 // Wait for notification that the instant API has been determined. As long as 694 // Wait for notification that the instant API has been determined. As long as
692 // we get the notification we're good (the renderer didn't crash). 695 // we get the notification we're good (the renderer didn't crash).
693 DetermineInstantSupport(); 696 DetermineInstantSupport();
694 } 697 }
695 698
696 // Makes sure window.chrome.searchbox doesn't persist when a new page is loaded. 699 // Makes sure window.chrome.searchbox doesn't persist when a new page is loaded.
697 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontPersistSearchbox)) { 700 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(DontPersistSearchbox)) {
698 ASSERT_TRUE(test_server()->Start()); 701 ASSERT_TRUE(test_server()->Start());
699 EnableInstant(); 702 EnableInstant();
700 SetupInstantProvider("instant.html"); 703 SetupInstantProvider("instant.html");
701 DetermineInstantSupport(); 704 DetermineInstantSupport();
702 SearchAndWaitForPreviewToShow(); 705 SearchAndWaitForPreviewToShow();
703 706
704 std::string value; 707 std::string value;
705 ASSERT_TRUE(GetStringFromJavascript(preview()->tab_contents(), 708 ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(),
706 "window.chrome.searchBox.value", &value)); 709 "window.chrome.searchBox.value", &value));
707 EXPECT_EQ("def", value); 710 EXPECT_EQ("def", value);
708 711
709 // Commit the preview. 712 // Commit the preview.
710 ASSERT_TRUE(PressEnter()); 713 ASSERT_TRUE(PressEnter());
711 EXPECT_FALSE(preview()); 714 EXPECT_FALSE(preview());
712 715
713 // The searchBox actually gets cleared on commit. 716 // The searchBox actually gets cleared on commit.
714 ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedTabContents(), 717 ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedWebContents(),
715 "window.chrome.searchBox.value", &value)); 718 "window.chrome.searchBox.value", &value));
716 EXPECT_EQ("", value); 719 EXPECT_EQ("", value);
717 720
718 // Navigate to a new URL. The searchBox values should stay cleared. 721 // Navigate to a new URL. The searchBox values should stay cleared.
719 ui_test_utils::NavigateToURL( 722 ui_test_utils::NavigateToURL(
720 browser(), test_server()->GetURL("files/empty.html")); 723 browser(), test_server()->GetURL("files/empty.html"));
721 724
722 ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedTabContents(), 725 ASSERT_TRUE(GetStringFromJavascript(browser()->GetSelectedWebContents(),
723 "window.chrome.searchBox.value", &value)); 726 "window.chrome.searchBox.value", &value));
724 EXPECT_EQ("", value); 727 EXPECT_EQ("", value);
725 } 728 }
726 729
727 // Tests that instant search is preloaded whenever the omnibox gets focus. 730 // Tests that instant search is preloaded whenever the omnibox gets focus.
728 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PreloadsInstant)) { 731 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PreloadsInstant)) {
729 CommandLine::ForCurrentProcess()->AppendSwitch( 732 CommandLine::ForCurrentProcess()->AppendSwitch(
730 switches::kPreloadInstantSearch); 733 switches::kPreloadInstantSearch);
731 ASSERT_TRUE(test_server()->Start()); 734 ASSERT_TRUE(test_server()->Start());
732 EnableInstant(); 735 EnableInstant();
(...skipping 13 matching lines...) Expand all
746 ui_test_utils::WindowedNotificationObserver instant_support_observer( 749 ui_test_utils::WindowedNotificationObserver instant_support_observer(
747 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, 750 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
748 content::NotificationService::AllSources()); 751 content::NotificationService::AllSources());
749 browser()->window()->GetLocationBar()->FocusLocation(false); 752 browser()->window()->GetLocationBar()->FocusLocation(false);
750 instant_support_observer.Wait(); 753 instant_support_observer.Wait();
751 754
752 // Instant should have a preview, but not display it. 755 // Instant should have a preview, but not display it.
753 EXPECT_TRUE(preview()); 756 EXPECT_TRUE(preview());
754 EXPECT_FALSE(instant()->is_displayable()); 757 EXPECT_FALSE(instant()->is_displayable());
755 EXPECT_FALSE(instant()->IsCurrent()); 758 EXPECT_FALSE(instant()->IsCurrent());
756 ASSERT_TRUE(CheckVisibilityIs(preview()->tab_contents(), false)); 759 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false));
757 760
758 // Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper. 761 // Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper.
759 TabContentsWrapper* preview_tab = preview(); 762 TabContentsWrapper* preview_tab = preview();
760 AddBlankTabAndShow(browser()); 763 AddBlankTabAndShow(browser());
761 EXPECT_EQ(preview_tab, preview()); 764 EXPECT_EQ(preview_tab, preview());
762 765
763 // Doing a search should still use the same loader for the preview. 766 // Doing a search should still use the same loader for the preview.
764 SearchAndWaitForPreviewToShow(); 767 SearchAndWaitForPreviewToShow();
765 EXPECT_EQ(preview_tab, preview()); 768 EXPECT_EQ(preview_tab, preview());
766 769
767 // Verify that the preview is in fact showing instant search. 770 // Verify that the preview is in fact showing instant search.
768 EXPECT_TRUE(instant()->is_displayable()); 771 EXPECT_TRUE(instant()->is_displayable());
769 EXPECT_TRUE(instant()->IsCurrent()); 772 EXPECT_TRUE(instant()->IsCurrent());
770 ASSERT_TRUE(CheckVisibilityIs(preview()->tab_contents(), true)); 773 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), true));
771 } 774 }
772 775
773 // Tests that the instant search page's visibility is set correctly. 776 // Tests that the instant search page's visibility is set correctly.
774 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { 777 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) {
775 ASSERT_TRUE(test_server()->Start()); 778 ASSERT_TRUE(test_server()->Start());
776 EnableInstant(); 779 EnableInstant();
777 SetupInstantProvider("instant.html"); 780 SetupInstantProvider("instant.html");
778 781
779 // Initially navigate to the empty page which should be visible. 782 // Initially navigate to the empty page which should be visible.
780 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); 783 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(""));
781 TabContents* initial_contents = browser()->GetSelectedTabContents(); 784 WebContents* initial_contents = browser()->GetSelectedWebContents();
782 785
783 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); 786 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true));
784 787
785 // Type a search term and wait for the preview to appear. 788 // Type a search term and wait for the preview to appear.
786 browser()->window()->GetLocationBar()->FocusLocation(false); 789 browser()->window()->GetLocationBar()->FocusLocation(false);
787 DetermineInstantSupport(); 790 DetermineInstantSupport();
788 SearchAndWaitForPreviewToShow(); 791 SearchAndWaitForPreviewToShow();
789 TabContents* preview_contents = preview()->tab_contents(); 792 WebContents* preview_contents = preview()->web_contents();
790 793
791 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); 794 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
792 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); 795 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false));
793 796
794 // Deleting the user text should hide the preview. 797 // Deleting the user text should hide the preview.
795 omnibox()->SetUserText(string16()); 798 omnibox()->SetUserText(string16());
796 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); 799 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false));
797 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); 800 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true));
798 801
799 // Set the user text back and we should see the preview again. 802 // Set the user text back and we should see the preview again.
800 omnibox()->SetUserText(ASCIIToUTF16("def")); 803 omnibox()->SetUserText(ASCIIToUTF16("def"));
801 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); 804 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
802 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); 805 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false));
803 806
804 // Commit the preview. 807 // Commit the preview.
805 ASSERT_TRUE(PressEnter()); 808 ASSERT_TRUE(PressEnter());
806 EXPECT_EQ(preview_contents, browser()->GetSelectedTabContents()); 809 EXPECT_EQ(preview_contents, browser()->GetSelectedWebContents());
807 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); 810 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true));
808 } 811 }
809 812
810 // Tests that the task manager identifies instant's preview tab correctly. 813 // Tests that the task manager identifies instant's preview tab correctly.
811 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) { 814 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) {
812 // The browser starts with one new tab, so the task manager should have two 815 // The browser starts with one new tab, so the task manager should have two
813 // rows initially, one for the browser process and one for tab's renderer. 816 // rows initially, one for the browser process and one for tab's renderer.
814 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); 817 TaskManagerModel* task_manager = TaskManager::GetInstance()->model();
815 task_manager->StartUpdating(); 818 task_manager->StartUpdating();
816 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 819 TaskManagerBrowserTestUtil::WaitForResourceChange(2);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 EXPECT_TRUE(preview()); 857 EXPECT_TRUE(preview());
855 EXPECT_TRUE(loader()->ready()); 858 EXPECT_TRUE(loader()->ready());
856 EXPECT_TRUE(instant()->is_displayable()); 859 EXPECT_TRUE(instant()->is_displayable());
857 EXPECT_TRUE(instant()->IsCurrent()); 860 EXPECT_TRUE(instant()->IsCurrent());
858 861
859 // Check that the suggested text has been set in the omnibox. 862 // Check that the suggested text has been set in the omnibox.
860 EXPECT_EQ("defghi", GetSuggestion()); 863 EXPECT_EQ("defghi", GetSuggestion());
861 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); 864 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
862 865
863 // Press <Enter> in the omnibox, causing the preview to be committed. 866 // Press <Enter> in the omnibox, causing the preview to be committed.
864 TabContents* preview_tab = preview()->tab_contents(); 867 WebContents* preview_tab = preview()->web_contents();
865 ASSERT_TRUE(PressEnter()); 868 ASSERT_TRUE(PressEnter());
866 869
867 // The preview contents should now be the active tab contents. 870 // The preview contents should now be the active tab contents.
868 EXPECT_FALSE(preview()); 871 EXPECT_FALSE(preview());
869 EXPECT_FALSE(instant()->is_displayable()); 872 EXPECT_FALSE(instant()->is_displayable());
870 EXPECT_FALSE(instant()->IsCurrent()); 873 EXPECT_FALSE(instant()->IsCurrent());
871 EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents()); 874 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents());
872 } 875 }
873 876
874 // Tests the HIDDEN experiment of the field trial. 877 // Tests the HIDDEN experiment of the field trial.
875 class InstantFieldTrialHiddenTest : public InstantTest { 878 class InstantFieldTrialHiddenTest : public InstantTest {
876 public: 879 public:
877 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 880 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
878 command_line->AppendSwitchASCII(switches::kInstantFieldTrial, 881 command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
879 switches::kInstantFieldTrialHidden); 882 switches::kInstantFieldTrialHidden);
880 } 883 }
881 }; 884 };
(...skipping 17 matching lines...) Expand all
899 EXPECT_TRUE(preview()); 902 EXPECT_TRUE(preview());
900 EXPECT_TRUE(loader()->ready()); 903 EXPECT_TRUE(loader()->ready());
901 EXPECT_FALSE(instant()->is_displayable()); 904 EXPECT_FALSE(instant()->is_displayable());
902 EXPECT_FALSE(instant()->IsCurrent()); 905 EXPECT_FALSE(instant()->IsCurrent());
903 906
904 // Check that the suggested text hasn't actually been set in the omnibox. 907 // Check that the suggested text hasn't actually been set in the omnibox.
905 EXPECT_EQ("defghi", GetSuggestion()); 908 EXPECT_EQ("defghi", GetSuggestion());
906 EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); 909 EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText()));
907 910
908 // Press <Enter> in the omnibox, causing the preview to be committed. 911 // Press <Enter> in the omnibox, causing the preview to be committed.
909 TabContents* preview_tab = preview()->tab_contents(); 912 WebContents* preview_tab = preview()->web_contents();
910 ASSERT_TRUE(PressEnter()); 913 ASSERT_TRUE(PressEnter());
911 914
912 // The preview contents should now be the active tab contents. 915 // The preview contents should now be the active tab contents.
913 EXPECT_FALSE(preview()); 916 EXPECT_FALSE(preview());
914 EXPECT_FALSE(instant()->is_displayable()); 917 EXPECT_FALSE(instant()->is_displayable());
915 EXPECT_FALSE(instant()->IsCurrent()); 918 EXPECT_FALSE(instant()->IsCurrent());
916 EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents()); 919 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents());
917 } 920 }
918 921
919 // Tests the SILENT experiment of the field trial. 922 // Tests the SILENT experiment of the field trial.
920 class InstantFieldTrialSilentTest : public InstantTest { 923 class InstantFieldTrialSilentTest : public InstantTest {
921 public: 924 public:
922 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 925 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
923 command_line->AppendSwitchASCII(switches::kInstantFieldTrial, 926 command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
924 switches::kInstantFieldTrialSilent); 927 switches::kInstantFieldTrialSilent);
925 } 928 }
926 }; 929 };
(...skipping 17 matching lines...) Expand all
944 EXPECT_TRUE(preview()); 947 EXPECT_TRUE(preview());
945 EXPECT_FALSE(loader()->ready()); 948 EXPECT_FALSE(loader()->ready());
946 EXPECT_FALSE(instant()->is_displayable()); 949 EXPECT_FALSE(instant()->is_displayable());
947 EXPECT_FALSE(instant()->IsCurrent()); 950 EXPECT_FALSE(instant()->IsCurrent());
948 951
949 // There are no suggestions, as the loader hasn't seen the query yet. 952 // There are no suggestions, as the loader hasn't seen the query yet.
950 EXPECT_EQ("", GetSuggestion()); 953 EXPECT_EQ("", GetSuggestion());
951 EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText())); 954 EXPECT_EQ("def", UTF16ToUTF8(omnibox()->GetText()));
952 955
953 // Press <Enter> in the omnibox, causing the preview to be committed. 956 // Press <Enter> in the omnibox, causing the preview to be committed.
954 TabContents* preview_tab = preview()->tab_contents(); 957 WebContents* preview_tab = preview()->web_contents();
955 ASSERT_TRUE(PressEnter()); 958 ASSERT_TRUE(PressEnter());
956 959
957 // The preview contents should now be the active tab contents. 960 // The preview contents should now be the active tab contents.
958 EXPECT_FALSE(preview()); 961 EXPECT_FALSE(preview());
959 EXPECT_FALSE(instant()->is_displayable()); 962 EXPECT_FALSE(instant()->is_displayable());
960 EXPECT_FALSE(instant()->IsCurrent()); 963 EXPECT_FALSE(instant()->IsCurrent());
961 EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents()); 964 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents());
962 } 965 }
963 966
964 // Tests the SUGGEST experiment of the field trial. 967 // Tests the SUGGEST experiment of the field trial.
965 class InstantFieldTrialSuggestTest : public InstantTest { 968 class InstantFieldTrialSuggestTest : public InstantTest {
966 public: 969 public:
967 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 970 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
968 command_line->AppendSwitchASCII(switches::kInstantFieldTrial, 971 command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
969 switches::kInstantFieldTrialSuggest); 972 switches::kInstantFieldTrialSuggest);
970 } 973 }
971 }; 974 };
(...skipping 17 matching lines...) Expand all
989 EXPECT_TRUE(preview()); 992 EXPECT_TRUE(preview());
990 EXPECT_TRUE(loader()->ready()); 993 EXPECT_TRUE(loader()->ready());
991 EXPECT_FALSE(instant()->is_displayable()); 994 EXPECT_FALSE(instant()->is_displayable());
992 EXPECT_FALSE(instant()->IsCurrent()); 995 EXPECT_FALSE(instant()->IsCurrent());
993 996
994 // Check that the suggested text has actually been set in the omnibox. 997 // Check that the suggested text has actually been set in the omnibox.
995 EXPECT_EQ("defghi", GetSuggestion()); 998 EXPECT_EQ("defghi", GetSuggestion());
996 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText())); 999 EXPECT_EQ("defghi", UTF16ToUTF8(omnibox()->GetText()));
997 1000
998 // Press <Enter> in the omnibox, causing the preview to be committed. 1001 // Press <Enter> in the omnibox, causing the preview to be committed.
999 TabContents* preview_tab = preview()->tab_contents(); 1002 WebContents* preview_tab = preview()->web_contents();
1000 ASSERT_TRUE(PressEnter()); 1003 ASSERT_TRUE(PressEnter());
1001 1004
1002 // The preview contents should now be the active tab contents. 1005 // The preview contents should now be the active tab contents.
1003 EXPECT_FALSE(preview()); 1006 EXPECT_FALSE(preview());
1004 EXPECT_FALSE(instant()->is_displayable()); 1007 EXPECT_FALSE(instant()->is_displayable());
1005 EXPECT_FALSE(instant()->IsCurrent()); 1008 EXPECT_FALSE(instant()->IsCurrent());
1006 EXPECT_EQ(preview_tab, browser()->GetSelectedTabContents()); 1009 EXPECT_EQ(preview_tab, browser()->GetSelectedWebContents());
1007 } 1010 }
OLDNEW
« no previous file with comments | « chrome/browser/gpu_pixel_browsertest.cc ('k') | chrome/browser/magic_iframe_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698