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

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

Powered by Google App Engine
This is Rietveld 408576698