summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/instant/instant_extended_browsertest.cc35
-rw-r--r--chrome/browser/ui/omnibox/omnibox_edit_model.cc5
-rw-r--r--chrome/test/data/instant_extended.html41
3 files changed, 79 insertions, 2 deletions
diff --git a/chrome/browser/instant/instant_extended_browsertest.cc b/chrome/browser/instant/instant_extended_browsertest.cc
index ff1bb16..6defb4b 100644
--- a/chrome/browser/instant/instant_extended_browsertest.cc
+++ b/chrome/browser/instant/instant_extended_browsertest.cc
@@ -17,6 +17,22 @@ class InstantExtendedTest : public InstantTestBase {
instant_url_ = https_test_server_.
GetURL("files/instant_extended.html?strk=1&");
}
+
+ std::string GetOmniboxText() {
+ return UTF16ToUTF8(omnibox()->GetText());
+ }
+
+ void SendDownArrow() {
+ omnibox()->model()->OnUpOrDownKeyPressed(1);
+ // Wait for JavaScript to run the key handler by executing a blank script.
+ EXPECT_TRUE(ExecuteScript(std::string()));
+ }
+
+ void SendUpArrow() {
+ omnibox()->model()->OnUpOrDownKeyPressed(-1);
+ // Wait for JavaScript to run the key handler by executing a blank script.
+ EXPECT_TRUE(ExecuteScript(std::string()));
+ }
};
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) {
@@ -133,3 +149,22 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponFocusLostCommit) {
// Suggestion should be cleared at this point.
EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion());
}
+
+// This test simulates a search provider using the InstantExtended API to
+// navigate through the suggested results and back to the original user query.
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) {
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+ FocusOmniboxAndWaitForInstantSupport();
+
+ SetOmniboxTextAndWaitForInstantToShow("hello");
+ EXPECT_EQ("hello", GetOmniboxText());
+
+ SendDownArrow();
+ EXPECT_EQ("result 1", GetOmniboxText());
+ SendDownArrow();
+ EXPECT_EQ("result 2", GetOmniboxText());
+ SendUpArrow();
+ EXPECT_EQ("result 1", GetOmniboxText());
+ SendUpArrow();
+ EXPECT_EQ("hello", GetOmniboxText());
+}
diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
index 698f82d..aa807ba 100644
--- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc
+++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc
@@ -1250,6 +1250,11 @@ bool OmniboxEditModel::DoInstant(const AutocompleteMatch& match) {
if (!instant || in_revert_)
return false;
+ // Don't call Update() if the change is a result of a
+ // INSTANT_COMPLETE_REPLACE instant suggestion.
+ if (has_temporary_text_ && is_temporary_text_set_by_instant_)
+ return false;
+
// The two pieces of text we want to send Instant, viz., what the user has
// typed, and the full omnibox text including any inline autocompletion.
string16 user_text = has_temporary_text_ ?
diff --git a/chrome/test/data/instant_extended.html b/chrome/test/data/instant_extended.html
index 0a620c7..96c2541 100644
--- a/chrome/test/data/instant_extended.html
+++ b/chrome/test/data/instant_extended.html
@@ -5,6 +5,9 @@
var apiHandle;
var onnativesuggestioncalls = 0;
var onsubmitcalls = 0;
+var savedUserText = null;
+var suggestionIndex = -1;
+var suggestions = ["result 1", "result 2", "result 3"];
var suggestion;
function getApiHandle() {
@@ -26,6 +29,8 @@ function handleSubmit() {
}
function handleOnChange() {
+ savedUserText = apiHandle.value;
+ suggestionIndex = -1;
if (suggestion) {
apiHandle.setAutocompleteText(suggestion, 2);
// Ensure this is only called once for this suggestion.
@@ -33,13 +38,45 @@ function handleOnChange() {
}
}
+function nextSuggestion() {
+ if (suggestionIndex < suggestions.length - 1) {
+ suggestionIndex++;
+ apiHandle.setValue(suggestions[suggestionIndex]);
+ }
+}
+
+function previousSuggestion() {
+ if (suggestionIndex != -1) {
+ suggestionIndex--;
+ if (suggestionIndex == -1) {
+ apiHandle.setValue(savedUserText);
+ } else {
+ apiHandle.setValue(suggestions[suggestionIndex]);
+ }
+ }
+}
+
+function handleKeyPress(event) {
+ var VKEY_UP = 0x26;
+ var VKEY_DOWN = 0x28;
+
+ if (event.keyCode == VKEY_DOWN) {
+ nextSuggestion();
+ } else if (event.keyCode == VKEY_UP) {
+ previousSuggestion();
+ }
+}
+
function setUp() {
apiHandle = getApiHandle();
- apiHandle.onchange = handleOnChange;
apiHandle.onnativesuggestions = handleNativeSuggestions;
apiHandle.onsubmit = handleSubmit;
- if (apiHandle.value)
+ apiHandle.onchange = handleOnChange;
+ apiHandle.onkeypress = handleKeyPress;
+ if (apiHandle.value) {
handleNativeSuggestions();
+ handleOnChange();
+ }
}
setUp();