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

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

Issue 6363001: Makes chrome pass down the length of text as the end of the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add support for selection_end and fix selectionStart Created 9 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 | « no previous file | chrome/browser/instant/instant_loader.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) 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"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void SetupPreview() { 98 void SetupPreview() {
99 // Wait for the preview to navigate. 99 // Wait for the preview to navigate.
100 WaitForPreviewToNavigate(true); 100 WaitForPreviewToNavigate(true);
101 101
102 ASSERT_TRUE(browser()->instant()->IsShowingInstant()); 102 ASSERT_TRUE(browser()->instant()->IsShowingInstant());
103 ASSERT_FALSE(browser()->instant()->is_displayable()); 103 ASSERT_FALSE(browser()->instant()->is_displayable());
104 ASSERT_TRUE(browser()->instant()->is_active()); 104 ASSERT_TRUE(browser()->instant()->is_active());
105 105
106 // When the page loads, the initial searchBox values are set and only a 106 // When the page loads, the initial searchBox values are set and only a
107 // resize will have been sent. 107 // resize will have been sent.
108 ASSERT_EQ("true 0 0 0 1 a false a false", 108 ASSERT_EQ("true 0 0 0 1 a false a false 1 1",
109 GetSearchStateAsString(preview_)); 109 GetSearchStateAsString(preview_));
110 } 110 }
111 111
112 void SetLocationBarText(const std::wstring& text) { 112 void SetLocationBarText(const std::wstring& text) {
113 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); 113 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
114 location_bar_->location_entry()->SetUserText(text); 114 location_bar_->location_entry()->SetUserText(text);
115 ui_test_utils::WaitForNotification( 115 ui_test_utils::WaitForNotification(
116 NotificationType::INSTANT_CONTROLLER_SHOWN); 116 NotificationType::INSTANT_CONTROLLER_SHOWN);
117 } 117 }
118 118
119 const string16& GetSuggestion() const { 119 const string16& GetSuggestion() const {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // following: 170 // following:
171 // window.chrome.sv 171 // window.chrome.sv
172 // window.onsubmitcalls 172 // window.onsubmitcalls
173 // window.oncancelcalls 173 // window.oncancelcalls
174 // window.onchangecalls 174 // window.onchangecalls
175 // window.onresizecalls 175 // window.onresizecalls
176 // window.beforeLoadSearchBox.value 176 // window.beforeLoadSearchBox.value
177 // window.beforeLoadSearchBox.verbatim 177 // window.beforeLoadSearchBox.verbatim
178 // window.chrome.searchBox.value 178 // window.chrome.searchBox.value
179 // window.chrome.searchBox.verbatim 179 // window.chrome.searchBox.verbatim
180 // window.chrome.searchBox.selectionStart
181 // window.chrome.searchBox.selectionEnd
180 // If determining any of the values fails, the value is 'fail'. 182 // If determining any of the values fails, the value is 'fail'.
181 std::string GetSearchStateAsString(TabContents* tab_contents) { 183 std::string GetSearchStateAsString(TabContents* tab_contents) {
182 bool sv = false; 184 bool sv = false;
183 int onsubmitcalls = 0; 185 int onsubmitcalls = 0;
184 int oncancelcalls = 0; 186 int oncancelcalls = 0;
185 int onchangecalls = 0; 187 int onchangecalls = 0;
186 int onresizecalls = 0; 188 int onresizecalls = 0;
189 int selection_start = 0;
190 int selection_end = 0;
187 std::string before_load_value; 191 std::string before_load_value;
188 bool before_load_verbatim = false; 192 bool before_load_verbatim = false;
189 std::string value; 193 std::string value;
190 bool verbatim = false; 194 bool verbatim = false;
191 195
192 if (!GetBoolFromJavascript(tab_contents, "window.chrome.sv", &sv) || 196 if (!GetBoolFromJavascript(tab_contents, "window.chrome.sv", &sv) ||
193 !GetIntFromJavascript(tab_contents, "window.onsubmitcalls", 197 !GetIntFromJavascript(tab_contents, "window.onsubmitcalls",
194 &onsubmitcalls) || 198 &onsubmitcalls) ||
195 !GetIntFromJavascript(tab_contents, "window.oncancelcalls", 199 !GetIntFromJavascript(tab_contents, "window.oncancelcalls",
196 &oncancelcalls) || 200 &oncancelcalls) ||
197 !GetIntFromJavascript(tab_contents, "window.onchangecalls", 201 !GetIntFromJavascript(tab_contents, "window.onchangecalls",
198 &onchangecalls) || 202 &onchangecalls) ||
199 !GetIntFromJavascript(tab_contents, "window.onresizecalls", 203 !GetIntFromJavascript(tab_contents, "window.onresizecalls",
200 &onresizecalls) || 204 &onresizecalls) ||
201 !GetStringFromJavascript( 205 !GetStringFromJavascript(
202 tab_contents, "window.beforeLoadSearchBox.value", 206 tab_contents, "window.beforeLoadSearchBox.value",
203 &before_load_value) || 207 &before_load_value) ||
204 !GetBoolFromJavascript( 208 !GetBoolFromJavascript(
205 tab_contents, "window.beforeLoadSearchBox.verbatim", 209 tab_contents, "window.beforeLoadSearchBox.verbatim",
206 &before_load_verbatim) || 210 &before_load_verbatim) ||
207 !GetStringFromJavascript(tab_contents, "window.chrome.searchBox.value", 211 !GetStringFromJavascript(tab_contents, "window.chrome.searchBox.value",
208 &value) || 212 &value) ||
209 !GetBoolFromJavascript(tab_contents, "window.chrome.searchBox.verbatim", 213 !GetBoolFromJavascript(tab_contents, "window.chrome.searchBox.verbatim",
210 &verbatim)) { 214 &verbatim) ||
215 !GetIntFromJavascript(tab_contents,
216 "window.chrome.searchBox.selectionStart",
217 &selection_start) ||
218 !GetIntFromJavascript(tab_contents,
219 "window.chrome.searchBox.selectionEnd",
220 &selection_end)) {
211 return "fail"; 221 return "fail";
212 } 222 }
213 223
214 return StringPrintf("%s %d %d %d %d %s %s %s %s", 224 return StringPrintf("%s %d %d %d %d %s %s %s %s %d %d",
215 sv ? "true" : "false", 225 sv ? "true" : "false",
216 onsubmitcalls, 226 onsubmitcalls,
217 oncancelcalls, 227 oncancelcalls,
218 onchangecalls, 228 onchangecalls,
219 onresizecalls, 229 onresizecalls,
220 before_load_value.c_str(), 230 before_load_value.c_str(),
221 before_load_verbatim ? "true" : "false", 231 before_load_verbatim ? "true" : "false",
222 value.c_str(), 232 value.c_str(),
223 verbatim ? "true" : "false"); 233 verbatim ? "true" : "false",
234 selection_start,
235 selection_end);
224 } 236 }
225 237
226 void CheckStringValueFromJavascript( 238 void CheckStringValueFromJavascript(
227 const std::string& expected, 239 const std::string& expected,
228 const std::string& function, 240 const std::string& function,
229 TabContents* tab_contents) { 241 TabContents* tab_contents) {
230 std::string result; 242 std::string result;
231 ASSERT_TRUE(GetStringFromJavascript(tab_contents, function, &result)); 243 ASSERT_TRUE(GetStringFromJavascript(tab_contents, function, &result));
232 ASSERT_EQ(expected, result); 244 ASSERT_EQ(expected, result);
233 } 245 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Verify that the onchange event is dispatched upon typing in the box. 286 // Verify that the onchange event is dispatched upon typing in the box.
275 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { 287 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) {
276 ASSERT_TRUE(test_server()->Start()); 288 ASSERT_TRUE(test_server()->Start());
277 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); 289 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
278 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 290 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
279 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 291 ASSERT_NO_FATAL_FAILURE(SetupPreview());
280 292
281 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); 293 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
282 294
283 // Check that the value is reflected and onchange is called. 295 // Check that the value is reflected and onchange is called.
284 EXPECT_EQ("true 0 0 1 1 a false abc false", 296 EXPECT_EQ("true 0 0 1 1 a false abc false 3 3",
285 GetSearchStateAsString(preview_)); 297 GetSearchStateAsString(preview_));
286 } 298 }
287 299
288 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) { 300 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) {
289 ASSERT_TRUE(test_server()->Start()); 301 ASSERT_TRUE(test_server()->Start());
290 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); 302 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
291 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 303 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
292 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 304 ASSERT_NO_FATAL_FAILURE(SetupPreview());
293 305
294 SetSuggestionsJavascriptArgument(preview_, "['abcde', 'unused']"); 306 SetSuggestionsJavascriptArgument(preview_, "['abcde', 'unused']");
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); 594 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
583 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); 595 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN));
584 596
585 // Check that the preview contents have been committed. 597 // Check that the preview contents have been committed.
586 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); 598 ASSERT_FALSE(browser()->instant()->GetPreviewContents());
587 ASSERT_FALSE(browser()->instant()->is_active()); 599 ASSERT_FALSE(browser()->instant()->is_active());
588 TabContents* contents = browser()->GetSelectedTabContents(); 600 TabContents* contents = browser()->GetSelectedTabContents();
589 ASSERT_TRUE(contents); 601 ASSERT_TRUE(contents);
590 602
591 // Check that the value is reflected and onsubmit is called. 603 // Check that the value is reflected and onsubmit is called.
592 EXPECT_EQ("true 1 0 1 1 a false abc true", 604 EXPECT_EQ("true 1 0 1 1 a false abc true 3 3",
593 GetSearchStateAsString(preview_)); 605 GetSearchStateAsString(preview_));
594 } 606 }
595 607
596 // Verify that the oncancel event is dispatched upon losing focus. 608 // Verify that the oncancel event is dispatched upon losing focus.
597 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { 609 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) {
598 ASSERT_TRUE(test_server()->Start()); 610 ASSERT_TRUE(test_server()->Start());
599 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); 611 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
600 612
601 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 613 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
602 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 614 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
603 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 615 ASSERT_NO_FATAL_FAILURE(SetupPreview());
604 616
605 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); 617 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
606 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), 618 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
607 VIEW_ID_TAB_CONTAINER)); 619 VIEW_ID_TAB_CONTAINER));
608 620
609 // Check that the preview contents have been committed. 621 // Check that the preview contents have been committed.
610 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); 622 ASSERT_FALSE(browser()->instant()->GetPreviewContents());
611 ASSERT_FALSE(browser()->instant()->is_active()); 623 ASSERT_FALSE(browser()->instant()->is_active());
612 TabContents* contents = browser()->GetSelectedTabContents(); 624 TabContents* contents = browser()->GetSelectedTabContents();
613 ASSERT_TRUE(contents); 625 ASSERT_TRUE(contents);
614 626
615 // Check that the value is reflected and oncancel is called. 627 // Check that the value is reflected and oncancel is called.
616 EXPECT_EQ("true 0 1 1 1 a false abc false", 628 EXPECT_EQ("true 0 1 1 1 a false abc false 3 3",
617 GetSearchStateAsString(preview_)); 629 GetSearchStateAsString(preview_));
618 } 630 }
619 631
620 #if !defined(OS_MACOSX) 632 #if !defined(OS_MACOSX)
621 // Only passes on Mac. http://crbug.com/66850 633 // Only passes on Mac. http://crbug.com/66850
622 #define MAYBE_TabKey FAILS_TabKey 634 #define MAYBE_TabKey FAILS_TabKey
623 #else 635 #else
624 #define MAYBE_TabKey TabKey 636 #define MAYBE_TabKey TabKey
625 #endif 637 #endif
626 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { 638 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) {
627 ASSERT_TRUE(test_server()->Start()); 639 ASSERT_TRUE(test_server()->Start());
628 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); 640 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
629 641
630 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 642 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
631 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 643 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
632 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 644 ASSERT_NO_FATAL_FAILURE(SetupPreview());
633 645
634 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); 646 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
635 647
636 // Pressing tab to convert instant suggest into inline autocomplete. 648 // Pressing tab to convert instant suggest into inline autocomplete.
637 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); 649 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB));
638 650
639 ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText()); 651 ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText());
640 652
641 EXPECT_EQ("true 0 0 2 2 a false abcdef false", 653 EXPECT_EQ("true 0 0 2 2 a false abcdef false 6 6",
642 GetSearchStateAsString(preview_)); 654 GetSearchStateAsString(preview_));
643 655
644 // Pressing tab again to accept the current instant preview. 656 // Pressing tab again to accept the current instant preview.
645 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); 657 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB));
646 658
647 // Check that the preview contents have been committed. 659 // Check that the preview contents have been committed.
648 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); 660 ASSERT_FALSE(browser()->instant()->GetPreviewContents());
649 ASSERT_FALSE(browser()->instant()->is_active()); 661 ASSERT_FALSE(browser()->instant()->is_active());
650 TabContents* contents = browser()->GetSelectedTabContents(); 662 TabContents* contents = browser()->GetSelectedTabContents();
651 ASSERT_TRUE(contents); 663 ASSERT_TRUE(contents);
652 664
653 // Check that the value is reflected and onsubmit is called. 665 // Check that the value is reflected and onsubmit is called.
654 EXPECT_EQ("true 1 0 2 2 a false abcdef true", 666 EXPECT_EQ("true 1 0 2 2 a false abcdef true 6 6",
655 GetSearchStateAsString(preview_)); 667 GetSearchStateAsString(preview_));
656 } 668 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/instant/instant_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698