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

Side by Side Diff: chrome/browser/ui/search/instant_extended_browsertest.cc

Issue 12895007: Send onsubmit query down to the instant extended overlay page when a navigation is performed from t… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check return value of UpdateSearchState. Created 7 years, 8 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/ui/search/instant_controller.cc ('k') | chrome/renderer/searchbox/searchbox.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <sstream> 5 #include <sstream>
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } // namespace 65 } // namespace
66 66
67 class InstantExtendedTest : public InProcessBrowserTest, 67 class InstantExtendedTest : public InProcessBrowserTest,
68 public InstantTestBase { 68 public InstantTestBase {
69 public: 69 public:
70 InstantExtendedTest() 70 InstantExtendedTest()
71 : on_most_visited_change_calls_(0), 71 : on_most_visited_change_calls_(0),
72 most_visited_items_count_(0), 72 most_visited_items_count_(0),
73 first_most_visited_item_id_(0), 73 first_most_visited_item_id_(0),
74 on_native_suggestions_calls_(0), 74 on_native_suggestions_calls_(0),
75 on_change_calls_(0) { 75 on_change_calls_(0),
76 submit_count_(0) {
76 } 77 }
77 protected: 78 protected:
78 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 79 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
79 chrome::EnableInstantExtendedAPIForTesting(); 80 chrome::EnableInstantExtendedAPIForTesting();
80 ASSERT_TRUE(https_test_server().Start()); 81 ASSERT_TRUE(https_test_server().Start());
81 GURL instant_url = https_test_server().GetURL( 82 GURL instant_url = https_test_server().GetURL(
82 "files/instant_extended.html?strk=1&"); 83 "files/instant_extended.html?strk=1&");
83 InstantTestBase::Init(instant_url); 84 InstantTestBase::Init(instant_url);
84 } 85 }
85 86
(...skipping 22 matching lines...) Expand all
108 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { 109 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT {
109 return GetIntFromJS(contents, "onMostVisitedChangedCalls", 110 return GetIntFromJS(contents, "onMostVisitedChangedCalls",
110 &on_most_visited_change_calls_) && 111 &on_most_visited_change_calls_) &&
111 GetIntFromJS(contents, "mostVisitedItemsCount", 112 GetIntFromJS(contents, "mostVisitedItemsCount",
112 &most_visited_items_count_) && 113 &most_visited_items_count_) &&
113 GetIntFromJS(contents, "firstMostVisitedItemId", 114 GetIntFromJS(contents, "firstMostVisitedItemId",
114 &first_most_visited_item_id_) && 115 &first_most_visited_item_id_) &&
115 GetIntFromJS(contents, "onNativeSuggestionsCalls", 116 GetIntFromJS(contents, "onNativeSuggestionsCalls",
116 &on_native_suggestions_calls_) && 117 &on_native_suggestions_calls_) &&
117 GetIntFromJS(contents, "onChangeCalls", 118 GetIntFromJS(contents, "onChangeCalls",
118 &on_change_calls_); 119 &on_change_calls_) &&
120 GetIntFromJS(contents, "submitCount",
121 &submit_count_) &&
122 GetStringFromJS(contents, "apiHandle.value",
123 &query_value_);
119 } 124 }
120 125
121 int on_most_visited_change_calls_; 126 int on_most_visited_change_calls_;
122 int most_visited_items_count_; 127 int most_visited_items_count_;
123 int first_most_visited_item_id_; 128 int first_most_visited_item_id_;
124 int on_native_suggestions_calls_; 129 int on_native_suggestions_calls_;
125 int on_change_calls_; 130 int on_change_calls_;
131 int submit_count_;
132 std::string query_value_;
126 }; 133 };
127 134
128 // Test class used to verify chrome-search: scheme and access policy from the 135 // Test class used to verify chrome-search: scheme and access policy from the
129 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it 136 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it
130 // loads a theme that provides a background image. 137 // loads a theme that provides a background image.
131 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { 138 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase {
132 public: 139 public:
133 InstantPolicyTest() {} 140 InstantPolicyTest() {}
134 141
135 protected: 142 protected:
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 std::string result; 448 std::string result;
442 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(), 449 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
443 "window.chrome.searchBox.value", 450 "window.chrome.searchBox.value",
444 &result)); 451 &result));
445 EXPECT_EQ("hello", result); 452 EXPECT_EQ("hello", result);
446 453
447 EXPECT_TRUE(HasUserInputInProgress()); 454 EXPECT_TRUE(HasUserInputInProgress());
448 // TODO(beaudoin): Figure out why this fails. 455 // TODO(beaudoin): Figure out why this fails.
449 // EXPECT_FALSE(HasTemporaryText()); 456 // EXPECT_FALSE(HasTemporaryText());
450 457
451
452 // Commit the search by pressing Enter. 458 // Commit the search by pressing Enter.
453 browser()->window()->GetLocationBar()->AcceptInput(); 459 browser()->window()->GetLocationBar()->AcceptInput();
454 EXPECT_EQ("hello", GetOmniboxText()); 460 EXPECT_EQ("hello", GetOmniboxText());
455 } 461 }
456 462
457 // This test simulates a search provider using the InstantExtended API to 463 // This test simulates a search provider using the InstantExtended API to
464 // navigate through the suggested results and back to the original user query.
465 // If this test starts to flake, it may be that the second call to AcceptInput
466 // below causes instant()->instant_tab() to no longer be valid due to e.g. a
467 // navigation. In that case, see https://codereview.chromium.org/12895007/#msg28
468 // and onwards for possible alternatives.
469 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
470 NavigateToURLSuggestionHitEnterAndLookForSubmit) {
471 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
472 FocusOmniboxAndWaitForInstantExtendedSupport();
473
474 // Create an observer to wait for the instant tab to support Instant.
475 content::WindowedNotificationObserver observer(
476 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
477 content::NotificationService::AllSources());
478
479 // Do a search and commit it.
480 SetOmniboxTextAndWaitForOverlayToShow("hello k");
481 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText());
482 browser()->window()->GetLocationBar()->AcceptInput();
483 observer.Wait();
484
485 SetOmniboxText("http");
486 EXPECT_EQ("http", GetOmniboxText());
487
488 SendDownArrow();
489 EXPECT_EQ("result 1", GetOmniboxText());
490 SendDownArrow();
491 EXPECT_EQ("result 2", GetOmniboxText());
492 SendDownArrow();
493 EXPECT_EQ("http://www.google.com", GetOmniboxText());
494
495 EXPECT_TRUE(HasUserInputInProgress());
496
497 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents()));
498 // Note the commit count is initially 1 due to the AcceptInput() call above.
499 EXPECT_EQ(1, submit_count_);
500
501 std::string old_query_value(query_value_);
502
503 // Commit the search by pressing Enter.
504 browser()->window()->GetLocationBar()->AcceptInput();
505
506 // Make sure a submit message got sent.
507 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents()));
508 EXPECT_EQ(2, submit_count_);
509 EXPECT_EQ(old_query_value, query_value_);
510 }
511
512 // This test simulates a search provider using the InstantExtended API to
458 // navigate through the suggested results and hitting escape to get back to the 513 // navigate through the suggested results and hitting escape to get back to the
459 // original user query. 514 // original user query.
460 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { 515 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) {
461 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 516 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
462 FocusOmniboxAndWaitForInstantExtendedSupport(); 517 FocusOmniboxAndWaitForInstantExtendedSupport();
463 518
464 SetOmniboxTextAndWaitForOverlayToShow("hello"); 519 SetOmniboxTextAndWaitForOverlayToShow("hello");
465 EXPECT_EQ("hello", GetOmniboxText()); 520 EXPECT_EQ("hello", GetOmniboxText());
466 521
467 SendDownArrow(); 522 SendDownArrow();
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1484 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1430 1485
1431 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL()); 1486 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL());
1432 1487
1433 // The second argument says to use only the local overlay. 1488 // The second argument says to use only the local overlay.
1434 instant()->SetInstantEnabled(false, true); 1489 instant()->SetInstantEnabled(false, true);
1435 1490
1436 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 1491 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
1437 instant()->ntp_->contents()->GetURL()); 1492 instant()->ntp_->contents()->GetURL());
1438 } 1493 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_controller.cc ('k') | chrome/renderer/searchbox/searchbox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698