OLD | NEW |
---|---|
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 Loading... | |
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", |
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 Loading... | |
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 | |
tonyg
2011/01/14 18:53:27
Optional: I recommend also testing selectionEnd (e
| |
180 // If determining any of the values fails, the value is 'fail'. | 181 // If determining any of the values fails, the value is 'fail'. |
181 std::string GetSearchStateAsString(TabContents* tab_contents) { | 182 std::string GetSearchStateAsString(TabContents* tab_contents) { |
182 bool sv = false; | 183 bool sv = false; |
183 int onsubmitcalls = 0; | 184 int onsubmitcalls = 0; |
184 int oncancelcalls = 0; | 185 int oncancelcalls = 0; |
185 int onchangecalls = 0; | 186 int onchangecalls = 0; |
186 int onresizecalls = 0; | 187 int onresizecalls = 0; |
188 int selection_start = 0; | |
187 std::string before_load_value; | 189 std::string before_load_value; |
188 bool before_load_verbatim = false; | 190 bool before_load_verbatim = false; |
189 std::string value; | 191 std::string value; |
190 bool verbatim = false; | 192 bool verbatim = false; |
191 | 193 |
192 if (!GetBoolFromJavascript(tab_contents, "window.chrome.sv", &sv) || | 194 if (!GetBoolFromJavascript(tab_contents, "window.chrome.sv", &sv) || |
193 !GetIntFromJavascript(tab_contents, "window.onsubmitcalls", | 195 !GetIntFromJavascript(tab_contents, "window.onsubmitcalls", |
194 &onsubmitcalls) || | 196 &onsubmitcalls) || |
195 !GetIntFromJavascript(tab_contents, "window.oncancelcalls", | 197 !GetIntFromJavascript(tab_contents, "window.oncancelcalls", |
196 &oncancelcalls) || | 198 &oncancelcalls) || |
197 !GetIntFromJavascript(tab_contents, "window.onchangecalls", | 199 !GetIntFromJavascript(tab_contents, "window.onchangecalls", |
198 &onchangecalls) || | 200 &onchangecalls) || |
199 !GetIntFromJavascript(tab_contents, "window.onresizecalls", | 201 !GetIntFromJavascript(tab_contents, "window.onresizecalls", |
200 &onresizecalls) || | 202 &onresizecalls) || |
201 !GetStringFromJavascript( | 203 !GetStringFromJavascript( |
202 tab_contents, "window.beforeLoadSearchBox.value", | 204 tab_contents, "window.beforeLoadSearchBox.value", |
203 &before_load_value) || | 205 &before_load_value) || |
204 !GetBoolFromJavascript( | 206 !GetBoolFromJavascript( |
205 tab_contents, "window.beforeLoadSearchBox.verbatim", | 207 tab_contents, "window.beforeLoadSearchBox.verbatim", |
206 &before_load_verbatim) || | 208 &before_load_verbatim) || |
207 !GetStringFromJavascript(tab_contents, "window.chrome.searchBox.value", | 209 !GetStringFromJavascript(tab_contents, "window.chrome.searchBox.value", |
208 &value) || | 210 &value) || |
209 !GetBoolFromJavascript(tab_contents, "window.chrome.searchBox.verbatim", | 211 !GetBoolFromJavascript(tab_contents, "window.chrome.searchBox.verbatim", |
210 &verbatim)) { | 212 &verbatim) || |
213 !GetIntFromJavascript(tab_contents, | |
214 "window.chrome.searchBox.selectionStart", | |
215 &selection_start)) { | |
211 return "fail"; | 216 return "fail"; |
212 } | 217 } |
213 | 218 |
214 return StringPrintf("%s %d %d %d %d %s %s %s %s", | 219 return StringPrintf("%s %d %d %d %d %s %s %s %s %d", |
215 sv ? "true" : "false", | 220 sv ? "true" : "false", |
216 onsubmitcalls, | 221 onsubmitcalls, |
217 oncancelcalls, | 222 oncancelcalls, |
218 onchangecalls, | 223 onchangecalls, |
219 onresizecalls, | 224 onresizecalls, |
220 before_load_value.c_str(), | 225 before_load_value.c_str(), |
221 before_load_verbatim ? "true" : "false", | 226 before_load_verbatim ? "true" : "false", |
222 value.c_str(), | 227 value.c_str(), |
223 verbatim ? "true" : "false"); | 228 verbatim ? "true" : "false", |
229 selection_start); | |
224 } | 230 } |
225 | 231 |
226 void CheckStringValueFromJavascript( | 232 void CheckStringValueFromJavascript( |
227 const std::string& expected, | 233 const std::string& expected, |
228 const std::string& function, | 234 const std::string& function, |
229 TabContents* tab_contents) { | 235 TabContents* tab_contents) { |
230 std::string result; | 236 std::string result; |
231 ASSERT_TRUE(GetStringFromJavascript(tab_contents, function, &result)); | 237 ASSERT_TRUE(GetStringFromJavascript(tab_contents, function, &result)); |
232 ASSERT_EQ(expected, result); | 238 ASSERT_EQ(expected, result); |
233 } | 239 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // Verify that the onchange event is dispatched upon typing in the box. | 280 // Verify that the onchange event is dispatched upon typing in the box. |
275 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { | 281 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { |
276 ASSERT_TRUE(test_server()->Start()); | 282 ASSERT_TRUE(test_server()->Start()); |
277 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 283 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
278 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 284 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
279 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 285 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
280 | 286 |
281 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 287 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
282 | 288 |
283 // Check that the value is reflected and onchange is called. | 289 // Check that the value is reflected and onchange is called. |
284 EXPECT_EQ("true 0 0 1 1 a false abc false", | 290 EXPECT_EQ("true 0 0 1 1 a false abc false 3", |
285 GetSearchStateAsString(preview_)); | 291 GetSearchStateAsString(preview_)); |
286 } | 292 } |
287 | 293 |
288 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) { | 294 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) { |
289 ASSERT_TRUE(test_server()->Start()); | 295 ASSERT_TRUE(test_server()->Start()); |
290 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 296 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
291 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 297 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
292 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 298 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
293 | 299 |
294 SetSuggestionsJavascriptArgument(preview_, "['abcde', 'unused']"); | 300 SetSuggestionsJavascriptArgument(preview_, "['abcde', 'unused']"); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 588 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
583 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); | 589 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); |
584 | 590 |
585 // Check that the preview contents have been committed. | 591 // Check that the preview contents have been committed. |
586 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 592 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
587 ASSERT_FALSE(browser()->instant()->is_active()); | 593 ASSERT_FALSE(browser()->instant()->is_active()); |
588 TabContents* contents = browser()->GetSelectedTabContents(); | 594 TabContents* contents = browser()->GetSelectedTabContents(); |
589 ASSERT_TRUE(contents); | 595 ASSERT_TRUE(contents); |
590 | 596 |
591 // Check that the value is reflected and onsubmit is called. | 597 // Check that the value is reflected and onsubmit is called. |
592 EXPECT_EQ("true 1 0 1 1 a false abc true", | 598 EXPECT_EQ("true 1 0 1 1 a false abc true 3", |
593 GetSearchStateAsString(preview_)); | 599 GetSearchStateAsString(preview_)); |
594 } | 600 } |
595 | 601 |
596 // Verify that the oncancel event is dispatched upon losing focus. | 602 // Verify that the oncancel event is dispatched upon losing focus. |
597 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { | 603 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { |
598 ASSERT_TRUE(test_server()->Start()); | 604 ASSERT_TRUE(test_server()->Start()); |
599 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 605 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
600 | 606 |
601 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 607 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
602 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 608 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
603 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 609 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
604 | 610 |
605 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 611 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
606 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), | 612 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
607 VIEW_ID_TAB_CONTAINER)); | 613 VIEW_ID_TAB_CONTAINER)); |
608 | 614 |
609 // Check that the preview contents have been committed. | 615 // Check that the preview contents have been committed. |
610 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 616 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
611 ASSERT_FALSE(browser()->instant()->is_active()); | 617 ASSERT_FALSE(browser()->instant()->is_active()); |
612 TabContents* contents = browser()->GetSelectedTabContents(); | 618 TabContents* contents = browser()->GetSelectedTabContents(); |
613 ASSERT_TRUE(contents); | 619 ASSERT_TRUE(contents); |
614 | 620 |
615 // Check that the value is reflected and oncancel is called. | 621 // Check that the value is reflected and oncancel is called. |
616 EXPECT_EQ("true 0 1 1 1 a false abc false", | 622 EXPECT_EQ("true 0 1 1 1 a false abc false 3", |
617 GetSearchStateAsString(preview_)); | 623 GetSearchStateAsString(preview_)); |
618 } | 624 } |
619 | 625 |
620 #if !defined(OS_MACOSX) | 626 #if !defined(OS_MACOSX) |
621 // Only passes on Mac. http://crbug.com/66850 | 627 // Only passes on Mac. http://crbug.com/66850 |
622 #define MAYBE_TabKey FAILS_TabKey | 628 #define MAYBE_TabKey FAILS_TabKey |
623 #else | 629 #else |
624 #define MAYBE_TabKey TabKey | 630 #define MAYBE_TabKey TabKey |
625 #endif | 631 #endif |
626 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { | 632 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { |
627 ASSERT_TRUE(test_server()->Start()); | 633 ASSERT_TRUE(test_server()->Start()); |
628 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 634 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
629 | 635 |
630 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 636 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
631 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 637 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
632 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 638 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
633 | 639 |
634 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 640 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
635 | 641 |
636 // Pressing tab to convert instant suggest into inline autocomplete. | 642 // Pressing tab to convert instant suggest into inline autocomplete. |
637 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); | 643 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); |
638 | 644 |
639 ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText()); | 645 ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText()); |
640 | 646 |
641 EXPECT_EQ("true 0 0 2 2 a false abcdef false", | 647 EXPECT_EQ("true 0 0 2 2 a false abcdef false 6", |
642 GetSearchStateAsString(preview_)); | 648 GetSearchStateAsString(preview_)); |
643 | 649 |
644 // Pressing tab again to accept the current instant preview. | 650 // Pressing tab again to accept the current instant preview. |
645 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); | 651 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); |
646 | 652 |
647 // Check that the preview contents have been committed. | 653 // Check that the preview contents have been committed. |
648 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 654 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
649 ASSERT_FALSE(browser()->instant()->is_active()); | 655 ASSERT_FALSE(browser()->instant()->is_active()); |
650 TabContents* contents = browser()->GetSelectedTabContents(); | 656 TabContents* contents = browser()->GetSelectedTabContents(); |
651 ASSERT_TRUE(contents); | 657 ASSERT_TRUE(contents); |
652 | 658 |
653 // Check that the value is reflected and onsubmit is called. | 659 // Check that the value is reflected and onsubmit is called. |
654 EXPECT_EQ("true 1 0 2 2 a false abcdef true", | 660 EXPECT_EQ("true 1 0 2 2 a false abcdef true 6", |
655 GetSearchStateAsString(preview_)); | 661 GetSearchStateAsString(preview_)); |
656 } | 662 } |
OLD | NEW |