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

Unified Diff: chrome/browser/ui/search/instant_extended_interactive_uitest.cc

Issue 14646034: Add onfocuschange to the Extended Search API, with associated isFocused attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit tests Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/search/instant_extended_interactive_uitest.cc
diff --git a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
index 6ec822ac556e1657045adb645338628399c89f3f..ef8e649c911e552e4c4c609e281270f37def6b92 100644
--- a/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
+++ b/chrome/browser/ui/search/instant_extended_interactive_uitest.cc
@@ -114,7 +114,9 @@ class InstantExtendedTest : public InProcessBrowserTest,
on_native_suggestions_calls_(0),
on_change_calls_(0),
submit_count_(0),
- on_esc_key_press_event_calls_(0) {
+ on_esc_key_press_event_calls_(0),
+ on_focus_changed_calls_(0),
+ is_focused_(false) {
}
protected:
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
@@ -167,7 +169,11 @@ class InstantExtendedTest : public InProcessBrowserTest,
GetStringFromJS(contents, "apiHandle.value",
&query_value_) &&
GetIntFromJS(contents, "onEscKeyPressedCalls",
- &on_esc_key_press_event_calls_);
+ &on_esc_key_press_event_calls_) &&
+ GetIntFromJS(contents, "onFocusChangedCalls",
+ &on_focus_changed_calls_) &&
+ GetBoolFromJS(contents, "isFocused",
+ &is_focused_);
}
TemplateURL* GetDefaultSearchProviderTemplateURL() {
@@ -219,6 +225,8 @@ class InstantExtendedTest : public InProcessBrowserTest,
int submit_count_;
int on_esc_key_press_event_calls_;
std::string query_value_;
+ int on_focus_changed_calls_;
+ bool is_focused_;
};
// Test class used to verify chrome-search: scheme and access policy from the
@@ -2026,6 +2034,61 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_EscapeClearsOmnibox) {
EXPECT_LT(0, on_esc_key_press_event_calls_);
}
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FocusApiRespondsToFocusChange) {
+ ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
+ EXPECT_FALSE(is_focused_);
+ EXPECT_EQ(0, on_focus_changed_calls_);
+
+ // Focus the Omnibox.
samarth 2013/05/22 04:40:56 super nit: lower-case "omnibox" (and below)
Donn Denman 2013/05/22 17:37:36 Done.
+ FocusOmniboxAndWaitForInstantOverlaySupport();
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
samarth 2013/05/22 04:40:56 nit: EXPECT -> ASSERT here and for other calls to
Donn Denman 2013/05/22 17:37:36 Ah, that makes the code much more readable! Done.
samarth 2013/05/23 21:06:33 Yeah, in general, any failed check that would make
+ EXPECT_TRUE(is_focused_);
+ EXPECT_EQ(1, on_focus_changed_calls_);
+
+ // Now unfocus the omnibox.
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
+ EXPECT_FALSE(is_focused_);
+ EXPECT_EQ(2, on_focus_changed_calls_);
+
+ // Focus the Omnibox again.
+ // The first focus may have worked only due to initial-state anomalies.
+ FocusOmniboxAndWaitForInstantOverlaySupport();
samarth 2013/05/22 04:40:56 Hmm, I'm surprised that this works. In particular
Donn Denman 2013/05/22 17:37:36 Done.
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
+ EXPECT_TRUE(is_focused_);
+ EXPECT_EQ(3, on_focus_changed_calls_);
+}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FocusApiIgnoresRedundantFocus) {
+ ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
+ EXPECT_FALSE(is_focused_);
+ EXPECT_EQ(0, on_focus_changed_calls_);
+
+ // Focus the Omnibox.
+ FocusOmniboxAndWaitForInstantOverlaySupport();
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
+ EXPECT_TRUE(is_focused_);
+ EXPECT_EQ(1, on_focus_changed_calls_);
+
+ // When we focus the omnibox again, nothing should change.
+ FocusOmniboxAndWaitForInstantOverlaySupport();
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
+ EXPECT_TRUE(is_focused_);
+ EXPECT_EQ(1, on_focus_changed_calls_);
+
+ // Now unfocus the omnibox.
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
+ EXPECT_FALSE(is_focused_);
+ EXPECT_EQ(2, on_focus_changed_calls_);
+
+ // When we unfocus again, nothing should change.
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
+ EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
+ EXPECT_FALSE(is_focused_);
+ EXPECT_EQ(2, on_focus_changed_calls_);
+}
+
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) {
InstantService* instant_service =
InstantServiceFactory::GetForProfile(browser()->profile());

Powered by Google App Engine
This is Rietveld 408576698