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

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: Address comments. 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 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) {
159 // Setup Instant.
160 ASSERT_NO_FATAL_FAILURE(SetupInstant());
161 FocusOmniboxAndWaitForInstantSupport();
162
163 // Explicitly unfocus the omnibox.
164 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
165 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
166 EXPECT_FALSE(omnibox()->model()->has_focus());
167
168 // Open new tab. Preloaded NTP contents should have been used.
169 ui_test_utils::NavigateToURLWithDisposition(
170 browser(),
171 GURL(chrome::kChromeUINewTabURL),
172 NEW_FOREGROUND_TAB,
173 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
174
175 // Omnibox should have focus.
176 EXPECT_TRUE(omnibox()->model()->has_focus());
177 }
178
179 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) {
180 // Setup Instant.
181 ASSERT_NO_FATAL_FAILURE(SetupInstant());
182 FocusOmniboxAndWaitForInstantSupport();
183
184 // Open new tab. Preloaded NTP contents should have been used.
185 ui_test_utils::NavigateToURLWithDisposition(
186 browser(),
187 GURL(chrome::kChromeUINewTabURL),
188 CURRENT_TAB,
189 ui_test_utils::BROWSER_TEST_NONE);
190
191 // Omnibox should be empty.
192 EXPECT_TRUE(omnibox()->GetText().empty());
193 }
194
195 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) {
196 ASSERT_NO_FATAL_FAILURE(SetupInstant());
197
198 // Focus omnibox and confirm overlay isn't shown.
199 FocusOmniboxAndWaitForInstantSupport();
200 content::WebContents* preview_tab = instant()->GetPreviewContents();
201 EXPECT_TRUE(preview_tab);
202 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
203 EXPECT_TRUE(instant()->model()->mode().is_default());
204
205 // Navigate to the NTP.
206 ui_test_utils::NavigateToURLWithDisposition(
207 browser(),
208 GURL(chrome::kChromeUINewTabURL),
209 CURRENT_TAB,
210 ui_test_utils::BROWSER_TEST_NONE);
211
212 // Typing in the omnibox should not show the overlay.
213 SetOmniboxText("query");
214 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
215 EXPECT_TRUE(instant()->model()->mode().is_default());
216 }
217
218 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) {
219 // Prior to setup no render process is dedicated to Instant.
220 InstantService* instant_service =
221 InstantServiceFactory::GetForProfile(browser()->profile());
222 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
223 EXPECT_EQ(0, instant_service->GetInstantProcessCount());
224
225 // Setup Instant.
226 ASSERT_NO_FATAL_FAILURE(SetupInstant());
227 FocusOmniboxAndWaitForInstantSupport();
228
229 // Now there should be a registered Instant render process.
230 EXPECT_LT(0, instant_service->GetInstantProcessCount());
231
232 // And the Instant overlay and ntp should live inside it.
233 content::WebContents* preview = instant()->GetPreviewContents();
234 EXPECT_TRUE(instant_service->IsInstantProcess(
235 preview->GetRenderProcessHost()->GetID()));
236 content::WebContents* ntp_contents = instant()->ntp_->contents();
237 EXPECT_TRUE(instant_service->IsInstantProcess(
238 ntp_contents->GetRenderProcessHost()->GetID()));
239
240 // Navigating to the NTP should use the Instant render process.
241 ui_test_utils::NavigateToURLWithDisposition(
242 browser(),
243 GURL(chrome::kChromeUINewTabURL),
244 CURRENT_TAB,
245 ui_test_utils::BROWSER_TEST_NONE);
246 content::WebContents* active_tab =
247 browser()->tab_strip_model()->GetActiveWebContents();
248 EXPECT_TRUE(instant_service->IsInstantProcess(
249 active_tab->GetRenderProcessHost()->GetID()));
250
251 // Navigating elsewhere should not use the Instant render process.
252 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
253 EXPECT_FALSE(instant_service->IsInstantProcess(
254 active_tab->GetRenderProcessHost()->GetID()));
255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698