OLD | NEW |
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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
9 #include "chrome/browser/ui/search/instant_test_utils.h" | 9 #include "chrome/browser/ui/search/instant_test_utils.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/interactive_test_utils.h" | 14 #include "chrome/test/base/interactive_test_utils.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
16 #include "components/omnibox/browser/omnibox_edit_model.h" | 16 #include "components/omnibox/browser/omnibox_edit_model.h" |
17 #include "components/omnibox/browser/omnibox_view.h" | 17 #include "components/omnibox/browser/omnibox_view.h" |
18 #include "components/omnibox/common/omnibox_focus_state.h" | 18 #include "components/omnibox/common/omnibox_focus_state.h" |
19 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/test/browser_test_utils.h" |
22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
23 #include "net/test/embedded_test_server/embedded_test_server.h" | 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/gfx/geometry/point.h" | 26 #include "ui/gfx/geometry/point.h" |
26 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
27 #include "ui/gfx/geometry/vector2d.h" | 28 #include "ui/gfx/geometry/vector2d.h" |
28 | 29 |
29 class LocalNTPTest : public InProcessBrowserTest, | 30 class LocalNTPTest : public InProcessBrowserTest, |
30 public InstantTestBase { | 31 public InstantTestBase { |
31 public: | 32 public: |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // The omnibox should have received visible focus. | 129 // The omnibox should have received visible focus. |
129 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state()); | 130 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state()); |
130 // ...and the typed text should have arrived there. | 131 // ...and the typed text should have arrived there. |
131 EXPECT_EQ("a", GetOmniboxText()); | 132 EXPECT_EQ("a", GetOmniboxText()); |
132 | 133 |
133 // On the JS side, the fakebox should have been hidden. | 134 // On the JS side, the fakebox should have been hidden. |
134 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsVisible()", &result)); | 135 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsVisible()", &result)); |
135 EXPECT_FALSE(result); | 136 EXPECT_FALSE(result); |
136 } | 137 } |
137 | 138 |
| 139 namespace { |
| 140 |
| 141 // Returns the RenderFrameHost corresponding to the most visited iframe in the |
| 142 // given |tab|. |tab| must correspond to an NTP. |
| 143 content::RenderFrameHost* GetMostVisitedIframe(content::WebContents* tab) { |
| 144 CHECK_EQ(2u, tab->GetAllFrames().size()); |
| 145 for (content::RenderFrameHost* frame : tab->GetAllFrames()) { |
| 146 if (frame != tab->GetMainFrame()) { |
| 147 return frame; |
| 148 } |
| 149 } |
| 150 NOTREACHED(); |
| 151 return nullptr; |
| 152 } |
| 153 |
| 154 } // namespace |
| 155 |
| 156 IN_PROC_BROWSER_TEST_F(LocalNTPTest, LoadsIframe) { |
| 157 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 158 FocusOmnibox(); |
| 159 |
| 160 ui_test_utils::NavigateToURLWithDisposition( |
| 161 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 162 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 163 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 164 content::WebContents* active_tab = |
| 165 browser()->tab_strip_model()->GetActiveWebContents(); |
| 166 ASSERT_TRUE(search::IsInstantNTP(active_tab)); |
| 167 |
| 168 content::DOMMessageQueue msg_queue; |
| 169 |
| 170 bool result = false; |
| 171 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!setupAdvancedTest(true)", &result)); |
| 172 ASSERT_TRUE(result); |
| 173 |
| 174 // Wait for the MV iframe to load. |
| 175 std::string message; |
| 176 // First get rid of the "true" message from the GetBoolFromJS call above. |
| 177 ASSERT_TRUE(msg_queue.PopMessage(&message)); |
| 178 ASSERT_EQ("true", message); |
| 179 // Now wait for the "loaded" message. |
| 180 ASSERT_TRUE(msg_queue.WaitForMessage(&message)); |
| 181 ASSERT_EQ("\"loaded\"", message); |
| 182 |
| 183 // Get the iframe and check that the tiles loaded correctly. |
| 184 content::RenderFrameHost* iframe = GetMostVisitedIframe(active_tab); |
| 185 |
| 186 // Get the total number of (non-empty) tiles from the iframe. |
| 187 int total_thumbs = 0; |
| 188 ASSERT_TRUE(GetIntFromJS( |
| 189 iframe, "document.querySelectorAll('.mv-thumb').length", &total_thumbs)); |
| 190 // Also get how many of the tiles succeeded and failed in loading their |
| 191 // thumbnail images. |
| 192 int succeeded_imgs = 0; |
| 193 ASSERT_TRUE(GetIntFromJS(iframe, |
| 194 "document.querySelectorAll('.mv-thumb img').length", |
| 195 &succeeded_imgs)); |
| 196 int failed_imgs = 0; |
| 197 ASSERT_TRUE(GetIntFromJS( |
| 198 iframe, "document.querySelectorAll('.mv-thumb.failed-img').length", |
| 199 &failed_imgs)); |
| 200 |
| 201 // First, sanity check that the numbers line up (none of the css classes was |
| 202 // renamed, etc). |
| 203 EXPECT_EQ(total_thumbs, succeeded_imgs + failed_imgs); |
| 204 |
| 205 // Since we're in a non-signed-in, fresh profile with no history, there should |
| 206 // be the default TopSites tiles (see history::PrepopulatedPage). |
| 207 // Check that there is at least one tile, and that all of them loaded their |
| 208 // images successfully. |
| 209 EXPECT_GT(total_thumbs, 0); |
| 210 EXPECT_EQ(total_thumbs, succeeded_imgs); |
| 211 EXPECT_EQ(0, failed_imgs); |
| 212 } |
| 213 |
138 IN_PROC_BROWSER_TEST_F(LocalNTPTest, | 214 IN_PROC_BROWSER_TEST_F(LocalNTPTest, |
139 NTPRespectsBrowserLanguageSetting) { | 215 NTPRespectsBrowserLanguageSetting) { |
140 // Make sure the default language is not French. | 216 // Make sure the default language is not French. |
141 std::string default_locale = g_browser_process->GetApplicationLocale(); | 217 std::string default_locale = g_browser_process->GetApplicationLocale(); |
142 EXPECT_NE("fr", default_locale); | 218 EXPECT_NE("fr", default_locale); |
143 | 219 |
144 // Switch browser language to French. | 220 // Switch browser language to French. |
145 std::string loaded_locale = | 221 std::string loaded_locale = |
146 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr"); | 222 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr"); |
147 | 223 |
(...skipping 16 matching lines...) Expand all Loading... |
164 browser(), GURL(chrome::kChromeUINewTabURL), | 240 browser(), GURL(chrome::kChromeUINewTabURL), |
165 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 241 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
166 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | 242 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
167 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 243 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
168 | 244 |
169 // Verify that the NTP is in French. | 245 // Verify that the NTP is in French. |
170 content::WebContents* active_tab = | 246 content::WebContents* active_tab = |
171 browser()->tab_strip_model()->GetActiveWebContents(); | 247 browser()->tab_strip_model()->GetActiveWebContents(); |
172 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); | 248 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); |
173 } | 249 } |
OLD | NEW |