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

Side by Side Diff: chrome/browser/ui/search/local_ntp_browsertest.cc

Issue 2857023003: Instant/LocalNTP tests cleanup (Closed)
Patch Set: skip incompatible tests if --site-per-process Created 3 years, 7 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/optional.h" 12 #include "base/optional.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h" 17 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h"
19 #include "chrome/browser/search/one_google_bar/one_google_bar_fetcher.h" 18 #include "chrome/browser/search/one_google_bar/one_google_bar_fetcher.h"
20 #include "chrome/browser/search/one_google_bar/one_google_bar_service.h" 19 #include "chrome/browser/search/one_google_bar/one_google_bar_service.h"
21 #include "chrome/browser/search/one_google_bar/one_google_bar_service_factory.h" 20 #include "chrome/browser/search/one_google_bar/one_google_bar_service_factory.h"
22 #include "chrome/browser/search/search.h" 21 #include "chrome/browser/search/search.h"
23 #include "chrome/browser/search_engines/template_url_service_factory.h" 22 #include "chrome/browser/search_engines/template_url_service_factory.h"
24 #include "chrome/browser/signin/signin_manager_factory.h" 23 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_commands.h" 25 #include "chrome/browser/ui/browser_commands.h"
26 #include "chrome/browser/ui/search/instant_test_base.h"
26 #include "chrome/browser/ui/search/instant_test_utils.h" 27 #include "chrome/browser/ui/search/instant_test_utils.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "chrome/test/base/in_process_browser_test.h" 31 #include "chrome/test/base/in_process_browser_test.h"
31 #include "chrome/test/base/interactive_test_utils.h"
32 #include "chrome/test/base/ui_test_utils.h" 32 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/keyed_service/content/browser_context_dependency_manager.h" 33 #include "components/keyed_service/content/browser_context_dependency_manager.h"
34 #include "components/omnibox/browser/omnibox_edit_model.h"
35 #include "components/omnibox/browser/omnibox_view.h"
36 #include "components/omnibox/common/omnibox_focus_state.h"
37 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
38 #include "components/search_engines/template_url.h" 35 #include "components/search_engines/template_url.h"
39 #include "components/search_engines/template_url_data.h" 36 #include "components/search_engines/template_url_data.h"
40 #include "components/search_engines/template_url_service.h" 37 #include "components/search_engines/template_url_service.h"
38 #include "components/signin/core/browser/signin_manager.h"
41 #include "content/public/browser/navigation_entry.h" 39 #include "content/public/browser/navigation_entry.h"
42 #include "content/public/browser/notification_service.h"
43 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
44 #include "content/public/common/content_switches.h" 41 #include "content/public/common/content_switches.h"
45 #include "content/public/test/browser_test_utils.h"
46 #include "content/public/test/test_navigation_observer.h" 42 #include "content/public/test/test_navigation_observer.h"
47 #include "content/public/test/test_utils.h" 43 #include "content/public/test/test_utils.h"
48 #include "net/test/embedded_test_server/embedded_test_server.h" 44 #include "net/test/embedded_test_server/embedded_test_server.h"
49 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
50 #include "ui/gfx/geometry/point.h"
51 #include "ui/gfx/geometry/rect.h"
52 #include "ui/gfx/geometry/vector2d.h"
53 46
54 namespace { 47 namespace {
55 48
56 content::WebContents* OpenNewTab(Browser* browser, const GURL& url) { 49 content::WebContents* OpenNewTab(Browser* browser, const GURL& url) {
57 ui_test_utils::NavigateToURLWithDisposition( 50 ui_test_utils::NavigateToURLWithDisposition(
58 browser, url, WindowOpenDisposition::NEW_FOREGROUND_TAB, 51 browser, url, WindowOpenDisposition::NEW_FOREGROUND_TAB,
59 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | 52 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
60 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 53 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
61 return browser->tab_strip_model()->GetActiveWebContents(); 54 return browser->tab_strip_model()->GetActiveWebContents();
62 } 55 }
63 56
64 // Switches the browser language to French, and returns true iff successful. 57 // Switches the browser language to French, and returns true iff successful.
65 bool SwitchToFrench() { 58 bool SwitchToFrench() {
66 base::ThreadRestrictions::ScopedAllowIO allow_io; 59 base::ThreadRestrictions::ScopedAllowIO allow_io;
67 // Make sure the default language is not French. 60 // Make sure the default language is not French.
68 std::string default_locale = g_browser_process->GetApplicationLocale(); 61 std::string default_locale = g_browser_process->GetApplicationLocale();
69 EXPECT_NE("fr", default_locale); 62 EXPECT_NE("fr", default_locale);
70 63
71 // Switch browser language to French. 64 // Switch browser language to French.
72 std::string loaded_locale = 65 std::string loaded_locale =
73 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr"); 66 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr");
74 67
75 return loaded_locale == "fr"; 68 return loaded_locale == "fr";
76 } 69 }
77 70
78 } // namespace 71 } // namespace
79 72
80 // A test class that sets up local_ntp_browsertest.html (which is mostly a copy 73 // A test class that sets up local_ntp_browsertest.html (which is mostly a copy
81 // of the real local_ntp.html) as the NTP URL. 74 // of the real local_ntp.html) as the NTP URL.
82 class LocalNTPTest : public InProcessBrowserTest, 75 class LocalNTPTest : public InProcessBrowserTest, public InstantTestBase {
83 public InstantTestBase {
84 public: 76 public:
85 LocalNTPTest() {} 77 LocalNTPTest() {}
86 78
87 GURL other_url() { return https_test_server().GetURL("/simple.html"); } 79 GURL other_url() { return https_test_server().GetURL("/simple.html"); }
88 80
89 protected: 81 protected:
90 void SetUpInProcessBrowserTestFixture() override { 82 void SetUpInProcessBrowserTestFixture() override {
91 ASSERT_TRUE(https_test_server().Start()); 83 ASSERT_TRUE(https_test_server().Start());
92 GURL instant_url = 84 GURL instant_url =
93 https_test_server().GetURL("/instant_extended.html?strk=1&"); 85 https_test_server().GetURL("/instant_extended.html?strk=1&");
94 GURL ntp_url = 86 GURL ntp_url =
95 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&"); 87 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&");
96 InstantTestBase::Init(instant_url, ntp_url, false); 88 InstantTestBase::Init(instant_url, ntp_url, false);
97 } 89 }
98 }; 90 };
99 91
100 // This runs a bunch of pure JS-side tests, i.e. those that don't require any 92 // This runs a bunch of pure JS-side tests, i.e. those that don't require any
101 // interaction from the native side. 93 // interaction from the native side.
102 IN_PROC_BROWSER_TEST_F(LocalNTPTest, SimpleJavascriptTests) { 94 IN_PROC_BROWSER_TEST_F(LocalNTPTest, SimpleJavascriptTests) {
95 if (content::AreAllSitesIsolatedForTesting()) {
96 LOG(ERROR) << "LocalNTPTest.SimpleJavascriptTests doesn't work in "
97 "--site-per-process mode yet, see crbug.com/695221.";
98 return;
99 }
100
103 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 101 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
104 FocusOmnibox();
105 102
106 content::WebContents* active_tab = OpenNewTab(browser(), ntp_url()); 103 content::WebContents* active_tab = OpenNewTab(browser(), ntp_url());
107 ASSERT_TRUE(search::IsInstantNTP(active_tab)); 104 ASSERT_TRUE(search::IsInstantNTP(active_tab));
108 105
109 bool success = false; 106 bool success = false;
110 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success)); 107 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
108 active_tab, "!!runSimpleTests()", &success));
111 EXPECT_TRUE(success); 109 EXPECT_TRUE(success);
112 } 110 }
113 111
114 IN_PROC_BROWSER_TEST_F(LocalNTPTest, EmbeddedSearchAPIOnlyAvailableOnNTP) { 112 IN_PROC_BROWSER_TEST_F(LocalNTPTest, EmbeddedSearchAPIOnlyAvailableOnNTP) {
115 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 113 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
116 FocusOmnibox();
117 114
118 // Open an NTP. 115 // Open an NTP.
119 content::WebContents* active_tab = OpenNewTab(browser(), ntp_url()); 116 content::WebContents* active_tab = OpenNewTab(browser(), ntp_url());
120 ASSERT_TRUE(search::IsInstantNTP(active_tab)); 117 ASSERT_TRUE(search::IsInstantNTP(active_tab));
121 // Check that the embeddedSearch API is available. 118 // Check that the embeddedSearch API is available.
122 bool result = false; 119 bool result = false;
123 ASSERT_TRUE( 120 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
124 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); 121 active_tab, "!!window.chrome.embeddedSearch", &result));
125 EXPECT_TRUE(result); 122 EXPECT_TRUE(result);
126 123
127 // Navigate somewhere else in the same tab. 124 // Navigate somewhere else in the same tab.
128 ui_test_utils::NavigateToURLWithDisposition( 125 ui_test_utils::NavigateToURLWithDisposition(
129 browser(), other_url(), WindowOpenDisposition::CURRENT_TAB, 126 browser(), other_url(), WindowOpenDisposition::CURRENT_TAB,
130 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 127 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
131 ASSERT_FALSE(search::IsInstantNTP(active_tab)); 128 ASSERT_FALSE(search::IsInstantNTP(active_tab));
132 // Now the embeddedSearch API should have gone away. 129 // Now the embeddedSearch API should have gone away.
133 ASSERT_TRUE( 130 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
134 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); 131 active_tab, "!!window.chrome.embeddedSearch", &result));
135 EXPECT_FALSE(result); 132 EXPECT_FALSE(result);
136 133
137 // Navigate back to the NTP. 134 // Navigate back to the NTP.
138 content::TestNavigationObserver back_observer(active_tab); 135 content::TestNavigationObserver back_observer(active_tab);
139 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); 136 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB);
140 back_observer.Wait(); 137 back_observer.Wait();
141 // The API should be back. 138 // The API should be back.
142 ASSERT_TRUE( 139 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
143 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); 140 active_tab, "!!window.chrome.embeddedSearch", &result));
144 EXPECT_TRUE(result); 141 EXPECT_TRUE(result);
145 142
146 // Navigate forward to the non-NTP page. 143 // Navigate forward to the non-NTP page.
147 content::TestNavigationObserver fwd_observer(active_tab); 144 content::TestNavigationObserver fwd_observer(active_tab);
148 chrome::GoForward(browser(), WindowOpenDisposition::CURRENT_TAB); 145 chrome::GoForward(browser(), WindowOpenDisposition::CURRENT_TAB);
149 fwd_observer.Wait(); 146 fwd_observer.Wait();
150 // The API should be gone. 147 // The API should be gone.
151 ASSERT_TRUE( 148 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
152 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); 149 active_tab, "!!window.chrome.embeddedSearch", &result));
153 EXPECT_FALSE(result); 150 EXPECT_FALSE(result);
154 151
155 // Navigate to a new NTP instance. 152 // Navigate to a new NTP instance.
156 ui_test_utils::NavigateToURLWithDisposition( 153 ui_test_utils::NavigateToURLWithDisposition(
157 browser(), ntp_url(), WindowOpenDisposition::CURRENT_TAB, 154 browser(), ntp_url(), WindowOpenDisposition::CURRENT_TAB,
158 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 155 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
159 ASSERT_TRUE(search::IsInstantNTP(active_tab)); 156 ASSERT_TRUE(search::IsInstantNTP(active_tab));
160 // Now the API should be available again. 157 // Now the API should be available again.
161 ASSERT_TRUE( 158 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
162 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); 159 active_tab, "!!window.chrome.embeddedSearch", &result));
163 EXPECT_TRUE(result); 160 EXPECT_TRUE(result);
164 } 161 }
165 162
166 IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) {
167 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
168 FocusOmnibox();
169
170 content::WebContents* active_tab = OpenNewTab(browser(), ntp_url());
171 ASSERT_TRUE(search::IsInstantNTP(active_tab));
172
173 // This is required to make the mouse events we send below arrive at the right
174 // place. It *should* be the default for all interactive_ui_tests anyway, but
175 // on Mac it isn't; see crbug.com/641969.
176 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
177
178 bool result = false;
179 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!setupAdvancedTest()", &result));
180 ASSERT_TRUE(result);
181
182 // Get the position of the fakebox on the page.
183 double fakebox_x = 0;
184 ASSERT_TRUE(GetDoubleFromJS(active_tab, "getFakeboxPositionX()", &fakebox_x));
185 double fakebox_y = 0;
186 ASSERT_TRUE(GetDoubleFromJS(active_tab, "getFakeboxPositionY()", &fakebox_y));
187
188 // Move the mouse over the fakebox.
189 gfx::Vector2d fakebox_pos(static_cast<int>(std::ceil(fakebox_x)),
190 static_cast<int>(std::ceil(fakebox_y)));
191 gfx::Point origin = active_tab->GetContainerBounds().origin();
192 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(origin + fakebox_pos +
193 gfx::Vector2d(1, 1)));
194
195 // Click on the fakebox, and wait for the omnibox to receive invisible focus.
196 // Note that simply waiting for the first OMNIBOX_FOCUS_CHANGED notification
197 // is not sufficient: If the omnibox had focus before, it will first lose the
198 // focus before gaining invisible focus.
199 ASSERT_NE(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state());
200 content::WindowedNotificationObserver focus_observer(
201 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED,
202 base::Bind(
203 [](const OmniboxEditModel* omnibox_model) {
204 return omnibox_model->focus_state() == OMNIBOX_FOCUS_INVISIBLE;
205 },
206 omnibox()->model()));
207
208 ASSERT_TRUE(
209 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::DOWN));
210 ASSERT_TRUE(
211 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP));
212
213 focus_observer.Wait();
214 EXPECT_EQ(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state());
215
216 // The fakebox should now also have focus.
217 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsFocused()", &result));
218 EXPECT_TRUE(result);
219
220 // Type "a".
221 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
222 browser(), ui::KeyboardCode::VKEY_A,
223 /*control=*/false, /*shift=*/false, /*alt=*/false, /*command=*/false));
224
225 // The omnibox should have received visible focus.
226 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state());
227 // ...and the typed text should have arrived there.
228 EXPECT_EQ("a", GetOmniboxText());
229
230 // On the JS side, the fakebox should have been hidden.
231 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsVisible()", &result));
232 EXPECT_FALSE(result);
233 }
234
235 namespace { 163 namespace {
236 164
237 // Returns the RenderFrameHost corresponding to the most visited iframe in the 165 // Returns the RenderFrameHost corresponding to the most visited iframe in the
238 // given |tab|. |tab| must correspond to an NTP. 166 // given |tab|. |tab| must correspond to an NTP.
239 content::RenderFrameHost* GetMostVisitedIframe(content::WebContents* tab) { 167 content::RenderFrameHost* GetMostVisitedIframe(content::WebContents* tab) {
240 CHECK_EQ(2u, tab->GetAllFrames().size()); 168 CHECK_EQ(2u, tab->GetAllFrames().size());
241 for (content::RenderFrameHost* frame : tab->GetAllFrames()) { 169 for (content::RenderFrameHost* frame : tab->GetAllFrames()) {
242 if (frame != tab->GetMainFrame()) { 170 if (frame != tab->GetMainFrame()) {
243 return frame; 171 return frame;
244 } 172 }
245 } 173 }
246 NOTREACHED(); 174 NOTREACHED();
247 return nullptr; 175 return nullptr;
248 } 176 }
249 177
250 } // namespace 178 } // namespace
251 179
252 IN_PROC_BROWSER_TEST_F(LocalNTPTest, LoadsIframe) { 180 IN_PROC_BROWSER_TEST_F(LocalNTPTest, LoadsIframe) {
181 if (content::AreAllSitesIsolatedForTesting()) {
182 LOG(ERROR) << "LocalNTPTest.LoadsIframe doesn't work in "
183 "--site-per-process mode yet, see crbug.com/695221.";
184 return;
185 }
186
253 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 187 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
254 FocusOmnibox();
255 188
256 content::WebContents* active_tab = OpenNewTab(browser(), ntp_url()); 189 content::WebContents* active_tab = OpenNewTab(browser(), ntp_url());
257 ASSERT_TRUE(search::IsInstantNTP(active_tab)); 190 ASSERT_TRUE(search::IsInstantNTP(active_tab));
258 191
259 content::DOMMessageQueue msg_queue; 192 content::DOMMessageQueue msg_queue;
260 193
261 bool result = false; 194 bool result = false;
262 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!setupAdvancedTest(true)", &result)); 195 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
196 active_tab, "!!setupAdvancedTest(true)", &result));
263 ASSERT_TRUE(result); 197 ASSERT_TRUE(result);
264 198
265 // Wait for the MV iframe to load. 199 // Wait for the MV iframe to load.
266 std::string message; 200 std::string message;
267 // First get rid of the "true" message from the GetBoolFromJS call above. 201 // First get rid of the "true" message from the GetBoolFromJS call above.
268 ASSERT_TRUE(msg_queue.PopMessage(&message)); 202 ASSERT_TRUE(msg_queue.PopMessage(&message));
269 ASSERT_EQ("true", message); 203 ASSERT_EQ("true", message);
270 // Now wait for the "loaded" message. 204 // Now wait for the "loaded" message.
271 ASSERT_TRUE(msg_queue.WaitForMessage(&message)); 205 ASSERT_TRUE(msg_queue.WaitForMessage(&message));
272 ASSERT_EQ("\"loaded\"", message); 206 ASSERT_EQ("\"loaded\"", message);
273 207
274 // Get the iframe and check that the tiles loaded correctly. 208 // Get the iframe and check that the tiles loaded correctly.
275 content::RenderFrameHost* iframe = GetMostVisitedIframe(active_tab); 209 content::RenderFrameHost* iframe = GetMostVisitedIframe(active_tab);
276 210
277 // Get the total number of (non-empty) tiles from the iframe. 211 // Get the total number of (non-empty) tiles from the iframe.
278 int total_thumbs = 0; 212 int total_thumbs = 0;
279 ASSERT_TRUE(GetIntFromJS( 213 ASSERT_TRUE(instant_test_utils::GetIntFromJS(
280 iframe, "document.querySelectorAll('.mv-thumb').length", &total_thumbs)); 214 iframe, "document.querySelectorAll('.mv-thumb').length", &total_thumbs));
281 // Also get how many of the tiles succeeded and failed in loading their 215 // Also get how many of the tiles succeeded and failed in loading their
282 // thumbnail images. 216 // thumbnail images.
283 int succeeded_imgs = 0; 217 int succeeded_imgs = 0;
284 ASSERT_TRUE(GetIntFromJS(iframe, 218 ASSERT_TRUE(instant_test_utils::GetIntFromJS(
285 "document.querySelectorAll('.mv-thumb img').length", 219 iframe, "document.querySelectorAll('.mv-thumb img').length",
286 &succeeded_imgs)); 220 &succeeded_imgs));
287 int failed_imgs = 0; 221 int failed_imgs = 0;
288 ASSERT_TRUE(GetIntFromJS( 222 ASSERT_TRUE(instant_test_utils::GetIntFromJS(
289 iframe, "document.querySelectorAll('.mv-thumb.failed-img').length", 223 iframe, "document.querySelectorAll('.mv-thumb.failed-img').length",
290 &failed_imgs)); 224 &failed_imgs));
291 225
292 // First, sanity check that the numbers line up (none of the css classes was 226 // First, sanity check that the numbers line up (none of the css classes was
293 // renamed, etc). 227 // renamed, etc).
294 EXPECT_EQ(total_thumbs, succeeded_imgs + failed_imgs); 228 EXPECT_EQ(total_thumbs, succeeded_imgs + failed_imgs);
295 229
296 // Since we're in a non-signed-in, fresh profile with no history, there should 230 // Since we're in a non-signed-in, fresh profile with no history, there should
297 // be the default TopSites tiles (see history::PrepopulatedPage). 231 // be the default TopSites tiles (see history::PrepopulatedPage).
298 // Check that there is at least one tile, and that all of them loaded their 232 // Check that there is at least one tile, and that all of them loaded their
(...skipping 21 matching lines...) Expand all
320 LOG(ERROR) << "Failed switching to French language, aborting test."; 254 LOG(ERROR) << "Failed switching to French language, aborting test.";
321 return; 255 return;
322 } 256 }
323 257
324 g_browser_process->SetApplicationLocale(loaded_locale); 258 g_browser_process->SetApplicationLocale(loaded_locale);
325 PrefService* prefs = g_browser_process->local_state(); 259 PrefService* prefs = g_browser_process->local_state();
326 prefs->SetString(prefs::kApplicationLocale, loaded_locale); 260 prefs->SetString(prefs::kApplicationLocale, loaded_locale);
327 261
328 // Setup Instant. 262 // Setup Instant.
329 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 263 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
330 FocusOmnibox();
331 264
332 // Open a new tab. 265 // Open a new tab.
333 content::WebContents* active_tab = 266 content::WebContents* active_tab =
334 OpenNewTab(browser(), GURL(chrome::kChromeUINewTabURL)); 267 OpenNewTab(browser(), GURL(chrome::kChromeUINewTabURL));
335 268
336 // Verify that the NTP is in French. 269 // Verify that the NTP is in French.
337 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); 270 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle());
338 } 271 }
339 272
340 // In contrast to LocalNTPTest, this one doesn't set up any special NTP 273 // In contrast to LocalNTPTest, this one doesn't set up any special NTP
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 372
440 void set_one_google_bar_data( 373 void set_one_google_bar_data(
441 const base::Optional<OneGoogleBarData>& one_google_bar_data) { 374 const base::Optional<OneGoogleBarData>& one_google_bar_data) {
442 one_google_bar_data_ = one_google_bar_data; 375 one_google_bar_data_ = one_google_bar_data;
443 } 376 }
444 377
445 private: 378 private:
446 base::Optional<OneGoogleBarData> one_google_bar_data_; 379 base::Optional<OneGoogleBarData> one_google_bar_data_;
447 }; 380 };
448 381
449 // TODO(treib): This inherits from InstantTestBase only for GetBoolFromJS, which 382 class LocalNTPOneGoogleBarSmokeTest : public InProcessBrowserTest {
450 // should just be a global helper somewhere.
451 class LocalNTPOneGoogleBarSmokeTest : public InProcessBrowserTest,
452 public InstantTestBase {
453 public: 383 public:
454 LocalNTPOneGoogleBarSmokeTest() {} 384 LocalNTPOneGoogleBarSmokeTest() {}
455 385
456 protected: 386 protected:
457 void SetUpCommandLine(base::CommandLine* cmdline) override { 387 void SetUpCommandLine(base::CommandLine* cmdline) override {
458 cmdline->AppendSwitchASCII(switches::kEnableFeatures, 388 cmdline->AppendSwitchASCII(switches::kEnableFeatures,
459 "UseGoogleLocalNtp,OneGoogleBarOnLocalNtp"); 389 "UseGoogleLocalNtp,OneGoogleBarOnLocalNtp");
460 } 390 }
461 391
462 void SetUpInProcessBrowserTestFixture() override { 392 void SetUpInProcessBrowserTestFixture() override {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); 467 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
538 ASSERT_TRUE(search::IsInstantNTP(active_tab)); 468 ASSERT_TRUE(search::IsInstantNTP(active_tab));
539 ASSERT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 469 ASSERT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
540 active_tab->GetController().GetVisibleEntry()->GetURL()); 470 active_tab->GetController().GetVisibleEntry()->GetURL());
541 // Make sure the OGB is finished loading. 471 // Make sure the OGB is finished loading.
542 console_observer.Wait(); 472 console_observer.Wait();
543 473
544 EXPECT_EQ("ogb-done", console_observer.message()); 474 EXPECT_EQ("ogb-done", console_observer.message());
545 475
546 bool in_head_ran = false; 476 bool in_head_ran = false;
547 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!window.inHeadRan", &in_head_ran)); 477 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
478 active_tab, "!!window.inHeadRan", &in_head_ran));
548 EXPECT_TRUE(in_head_ran); 479 EXPECT_TRUE(in_head_ran);
549 bool after_bar_ran = false; 480 bool after_bar_ran = false;
550 ASSERT_TRUE( 481 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
551 GetBoolFromJS(active_tab, "!!window.afterBarRan", &after_bar_ran)); 482 active_tab, "!!window.afterBarRan", &after_bar_ran));
552 EXPECT_TRUE(after_bar_ran); 483 EXPECT_TRUE(after_bar_ran);
553 } 484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698