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

Side by Side Diff: chrome/browser/extensions/extension_override_apitest.cc

Issue 2754363002: Don't focus the omnibox when a subframe navigates on NTP (Merge to M58) (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | content/browser/frame_host/render_frame_host_manager.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_web_ui.h" 10 #include "chrome/browser/extensions/extension_web_ui.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/extensions/chrome_manifest_url_handlers.h" 14 #include "chrome/common/extensions/chrome_manifest_url_handlers.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
17 #include "components/prefs/pref_service.h" 17 #include "components/prefs/pref_service.h"
18 #include "components/prefs/scoped_user_pref_update.h" 18 #include "components/prefs/scoped_user_pref_update.h"
19 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/render_widget_host_view.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/browser_test_utils.h"
21 #include "extensions/common/constants.h" 23 #include "extensions/common/constants.h"
22 #include "extensions/test/extension_test_message_listener.h" 24 #include "extensions/test/extension_test_message_listener.h"
23 #include "extensions/test/result_catcher.h" 25 #include "extensions/test/result_catcher.h"
26 #include "net/dns/mock_host_resolver.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h"
24 28
25 using content::WebContents; 29 using content::WebContents;
26 30
27 namespace extensions { 31 namespace extensions {
28 32
29 class ExtensionOverrideTest : public ExtensionApiTest { 33 class ExtensionOverrideTest : public ExtensionApiTest {
30 protected: 34 protected:
31 bool CheckHistoryOverridesContainsNoDupes() { 35 bool CheckHistoryOverridesContainsNoDupes() {
32 // There should be no duplicate entries in the preferences. 36 // There should be no duplicate entries in the preferences.
33 const base::DictionaryValue* overrides = 37 const base::DictionaryValue* overrides =
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Navigate an incognito tab to the new tab page. We should get the actual 188 // Navigate an incognito tab to the new tab page. We should get the actual
185 // new tab page because we can't load chrome-extension URLs in incognito. 189 // new tab page because we can't load chrome-extension URLs in incognito.
186 Browser* otr_browser = 190 Browser* otr_browser =
187 OpenURLOffTheRecord(browser()->profile(), GURL("chrome://newtab/")); 191 OpenURLOffTheRecord(browser()->profile(), GURL("chrome://newtab/"));
188 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); 192 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents();
189 ASSERT_TRUE(tab->GetController().GetVisibleEntry()); 193 ASSERT_TRUE(tab->GetController().GetVisibleEntry());
190 EXPECT_FALSE(tab->GetController().GetVisibleEntry()->GetURL(). 194 EXPECT_FALSE(tab->GetController().GetVisibleEntry()->GetURL().
191 SchemeIs(kExtensionScheme)); 195 SchemeIs(kExtensionScheme));
192 } 196 }
193 197
198 // Check that when an overridden new tab page has focus, a subframe navigation
199 // on that page does not steal the focus away by focusing the omnibox.
200 // See https://crbug.com/700124.
201 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest,
202 SubframeNavigationInOverridenNTPDoesNotAffectFocus) {
203 host_resolver()->AddRule("*", "127.0.0.1");
204 ASSERT_TRUE(embedded_test_server()->Start());
205
206 // Load an extension that overrides the new tab page.
207 const Extension* extension = LoadExtension(data_dir().AppendASCII("newtab"));
208
209 // Navigate to the new tab page. The overridden new tab page
210 // will call chrome.test.sendMessage('controlled by first').
211 ExtensionTestMessageListener listener("controlled by first", false);
212 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
213 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
214 EXPECT_TRUE(ExtensionControlsPage(contents, extension->id()));
215 EXPECT_TRUE(listener.WaitUntilSatisfied());
216
217 // Start off with the main page focused.
218 contents->Focus();
219 EXPECT_TRUE(contents->GetRenderWidgetHostView()->HasFocus());
220
221 // Inject an iframe and navigate it to a cross-site URL. With
222 // --site-per-process, this will go into a separate process.
223 GURL cross_site_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
224 std::string script = "var f = document.createElement('iframe');\n"
225 "f.src = '" + cross_site_url.spec() + "';\n"
226 "document.body.appendChild(f);\n";
227 EXPECT_TRUE(ExecuteScript(contents, script));
228 WaitForLoadStop(contents);
229
230 // The page should still have focus. The cross-process subframe navigation
231 // above should not try to focus the omnibox, which would make this false.
232 EXPECT_TRUE(contents->GetRenderWidgetHostView()->HasFocus());
233 }
234
194 // Times out consistently on Win, http://crbug.com/45173. 235 // Times out consistently on Win, http://crbug.com/45173.
195 #if defined(OS_WIN) 236 #if defined(OS_WIN)
196 #define MAYBE_OverrideHistory DISABLED_OverrideHistory 237 #define MAYBE_OverrideHistory DISABLED_OverrideHistory
197 #else 238 #else
198 #define MAYBE_OverrideHistory OverrideHistory 239 #define MAYBE_OverrideHistory OverrideHistory
199 #endif // defined(OS_WIN) 240 #endif // defined(OS_WIN)
200 241
201 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideHistory) { 242 IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideHistory) {
202 ASSERT_TRUE(RunExtensionTest("override/history")) << message_; 243 ASSERT_TRUE(RunExtensionTest("override/history")) << message_;
203 { 244 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 289 }
249 290
250 ASSERT_FALSE(CheckHistoryOverridesContainsNoDupes()); 291 ASSERT_FALSE(CheckHistoryOverridesContainsNoDupes());
251 292
252 ExtensionWebUI::InitializeChromeURLOverrides(profile()); 293 ExtensionWebUI::InitializeChromeURLOverrides(profile());
253 294
254 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes()); 295 ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes());
255 } 296 }
256 297
257 } // namespace extensions 298 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698