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

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: Undo to fix blacklisting. 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
« no previous file with comments | « chrome/browser/instant/instant_controller.cc ('k') | chrome/browser/instant/instant_loader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 }
20 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 }
41
21 std::string GetOmniboxText() { 42 std::string GetOmniboxText() {
22 return UTF16ToUTF8(omnibox()->GetText()); 43 return UTF16ToUTF8(omnibox()->GetText());
23 } 44 }
24 45
25 void SendDownArrow() { 46 void SendDownArrow() {
26 omnibox()->model()->OnUpOrDownKeyPressed(1); 47 omnibox()->model()->OnUpOrDownKeyPressed(1);
27 // Wait for JavaScript to run the key handler by executing a blank script. 48 // Wait for JavaScript to run the key handler by executing a blank script.
28 EXPECT_TRUE(ExecuteScript(std::string())); 49 EXPECT_TRUE(ExecuteScript(std::string()));
29 } 50 }
30 51
(...skipping 14 matching lines...) Expand all
45 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 66 ASSERT_NO_FATAL_FAILURE(SetupInstant());
46 67
47 // Explicitly unfocus the omnibox. 68 // Explicitly unfocus the omnibox.
48 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 69 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
49 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 70 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
50 71
51 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 72 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
52 EXPECT_FALSE(omnibox()->model()->has_focus()); 73 EXPECT_FALSE(omnibox()->model()->has_focus());
53 74
54 // Delete any existing preview. 75 // Delete any existing preview.
55 instant()->loader_.reset(); 76 instant()->overlay_.reset();
56 EXPECT_FALSE(instant()->GetPreviewContents()); 77 EXPECT_FALSE(instant()->GetPreviewContents());
57 78
58 // Refocus the omnibox. The InstantController should've preloaded Instant. 79 // Refocus the omnibox. The InstantController should've preloaded Instant.
59 FocusOmniboxAndWaitForInstantSupport(); 80 FocusOmniboxAndWaitForInstantSupport();
60 81
61 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 82 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
62 EXPECT_TRUE(omnibox()->model()->has_focus()); 83 EXPECT_TRUE(omnibox()->model()->has_focus());
63 84
64 content::WebContents* preview_tab = instant()->GetPreviewContents(); 85 content::WebContents* preview_tab = instant()->GetPreviewContents();
65 EXPECT_TRUE(preview_tab); 86 EXPECT_TRUE(preview_tab);
66 87
67 // Check that the page supports Instant, but it isn't showing. 88 // Check that the page supports Instant, but it isn't showing.
68 EXPECT_TRUE(instant()->loader_->supports_instant()); 89 EXPECT_TRUE(instant()->overlay_->supports_instant());
69 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); 90 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
70 EXPECT_TRUE(instant()->model()->mode().is_default()); 91 EXPECT_TRUE(instant()->model()->mode().is_default());
71 92
72 // Adding a new tab shouldn't delete or recreate the preview; otherwise, 93 // Adding a new tab shouldn't delete or recreate the preview; otherwise,
73 // what's the point of preloading? 94 // what's the point of preloading?
74 AddBlankTabAndShow(browser()); 95 AddBlankTabAndShow(browser());
75 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); 96 EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
76 97
77 // Unfocusing and refocusing the omnibox should also preserve the preview. 98 // Unfocusing and refocusing the omnibox should also preserve the preview.
78 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 99 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 182
162 SendDownArrow(); 183 SendDownArrow();
163 EXPECT_EQ("result 1", GetOmniboxText()); 184 EXPECT_EQ("result 1", GetOmniboxText());
164 SendDownArrow(); 185 SendDownArrow();
165 EXPECT_EQ("result 2", GetOmniboxText()); 186 EXPECT_EQ("result 2", GetOmniboxText());
166 SendUpArrow(); 187 SendUpArrow();
167 EXPECT_EQ("result 1", GetOmniboxText()); 188 EXPECT_EQ("result 1", GetOmniboxText());
168 SendUpArrow(); 189 SendUpArrow();
169 EXPECT_EQ("hello", GetOmniboxText()); 190 EXPECT_EQ("hello", GetOmniboxText());
170 } 191 }
192
193 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) {
194 // Setup Instant.
195 ASSERT_NO_FATAL_FAILURE(SetupInstant());
196 FocusOmniboxAndWaitForInstantSupport();
197
198 // NTP contents should be preloaded.
199 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
200 content::WebContents* ntp_contents = instant()->ntp_->contents();
201 EXPECT_TRUE(ntp_contents);
202 }
203
204 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) {
205 // Setup Instant.
206 ASSERT_NO_FATAL_FAILURE(SetupInstant());
207 FocusOmniboxAndWaitForInstantSupport();
208
209 // NTP contents should be preloaded.
210 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
211 content::WebContents* ntp_contents = instant()->ntp_->contents();
212 EXPECT_TRUE(ntp_contents);
213
214 // Open new tab. Preloaded NTP contents should have been used.
215 ui_test_utils::NavigateToURLWithDisposition(
216 browser(),
217 GURL(chrome::kChromeUINewTabURL),
218 NEW_FOREGROUND_TAB,
219 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
220 content::WebContents* active_tab =
221 browser()->tab_strip_model()->GetActiveWebContents();
222 EXPECT_EQ(ntp_contents, active_tab);
223 }
224
225 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) {
226 // Setup Instant.
227 ASSERT_NO_FATAL_FAILURE(SetupInstant());
228 FocusOmniboxAndWaitForInstantSupport();
229
230 // NTP contents should be preloaded.
231 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
232 content::WebContents* ntp_contents = instant()->ntp_->contents();
233 EXPECT_TRUE(ntp_contents);
234
235 // Open new tab. Preloaded NTP contents should have been used.
236 ui_test_utils::NavigateToURLWithDisposition(
237 browser(),
238 GURL(chrome::kChromeUINewTabURL),
239 CURRENT_TAB,
240 ui_test_utils::BROWSER_TEST_NONE);
241 content::WebContents* active_tab =
242 browser()->tab_strip_model()->GetActiveWebContents();
243 EXPECT_EQ(ntp_contents, active_tab);
244 }
245
246 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) {
247 // Setup Instant.
248 ASSERT_NO_FATAL_FAILURE(SetupInstant());
249 FocusOmniboxAndWaitForInstantSupport();
250
251 // Explicitly unfocus the omnibox.
252 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
253 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
254 EXPECT_FALSE(omnibox()->model()->has_focus());
255
256 // Open new tab. Preloaded NTP contents should have been used.
257 ui_test_utils::NavigateToURLWithDisposition(
258 browser(),
259 GURL(chrome::kChromeUINewTabURL),
260 NEW_FOREGROUND_TAB,
261 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
262
263 // Omnibox should have focus.
264 EXPECT_TRUE(omnibox()->model()->has_focus());
265 }
266
267 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) {
268 // Setup Instant.
269 ASSERT_NO_FATAL_FAILURE(SetupInstant());
270 FocusOmniboxAndWaitForInstantSupport();
271
272 // Open new tab. Preloaded NTP contents should have been used.
273 ui_test_utils::NavigateToURLWithDisposition(
274 browser(),
275 GURL(chrome::kChromeUINewTabURL),
276 CURRENT_TAB,
277 ui_test_utils::BROWSER_TEST_NONE);
278
279 // Omnibox should be empty.
280 EXPECT_TRUE(omnibox()->GetText().empty());
281 }
282
283 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) {
284 ASSERT_NO_FATAL_FAILURE(SetupInstant());
285
286 // Focus omnibox and confirm overlay isn't shown.
287 FocusOmniboxAndWaitForInstantSupport();
288 content::WebContents* preview_tab = instant()->GetPreviewContents();
289 EXPECT_TRUE(preview_tab);
290 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
291 EXPECT_TRUE(instant()->model()->mode().is_default());
292
293 // Navigate to the NTP.
294 ui_test_utils::NavigateToURLWithDisposition(
295 browser(),
296 GURL(chrome::kChromeUINewTabURL),
297 CURRENT_TAB,
298 ui_test_utils::BROWSER_TEST_NONE);
299
300 // Typing in the omnibox should not show the overlay.
301 SetOmniboxText("query");
302 EXPECT_FALSE(instant()->IsPreviewingSearchResults());
303 EXPECT_TRUE(instant()->model()->mode().is_default());
304 }
305
306 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) {
307 // Prior to setup no render process is dedicated to Instant.
308 InstantService* instant_service =
309 InstantServiceFactory::GetForProfile(browser()->profile());
310 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
311 EXPECT_EQ(0, instant_service->GetInstantProcessCount());
312
313 // Setup Instant.
314 ASSERT_NO_FATAL_FAILURE(SetupInstant());
315 FocusOmniboxAndWaitForInstantSupport();
316
317 // Now there should be a registered Instant render process.
318 EXPECT_LT(0, instant_service->GetInstantProcessCount());
319
320 // And the Instant overlay and ntp should live inside it.
321 content::WebContents* preview = instant()->GetPreviewContents();
322 EXPECT_TRUE(instant_service->IsInstantProcess(
323 preview->GetRenderProcessHost()->GetID()));
324 content::WebContents* ntp_contents = instant()->ntp_->contents();
325 EXPECT_TRUE(instant_service->IsInstantProcess(
326 ntp_contents->GetRenderProcessHost()->GetID()));
327
328 // Navigating to the NTP should use the Instant render process.
329 ui_test_utils::NavigateToURLWithDisposition(
330 browser(),
331 GURL(chrome::kChromeUINewTabURL),
332 CURRENT_TAB,
333 ui_test_utils::BROWSER_TEST_NONE);
334 content::WebContents* active_tab =
335 browser()->tab_strip_model()->GetActiveWebContents();
336 EXPECT_TRUE(instant_service->IsInstantProcess(
337 active_tab->GetRenderProcessHost()->GetID()));
338
339 // Navigating elsewhere should not use the Instant render process.
340 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
341 EXPECT_FALSE(instant_service->IsInstantProcess(
342 active_tab->GetRenderProcessHost()->GetID()));
343 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.cc ('k') | chrome/browser/instant/instant_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698