Chromium Code Reviews| 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 IN_PROC_BROWSER_TEST_F(LocalNTPTest, LoadsIframe) { | |
| 140 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 141 FocusOmnibox(); | |
| 142 | |
| 143 ui_test_utils::NavigateToURLWithDisposition( | |
| 144 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
| 145 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | |
| 146 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 147 content::WebContents* active_tab = | |
| 148 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 149 ASSERT_TRUE(search::IsInstantNTP(active_tab)); | |
| 150 | |
| 151 content::DOMMessageQueue msg_queue; | |
| 152 | |
| 153 bool result = false; | |
| 154 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!setupAdvancedTest(true)", &result)); | |
| 155 ASSERT_TRUE(result); | |
| 156 | |
| 157 // Wait for the MV iframe to load. | |
| 158 std::string message; | |
| 159 // First get rid of the "true" message from the GetBoolFromJS call above. | |
| 160 msg_queue.PopMessage(&message); | |
| 161 ASSERT_EQ("true", message); | |
| 162 // Now wait for the "loaded" message. | |
| 163 msg_queue.WaitForMessage(&message); | |
| 164 ASSERT_EQ("\"loaded\"", message); | |
| 165 | |
| 166 // Find the RenderFrameHost of the iframe. | |
|
sfiera
2017/02/17 17:38:12
Break out a "GetIframe()" helper function?
Marc Treib
2017/02/17 18:15:23
Done.
| |
| 167 ASSERT_EQ(2, active_tab->GetAllFrames().size()); | |
| 168 content::RenderFrameHost* iframe = nullptr; | |
| 169 for (content::RenderFrameHost* frame : active_tab->GetAllFrames()) { | |
| 170 if (frame != active_tab->GetMainFrame()) { | |
| 171 iframe = frame; | |
| 172 break; | |
| 173 } | |
| 174 } | |
| 175 CHECK(iframe); | |
| 176 | |
| 177 // Check that there is at least one thumbnail, and that all of them loaded | |
| 178 // their images successfully. | |
|
sfiera
2017/02/17 17:38:12
I'm not sure I follow this set of conditions.
Marc Treib
2017/02/17 18:15:23
I've tried to make the comments clearer. Does this
sfiera
2017/02/20 11:20:10
I think I'm just not familiar enough with this tes
Marc Treib
2017/02/20 11:37:27
The test runs in a non-signed-in, fresh profile, i
| |
| 179 int total_thumbs = 0; | |
| 180 ASSERT_TRUE(GetIntFromJS( | |
| 181 iframe, "document.querySelectorAll('.mv-thumb').length", &total_thumbs)); | |
| 182 int succeeded_imgs = 0; | |
| 183 ASSERT_TRUE(GetIntFromJS(iframe, | |
| 184 "document.querySelectorAll('.mv-thumb img').length", | |
| 185 &succeeded_imgs)); | |
| 186 int failed_imgs = 0; | |
| 187 ASSERT_TRUE(GetIntFromJS( | |
| 188 iframe, "document.querySelectorAll('.mv-thumb.failed-img').length", | |
| 189 &failed_imgs)); | |
| 190 | |
| 191 ASSERT_EQ(total_thumbs, succeeded_imgs + failed_imgs); | |
|
sfiera
2017/02/17 17:38:12
This assert doesn't seem to add anything to the be
Marc Treib
2017/02/17 18:15:23
Well, true. It's supposed to be a sanity check - i
sfiera
2017/02/20 11:20:10
It still looks to me like it would make debugging
Marc Treib
2017/02/20 11:37:28
But if e.g. only the ".failed-img" class is rename
sfiera
2017/02/20 12:16:43
The test would notice, because succeeded_imgs woul
| |
| 192 | |
| 193 EXPECT_GT(total_thumbs, 0); | |
| 194 EXPECT_EQ(total_thumbs, succeeded_imgs); | |
| 195 EXPECT_EQ(0, failed_imgs); | |
| 196 } | |
| 197 | |
| 138 IN_PROC_BROWSER_TEST_F(LocalNTPTest, | 198 IN_PROC_BROWSER_TEST_F(LocalNTPTest, |
| 139 NTPRespectsBrowserLanguageSetting) { | 199 NTPRespectsBrowserLanguageSetting) { |
| 140 // Make sure the default language is not French. | 200 // Make sure the default language is not French. |
| 141 std::string default_locale = g_browser_process->GetApplicationLocale(); | 201 std::string default_locale = g_browser_process->GetApplicationLocale(); |
| 142 EXPECT_NE("fr", default_locale); | 202 EXPECT_NE("fr", default_locale); |
| 143 | 203 |
| 144 // Switch browser language to French. | 204 // Switch browser language to French. |
| 145 std::string loaded_locale = | 205 std::string loaded_locale = |
| 146 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr"); | 206 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr"); |
| 147 | 207 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 164 browser(), GURL(chrome::kChromeUINewTabURL), | 224 browser(), GURL(chrome::kChromeUINewTabURL), |
| 165 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 225 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 166 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | 226 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 167 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 227 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 168 | 228 |
| 169 // Verify that the NTP is in French. | 229 // Verify that the NTP is in French. |
| 170 content::WebContents* active_tab = | 230 content::WebContents* active_tab = |
| 171 browser()->tab_strip_model()->GetActiveWebContents(); | 231 browser()->tab_strip_model()->GetActiveWebContents(); |
| 172 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); | 232 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); |
| 173 } | 233 } |
| OLD | NEW |