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

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: Rebase. 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_loader.h" 5 #include "chrome/browser/instant/instant_ntp.h"
6 #include "chrome/browser/instant/instant_overlay.h"
7 #include "chrome/browser/instant/instant_service.h"
8 #include "chrome/browser/instant/instant_service_factory.h"
6 #include "chrome/browser/instant/instant_test_utils.h" 9 #include "chrome/browser/instant/instant_test_utils.h"
7 #include "chrome/browser/ui/search/search.h" 10 #include "chrome/browser/ui/search/search.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/common/url_constants.h"
8 #include "chrome/test/base/interactive_test_utils.h" 14 #include "chrome/test/base/interactive_test_utils.h"
9 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/web_contents.h"
10 19
11 class InstantExtendedTest : public InstantTestBase { 20 class InstantExtendedTest : public InstantTestBase {
12 protected: 21 protected:
13 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 22 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
14 chrome::search::EnableInstantExtendedAPIForTesting(); 23 chrome::search::EnableInstantExtendedAPIForTesting();
15 ASSERT_TRUE(test_server()->Start()); 24 ASSERT_TRUE(test_server()->Start());
16 instant_url_ = test_server()->GetURL("files/instant_extended.html"); 25 instant_url_ = test_server()->GetURL("files/instant_extended.html");
17 } 26 }
27
28 void FocusOmniboxAndWaitForInstantSupport() {
29 content::WindowedNotificationObserver ntp_observer(
30 chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
31 content::NotificationService::AllSources());
32 content::WindowedNotificationObserver overlay_observer(
33 chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED,
34 content::NotificationService::AllSources());
35 FocusOmnibox();
36 ntp_observer.Wait();
37 overlay_observer.Wait();
38 }
18 }; 39 };
19 40
20 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { 41 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) {
21 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 42 ASSERT_NO_FATAL_FAILURE(SetupInstant());
22 EXPECT_TRUE(instant()->extended_enabled_); 43 EXPECT_TRUE(instant()->extended_enabled_);
23 } 44 }
24 45
25 // Test that Instant is preloaded when the omnibox is focused. 46 // Test that Instant is preloaded when the omnibox is focused.
26 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { 47 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) {
27 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 48 ASSERT_NO_FATAL_FAILURE(SetupInstant());
28 49
29 // Explicitly unfocus the omnibox. 50 // Explicitly unfocus the omnibox.
30 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 51 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
31 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 52 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
32 53
33 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 54 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
34 EXPECT_FALSE(omnibox()->model()->has_focus()); 55 EXPECT_FALSE(omnibox()->model()->has_focus());
35 56
36 // Delete any existing preview. 57 // Delete any existing preview.
37 instant()->loader_.reset(); 58 instant()->overlay_.reset();
38 EXPECT_FALSE(instant()->GetPreviewContents()); 59 EXPECT_FALSE(instant()->GetPreviewContents());
39 60
40 // Refocus the omnibox. The InstantController should've preloaded Instant. 61 // Refocus the omnibox. The InstantController should've preloaded Instant.
41 FocusOmniboxAndWaitForInstantSupport(); 62 FocusOmniboxAndWaitForInstantSupport();
42 63
43 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 64 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
44 EXPECT_TRUE(omnibox()->model()->has_focus()); 65 EXPECT_TRUE(omnibox()->model()->has_focus());
45 66
46 content::WebContents* preview_tab = instant()->GetPreviewContents(); 67 content::WebContents* preview_tab = instant()->GetPreviewContents();
47 EXPECT_TRUE(preview_tab); 68 EXPECT_TRUE(preview_tab);
48 69
49 // Check that the page supports Instant, but it isn't showing. 70 // Check that the page supports Instant, but it isn't showing.
50 EXPECT_TRUE(instant()->loader_->supports_instant()); 71 EXPECT_TRUE(instant()->overlay_->supports_instant());
51 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); 72 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
52 EXPECT_TRUE(instant()->model()->mode().is_default()); 73 EXPECT_TRUE(instant()->model()->mode().is_default());
53 74
54 // Adding a new tab shouldn't delete or recreate the preview; otherwise, 75 // Adding a new tab shouldn't delete or recreate the preview; otherwise,
55 // what's the point of preloading? 76 // what's the point of preloading?
56 AddBlankTabAndShow(browser()); 77 AddBlankTabAndShow(browser());
57 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); 78 EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
58 79
59 // Unfocusing and refocusing the omnibox should also preserve the preview. 80 // Unfocusing and refocusing the omnibox should also preserve the preview.
60 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 81 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
(...skipping 12 matching lines...) Expand all
73 content::WebContents* preview_tab = instant()->GetPreviewContents(); 94 content::WebContents* preview_tab = instant()->GetPreviewContents();
74 EXPECT_TRUE(preview_tab); 95 EXPECT_TRUE(preview_tab);
75 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); 96 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
76 EXPECT_TRUE(instant()->model()->mode().is_default()); 97 EXPECT_TRUE(instant()->model()->mode().is_default());
77 98
78 // Typing in the omnibox should show the overlay. 99 // Typing in the omnibox should show the overlay.
79 SetOmniboxTextAndWaitForInstantToShow("query"); 100 SetOmniboxTextAndWaitForInstantToShow("query");
80 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); 101 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
81 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); 102 EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
82 } 103 }
104
105 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) {
106 // Setup Instant.
107 ASSERT_NO_FATAL_FAILURE(SetupInstant());
108 FocusOmniboxAndWaitForInstantSupport();
109
110 // NTP contents should be preloaded.
111 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
112 content::WebContents* ntp_contents = instant()->ntp_->contents();
113 EXPECT_TRUE(ntp_contents);
114 }
115
116 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) {
117 // Setup Instant.
118 ASSERT_NO_FATAL_FAILURE(SetupInstant());
119 FocusOmniboxAndWaitForInstantSupport();
120
121 // NTP contents should be preloaded.
122 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
123 content::WebContents* ntp_contents = instant()->ntp_->contents();
124 EXPECT_TRUE(ntp_contents);
125
126 // Open new tab. Preloaded NTP contents should have been used.
127 ui_test_utils::NavigateToURLWithDisposition(
128 browser(),
129 GURL(chrome::kChromeUINewTabURL),
130 NEW_FOREGROUND_TAB,
131 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
132 content::WebContents* active_tab =
133 browser()->tab_strip_model()->GetActiveWebContents();
134 EXPECT_EQ(ntp_contents, active_tab);
135 }
136
137 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) {
138 // Setup Instant.
139 ASSERT_NO_FATAL_FAILURE(SetupInstant());
140 FocusOmniboxAndWaitForInstantSupport();
141
142 // NTP contents should be preloaded.
143 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
144 content::WebContents* ntp_contents = instant()->ntp_->contents();
145 EXPECT_TRUE(ntp_contents);
146
147 // Open new tab. Preloaded NTP contents should have been used.
148 ui_test_utils::NavigateToURLWithDisposition(
149 browser(),
150 GURL(chrome::kChromeUINewTabURL),
151 CURRENT_TAB,
152 ui_test_utils::BROWSER_TEST_NONE);
153 content::WebContents* active_tab =
154 browser()->tab_strip_model()->GetActiveWebContents();
155 EXPECT_EQ(ntp_contents, active_tab);
156 }
157
158 // TODO(samarth): re-enable once omnibox focusing works.
159 //IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) {
160 // // Setup Instant.
161 // ASSERT_NO_FATAL_FAILURE(SetupInstant());
162 // FocusOmniboxAndWaitForInstantSupport();
163 //
164 // // Explicitly unfocus the omnibox.
165 // EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
166 // ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
167 // EXPECT_FALSE(omnibox()->model()->has_focus());
168 //
169 // // Open new tab. Preloaded NTP contents should have been used.
170 // ui_test_utils::NavigateToURLWithDisposition(
171 // browser(),
172 // GURL(chrome::kChromeUINewTabURL),
173 // NEW_FOREGROUND_TAB,
174 // ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
175 //
176 // // Omnibox should have focus.
177 // EXPECT_TRUE(omnibox()->model()->has_focus());
178 //}
179
180 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) {
181 // Setup Instant.
182 ASSERT_NO_FATAL_FAILURE(SetupInstant());
183 FocusOmniboxAndWaitForInstantSupport();
184
185 // Open new tab. Preloaded NTP contents should have been used.
186 ui_test_utils::NavigateToURLWithDisposition(
187 browser(),
188 GURL(chrome::kChromeUINewTabURL),
189 CURRENT_TAB,
190 ui_test_utils::BROWSER_TEST_NONE);
191
192 // Omnibox should be empty.
193 EXPECT_TRUE(omnibox()->GetText().empty());
194 }
195
196 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) {
197 ASSERT_NO_FATAL_FAILURE(SetupInstant());
198
199 // Focus omnibox and confirm overlay isn't shown.
200 FocusOmniboxAndWaitForInstantSupport();
201 content::WebContents* preview_tab = instant()->GetPreviewContents();
202 EXPECT_TRUE(preview_tab);
203 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
204 EXPECT_TRUE(instant()->model()->mode().is_default());
205
206 // Navigate to the NTP.
207 ui_test_utils::NavigateToURLWithDisposition(
208 browser(),
209 GURL(chrome::kChromeUINewTabURL),
210 CURRENT_TAB,
211 ui_test_utils::BROWSER_TEST_NONE);
212
213 // Typing in the omnibox should not show the overlay.
214 SetOmniboxText("query");
215 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
216 EXPECT_TRUE(instant()->model()->mode().is_default());
217 }
218
219 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) {
220 // Prior to setup no render process is dedicated to Instant.
221 InstantService* instant_service =
222 InstantServiceFactory::GetForProfile(browser()->profile());
223 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
224 EXPECT_EQ(0, instant_service->GetInstantProcessCount());
225
226 // Setup Instant.
227 ASSERT_NO_FATAL_FAILURE(SetupInstant());
228 FocusOmniboxAndWaitForInstantSupport();
229
230 // Now there should be a registered Instant render process.
231 EXPECT_LT(0, instant_service->GetInstantProcessCount());
232
233 // And the Instant overlay and ntp should live inside it.
234 content::WebContents* preview = instant()->GetPreviewContents();
235 EXPECT_TRUE(instant_service->IsInstantProcess(
236 preview->GetRenderProcessHost()->GetID()));
237 content::WebContents* ntp_contents = instant()->ntp_->contents();
238 EXPECT_TRUE(instant_service->IsInstantProcess(
239 ntp_contents->GetRenderProcessHost()->GetID()));
240
241 // Navigating to the NTP should use the Instant render process.
242 ui_test_utils::NavigateToURLWithDisposition(
243 browser(),
244 GURL(chrome::kChromeUINewTabURL),
245 CURRENT_TAB,
246 ui_test_utils::BROWSER_TEST_NONE);
247 content::WebContents* active_tab =
248 browser()->tab_strip_model()->GetActiveWebContents();
249 EXPECT_TRUE(instant_service->IsInstantProcess(
250 active_tab->GetRenderProcessHost()->GetID()));
251
252 // Navigating elsewhere should not use the Instant render process.
253 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
254 EXPECT_FALSE(instant_service->IsInstantProcess(
255 active_tab->GetRenderProcessHost()->GetID()));
256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698