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

Side by Side Diff: chrome/browser/instant/instant_extended_browsertest.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failures. Created 7 years, 10 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
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 "chrome/browser/instant/instant_commit_type.h" 5 #include "chrome/browser/instant/instant_commit_type.h"
6 #include "chrome/browser/instant/instant_loader.h" 6 #include "chrome/browser/instant/instant_ntp.h"
7 #include "chrome/browser/instant/instant_overlay.h"
8 #include "chrome/browser/instant/instant_service.h"
9 #include "chrome/browser/instant/instant_service_factory.h"
7 #include "chrome/browser/instant/instant_test_utils.h" 10 #include "chrome/browser/instant/instant_test_utils.h"
8 #include "chrome/browser/ui/search/search.h" 11 #include "chrome/browser/ui/search/search.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/url_constants.h"
9 #include "chrome/test/base/interactive_test_utils.h" 15 #include "chrome/test/base/interactive_test_utils.h"
10 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/web_contents.h"
11 20
12 class InstantExtendedTest : public InstantTestBase { 21 class InstantExtendedTest : public InstantTestBase {
13 protected: 22 protected:
14 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 23 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
15 chrome::search::EnableInstantExtendedAPIForTesting(); 24 chrome::search::EnableInstantExtendedAPIForTesting();
16 ASSERT_TRUE(https_test_server_.Start()); 25 ASSERT_TRUE(https_test_server_.Start());
17 instant_url_ = https_test_server_. 26 instant_url_ = https_test_server_.
18 GetURL("files/instant_extended.html?strk=1&"); 27 GetURL("files/instant_extended.html?strk=1&");
19 } 28 }
29
30 void FocusOmniboxAndWaitForInstantSupport() {
31 content::WindowedNotificationObserver ntp_observer(
32 chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
33 content::NotificationService::AllSources());
34 content::WindowedNotificationObserver overlay_observer(
35 chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED,
36 content::NotificationService::AllSources());
37 FocusOmnibox();
38 ntp_observer.Wait();
39 overlay_observer.Wait();
40 }
20 }; 41 };
21 42
22 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { 43 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) {
23 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 44 ASSERT_NO_FATAL_FAILURE(SetupInstant());
24 EXPECT_TRUE(instant()->extended_enabled_); 45 EXPECT_TRUE(instant()->extended_enabled_);
25 } 46 }
26 47
27 // Test that Instant is preloaded when the omnibox is focused. 48 // Test that Instant is preloaded when the omnibox is focused.
28 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { 49 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) {
29 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 50 ASSERT_NO_FATAL_FAILURE(SetupInstant());
30 51
31 // Explicitly unfocus the omnibox. 52 // Explicitly unfocus the omnibox.
32 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 53 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
33 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 54 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
34 55
35 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 56 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
36 EXPECT_FALSE(omnibox()->model()->has_focus()); 57 EXPECT_FALSE(omnibox()->model()->has_focus());
37 58
38 // Delete any existing preview. 59 // Delete any existing preview.
39 instant()->loader_.reset(); 60 instant()->overlay_.reset();
40 EXPECT_FALSE(instant()->GetPreviewContents()); 61 EXPECT_FALSE(instant()->GetPreviewContents());
41 62
42 // Refocus the omnibox. The InstantController should've preloaded Instant. 63 // Refocus the omnibox. The InstantController should've preloaded Instant.
43 FocusOmniboxAndWaitForInstantSupport(); 64 FocusOmniboxAndWaitForInstantSupport();
44 65
45 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 66 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
46 EXPECT_TRUE(omnibox()->model()->has_focus()); 67 EXPECT_TRUE(omnibox()->model()->has_focus());
47 68
48 content::WebContents* preview_tab = instant()->GetPreviewContents(); 69 content::WebContents* preview_tab = instant()->GetPreviewContents();
49 EXPECT_TRUE(preview_tab); 70 EXPECT_TRUE(preview_tab);
50 71
51 // Check that the page supports Instant, but it isn't showing. 72 // Check that the page supports Instant, but it isn't showing.
52 EXPECT_TRUE(instant()->loader_->supports_instant()); 73 EXPECT_TRUE(instant()->overlay_->supports_instant());
53 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); 74 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
54 EXPECT_TRUE(instant()->model()->mode().is_default()); 75 EXPECT_TRUE(instant()->model()->mode().is_default());
55 76
56 // Adding a new tab shouldn't delete or recreate the preview; otherwise, 77 // Adding a new tab shouldn't delete or recreate the preview; otherwise,
57 // what's the point of preloading? 78 // what's the point of preloading?
58 AddBlankTabAndShow(browser()); 79 AddBlankTabAndShow(browser());
59 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); 80 EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
60 81
61 // Unfocusing and refocusing the omnibox should also preserve the preview. 82 // Unfocusing and refocusing the omnibox should also preserve the preview.
62 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 83 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 147
127 // Commit the overlay by lost focus (e.g. clicking on the page). 148 // Commit the overlay by lost focus (e.g. clicking on the page).
128 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); 149 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
129 150
130 // Search term extraction should kick in with the autocompleted text. 151 // Search term extraction should kick in with the autocompleted text.
131 EXPECT_EQ(ASCIIToUTF16("johnny depp"), omnibox()->GetText()); 152 EXPECT_EQ(ASCIIToUTF16("johnny depp"), omnibox()->GetText());
132 153
133 // Suggestion should be cleared at this point. 154 // Suggestion should be cleared at this point.
134 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); 155 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion());
135 } 156 }
157
158 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) {
159 // Setup Instant.
160 ASSERT_NO_FATAL_FAILURE(SetupInstant());
161 FocusOmniboxAndWaitForInstantSupport();
162
163 // NTP contents should be preloaded.
164 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
165 content::WebContents* ntp_contents = instant()->ntp_->contents();
166 EXPECT_TRUE(ntp_contents);
167 }
168
169 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) {
170 // Setup Instant.
171 ASSERT_NO_FATAL_FAILURE(SetupInstant());
172 FocusOmniboxAndWaitForInstantSupport();
173
174 // NTP contents should be preloaded.
175 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
176 content::WebContents* ntp_contents = instant()->ntp_->contents();
177 EXPECT_TRUE(ntp_contents);
178
179 // Open new tab. Preloaded NTP contents should have been used.
180 ui_test_utils::NavigateToURLWithDisposition(
181 browser(),
182 GURL(chrome::kChromeUINewTabURL),
183 NEW_FOREGROUND_TAB,
184 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
185 content::WebContents* active_tab =
186 browser()->tab_strip_model()->GetActiveWebContents();
187 EXPECT_EQ(ntp_contents, active_tab);
188 }
189
190 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) {
191 // Setup Instant.
192 ASSERT_NO_FATAL_FAILURE(SetupInstant());
193 FocusOmniboxAndWaitForInstantSupport();
194
195 // NTP contents should be preloaded.
196 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
197 content::WebContents* ntp_contents = instant()->ntp_->contents();
198 EXPECT_TRUE(ntp_contents);
199
200 // Open new tab. Preloaded NTP contents should have been used.
201 ui_test_utils::NavigateToURLWithDisposition(
202 browser(),
203 GURL(chrome::kChromeUINewTabURL),
204 CURRENT_TAB,
205 ui_test_utils::BROWSER_TEST_NONE);
206 content::WebContents* active_tab =
207 browser()->tab_strip_model()->GetActiveWebContents();
208 EXPECT_EQ(ntp_contents, active_tab);
209 }
210
211 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) {
212 // Setup Instant.
213 ASSERT_NO_FATAL_FAILURE(SetupInstant());
214 FocusOmniboxAndWaitForInstantSupport();
215
216 // Explicitly unfocus the omnibox.
217 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
218 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
219 EXPECT_FALSE(omnibox()->model()->has_focus());
220
221 // Open new tab. Preloaded NTP contents should have been used.
222 ui_test_utils::NavigateToURLWithDisposition(
223 browser(),
224 GURL(chrome::kChromeUINewTabURL),
225 NEW_FOREGROUND_TAB,
226 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
227
228 // Omnibox should have focus.
229 EXPECT_TRUE(omnibox()->model()->has_focus());
230 }
231
232 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) {
233 // Setup Instant.
234 ASSERT_NO_FATAL_FAILURE(SetupInstant());
235 FocusOmniboxAndWaitForInstantSupport();
236
237 // Open new tab. Preloaded NTP contents should have been used.
238 ui_test_utils::NavigateToURLWithDisposition(
239 browser(),
240 GURL(chrome::kChromeUINewTabURL),
241 CURRENT_TAB,
242 ui_test_utils::BROWSER_TEST_NONE);
243
244 // Omnibox should be empty.
245 EXPECT_TRUE(omnibox()->GetText().empty());
246 }
247
248 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) {
249 ASSERT_NO_FATAL_FAILURE(SetupInstant());
250
251 // Focus omnibox and confirm overlay isn't shown.
252 FocusOmniboxAndWaitForInstantSupport();
253 content::WebContents* preview_tab = instant()->GetPreviewContents();
254 EXPECT_TRUE(preview_tab);
255 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
256 EXPECT_TRUE(instant()->model()->mode().is_default());
257
258 // Navigate to the NTP.
259 ui_test_utils::NavigateToURLWithDisposition(
260 browser(),
261 GURL(chrome::kChromeUINewTabURL),
262 CURRENT_TAB,
263 ui_test_utils::BROWSER_TEST_NONE);
264
265 // Typing in the omnibox should not show the overlay.
266 SetOmniboxText("query");
267 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
268 EXPECT_TRUE(instant()->model()->mode().is_default());
269 }
270
271 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) {
272 // Prior to setup no render process is dedicated to Instant.
273 InstantService* instant_service =
274 InstantServiceFactory::GetForProfile(browser()->profile());
275 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
276 EXPECT_EQ(0, instant_service->GetInstantProcessCount());
277
278 // Setup Instant.
279 ASSERT_NO_FATAL_FAILURE(SetupInstant());
280 FocusOmniboxAndWaitForInstantSupport();
281
282 // Now there should be a registered Instant render process.
283 EXPECT_LT(0, instant_service->GetInstantProcessCount());
284
285 // And the Instant overlay and ntp should live inside it.
286 content::WebContents* preview = instant()->GetPreviewContents();
287 EXPECT_TRUE(instant_service->IsInstantProcess(
288 preview->GetRenderProcessHost()->GetID()));
289 content::WebContents* ntp_contents = instant()->ntp_->contents();
290 EXPECT_TRUE(instant_service->IsInstantProcess(
291 ntp_contents->GetRenderProcessHost()->GetID()));
292
293 // Navigating to the NTP should use the Instant render process.
294 ui_test_utils::NavigateToURLWithDisposition(
295 browser(),
296 GURL(chrome::kChromeUINewTabURL),
297 CURRENT_TAB,
298 ui_test_utils::BROWSER_TEST_NONE);
299 content::WebContents* active_tab =
300 browser()->tab_strip_model()->GetActiveWebContents();
301 EXPECT_TRUE(instant_service->IsInstantProcess(
302 active_tab->GetRenderProcessHost()->GetID()));
303
304 // Navigating elsewhere should not use the Instant render process.
305 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
306 EXPECT_FALSE(instant_service->IsInstantProcess(
307 active_tab->GetRenderProcessHost()->GetID()));
308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698