OLD | NEW |
---|---|
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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 class InstantExtendedTest : public InProcessBrowserTest, | 107 class InstantExtendedTest : public InProcessBrowserTest, |
108 public InstantTestBase { | 108 public InstantTestBase { |
109 public: | 109 public: |
110 InstantExtendedTest() | 110 InstantExtendedTest() |
111 : on_most_visited_change_calls_(0), | 111 : on_most_visited_change_calls_(0), |
112 most_visited_items_count_(0), | 112 most_visited_items_count_(0), |
113 first_most_visited_item_id_(0), | 113 first_most_visited_item_id_(0), |
114 on_native_suggestions_calls_(0), | 114 on_native_suggestions_calls_(0), |
115 on_change_calls_(0), | 115 on_change_calls_(0), |
116 submit_count_(0), | 116 submit_count_(0), |
117 on_esc_key_press_event_calls_(0) { | 117 on_esc_key_press_event_calls_(0), |
118 on_focus_changed_calls_(0), | |
119 is_focused_(false) { | |
118 } | 120 } |
119 protected: | 121 protected: |
120 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 122 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
121 chrome::EnableInstantExtendedAPIForTesting(); | 123 chrome::EnableInstantExtendedAPIForTesting(); |
122 ASSERT_TRUE(https_test_server().Start()); | 124 ASSERT_TRUE(https_test_server().Start()); |
123 GURL instant_url = https_test_server().GetURL( | 125 GURL instant_url = https_test_server().GetURL( |
124 "files/instant_extended.html?strk=1&"); | 126 "files/instant_extended.html?strk=1&"); |
125 InstantTestBase::Init(instant_url); | 127 InstantTestBase::Init(instant_url); |
126 } | 128 } |
127 | 129 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 &first_most_visited_item_id_) && | 162 &first_most_visited_item_id_) && |
161 GetIntFromJS(contents, "onNativeSuggestionsCalls", | 163 GetIntFromJS(contents, "onNativeSuggestionsCalls", |
162 &on_native_suggestions_calls_) && | 164 &on_native_suggestions_calls_) && |
163 GetIntFromJS(contents, "onChangeCalls", | 165 GetIntFromJS(contents, "onChangeCalls", |
164 &on_change_calls_) && | 166 &on_change_calls_) && |
165 GetIntFromJS(contents, "submitCount", | 167 GetIntFromJS(contents, "submitCount", |
166 &submit_count_) && | 168 &submit_count_) && |
167 GetStringFromJS(contents, "apiHandle.value", | 169 GetStringFromJS(contents, "apiHandle.value", |
168 &query_value_) && | 170 &query_value_) && |
169 GetIntFromJS(contents, "onEscKeyPressedCalls", | 171 GetIntFromJS(contents, "onEscKeyPressedCalls", |
170 &on_esc_key_press_event_calls_); | 172 &on_esc_key_press_event_calls_) && |
173 GetIntFromJS(contents, "onFocusChangedCalls", | |
174 &on_focus_changed_calls_) && | |
175 GetBoolFromJS(contents, "isFocused", | |
176 &is_focused_); | |
171 } | 177 } |
172 | 178 |
173 TemplateURL* GetDefaultSearchProviderTemplateURL() { | 179 TemplateURL* GetDefaultSearchProviderTemplateURL() { |
174 TemplateURLService* template_url_service = | 180 TemplateURLService* template_url_service = |
175 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 181 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
176 if (template_url_service) | 182 if (template_url_service) |
177 return template_url_service->GetDefaultSearchProvider(); | 183 return template_url_service->GetDefaultSearchProvider(); |
178 return NULL; | 184 return NULL; |
179 } | 185 } |
180 | 186 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 218 } |
213 | 219 |
214 int on_most_visited_change_calls_; | 220 int on_most_visited_change_calls_; |
215 int most_visited_items_count_; | 221 int most_visited_items_count_; |
216 int first_most_visited_item_id_; | 222 int first_most_visited_item_id_; |
217 int on_native_suggestions_calls_; | 223 int on_native_suggestions_calls_; |
218 int on_change_calls_; | 224 int on_change_calls_; |
219 int submit_count_; | 225 int submit_count_; |
220 int on_esc_key_press_event_calls_; | 226 int on_esc_key_press_event_calls_; |
221 std::string query_value_; | 227 std::string query_value_; |
228 int on_focus_changed_calls_; | |
229 bool is_focused_; | |
222 }; | 230 }; |
223 | 231 |
224 // Test class used to verify chrome-search: scheme and access policy from the | 232 // Test class used to verify chrome-search: scheme and access policy from the |
225 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it | 233 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it |
226 // loads a theme that provides a background image. | 234 // loads a theme that provides a background image. |
227 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { | 235 class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { |
228 public: | 236 public: |
229 InstantPolicyTest() {} | 237 InstantPolicyTest() {} |
230 | 238 |
231 protected: | 239 protected: |
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 &query)); | 2027 &query)); |
2020 EXPECT_EQ("", query); | 2028 EXPECT_EQ("", query); |
2021 EXPECT_EQ("", GetOmniboxText()); | 2029 EXPECT_EQ("", GetOmniboxText()); |
2022 | 2030 |
2023 EXPECT_TRUE(UpdateSearchState(contents)); | 2031 EXPECT_TRUE(UpdateSearchState(contents)); |
2024 EXPECT_LT(0, on_change_calls_); | 2032 EXPECT_LT(0, on_change_calls_); |
2025 EXPECT_EQ(0, submit_count_); | 2033 EXPECT_EQ(0, submit_count_); |
2026 EXPECT_LT(0, on_esc_key_press_event_calls_); | 2034 EXPECT_LT(0, on_esc_key_press_event_calls_); |
2027 } | 2035 } |
2028 | 2036 |
2037 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FocusApiRespondsToFocusChange) { | |
2038 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
2039 EXPECT_FALSE(is_focused_); | |
2040 EXPECT_EQ(0, on_focus_changed_calls_); | |
2041 | |
2042 // 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.
| |
2043 FocusOmniboxAndWaitForInstantOverlaySupport(); | |
2044 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
| |
2045 EXPECT_TRUE(is_focused_); | |
2046 EXPECT_EQ(1, on_focus_changed_calls_); | |
2047 | |
2048 // Now unfocus the omnibox. | |
2049 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | |
2050 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); | |
2051 EXPECT_FALSE(is_focused_); | |
2052 EXPECT_EQ(2, on_focus_changed_calls_); | |
2053 | |
2054 // Focus the Omnibox again. | |
2055 // The first focus may have worked only due to initial-state anomalies. | |
2056 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.
| |
2057 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); | |
2058 EXPECT_TRUE(is_focused_); | |
2059 EXPECT_EQ(3, on_focus_changed_calls_); | |
2060 } | |
2061 | |
2062 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FocusApiIgnoresRedundantFocus) { | |
2063 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
2064 EXPECT_FALSE(is_focused_); | |
2065 EXPECT_EQ(0, on_focus_changed_calls_); | |
2066 | |
2067 // Focus the Omnibox. | |
2068 FocusOmniboxAndWaitForInstantOverlaySupport(); | |
2069 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); | |
2070 EXPECT_TRUE(is_focused_); | |
2071 EXPECT_EQ(1, on_focus_changed_calls_); | |
2072 | |
2073 // When we focus the omnibox again, nothing should change. | |
2074 FocusOmniboxAndWaitForInstantOverlaySupport(); | |
2075 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); | |
2076 EXPECT_TRUE(is_focused_); | |
2077 EXPECT_EQ(1, on_focus_changed_calls_); | |
2078 | |
2079 // Now unfocus the omnibox. | |
2080 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | |
2081 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); | |
2082 EXPECT_FALSE(is_focused_); | |
2083 EXPECT_EQ(2, on_focus_changed_calls_); | |
2084 | |
2085 // When we unfocus again, nothing should change. | |
2086 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | |
2087 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); | |
2088 EXPECT_FALSE(is_focused_); | |
2089 EXPECT_EQ(2, on_focus_changed_calls_); | |
2090 } | |
2091 | |
2029 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { | 2092 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { |
2030 InstantService* instant_service = | 2093 InstantService* instant_service = |
2031 InstantServiceFactory::GetForProfile(browser()->profile()); | 2094 InstantServiceFactory::GetForProfile(browser()->profile()); |
2032 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | 2095 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
2033 | 2096 |
2034 // Setup Instant. | 2097 // Setup Instant. |
2035 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2098 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
2036 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2099 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
2037 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); | 2100 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); |
2038 | 2101 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2413 EXPECT_TRUE(instant()->ntp()->IsLocal()); | 2476 EXPECT_TRUE(instant()->ntp()->IsLocal()); |
2414 | 2477 |
2415 // Overlay contents should be preloaded. | 2478 // Overlay contents should be preloaded. |
2416 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); | 2479 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay()); |
2417 EXPECT_TRUE(instant()->overlay()->IsLocal()); | 2480 EXPECT_TRUE(instant()->overlay()->IsLocal()); |
2418 | 2481 |
2419 // Instant tab contents should be preloaded. | 2482 // Instant tab contents should be preloaded. |
2420 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); | 2483 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); |
2421 EXPECT_TRUE(instant()->instant_tab()->IsLocal()); | 2484 EXPECT_TRUE(instant()->instant_tab()->IsLocal()); |
2422 } | 2485 } |
OLD | NEW |