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

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

Issue 2486843003: Allow navigations to non-web-accessible resources from chrome schemes. (Closed)
Patch Set: nit Created 4 years, 1 month 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 | « chrome/browser/extensions/chrome_content_browser_client_extensions_part.cc ('k') | no next file » | 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 "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/result_codes.h" 25 #include "content/public/common/result_codes.h"
25 #include "content/public/common/url_constants.h" 26 #include "content/public/common/url_constants.h"
26 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/test_navigation_observer.h"
27 #include "extensions/browser/extension_host.h" 29 #include "extensions/browser/extension_host.h"
28 #include "extensions/browser/process_manager.h" 30 #include "extensions/browser/process_manager.h"
29 #include "extensions/common/constants.h" 31 #include "extensions/common/constants.h"
30 #include "extensions/common/extension.h" 32 #include "extensions/common/extension.h"
31 #include "extensions/test/extension_test_message_listener.h" 33 #include "extensions/test/extension_test_message_listener.h"
32 #include "extensions/test/result_catcher.h" 34 #include "extensions/test/result_catcher.h"
33 #include "net/dns/mock_host_resolver.h" 35 #include "net/dns/mock_host_resolver.h"
34 #include "net/test/embedded_test_server/embedded_test_server.h" 36 #include "net/test/embedded_test_server/embedded_test_server.h"
35 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
36 38
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", 289 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
288 &result)); 290 &result));
289 EXPECT_TRUE(result); 291 EXPECT_TRUE(result);
290 } 292 }
291 293
292 // Tests that calling window.open for an extension URL from a non-HTTP or HTTPS 294 // Tests that calling window.open for an extension URL from a non-HTTP or HTTPS
293 // URL on a new tab cannot access non-web-accessible resources. 295 // URL on a new tab cannot access non-web-accessible resources.
294 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, 296 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
295 WindowOpenInaccessibleResourceFromDataURL) { 297 WindowOpenInaccessibleResourceFromDataURL) {
296 base::HistogramTester uma; 298 base::HistogramTester uma;
297 ASSERT_TRUE(LoadExtension( 299 const extensions::Extension* extension = LoadExtension(
298 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); 300 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"));
301 ASSERT_TRUE(extension);
299 302
300 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,foo")); 303 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,foo"));
301 304
302 // test.html is not web-accessible and should not be loaded. 305 // test.html is not web-accessible and should not be loaded.
303 GURL extension_url(extensions::Extension::GetResourceURL( 306 GURL extension_url(extension->GetResourceURL("test.html"));
304 extensions::Extension::GetBaseURLFromExtensionId(
305 last_loaded_extension_id()),
306 "test.html"));
307
308 content::WindowedNotificationObserver windowed_observer( 307 content::WindowedNotificationObserver windowed_observer(
309 content::NOTIFICATION_LOAD_STOP, 308 content::NOTIFICATION_LOAD_STOP,
310 content::NotificationService::AllSources()); 309 content::NotificationService::AllSources());
311 ASSERT_TRUE(content::ExecuteScript( 310 ASSERT_TRUE(content::ExecuteScript(
312 browser()->tab_strip_model()->GetActiveWebContents(), 311 browser()->tab_strip_model()->GetActiveWebContents(),
313 "window.open('" + extension_url.spec() + "');")); 312 "window.open('" + extension_url.spec() + "');"));
314 windowed_observer.Wait(); 313 windowed_observer.Wait();
315 content::NavigationController* controller = 314 content::NavigationController* controller =
316 content::Source<content::NavigationController>(windowed_observer.source()) 315 content::Source<content::NavigationController>(windowed_observer.source())
317 .ptr(); 316 .ptr();
318 content::WebContents* newtab = controller->GetWebContents(); 317 content::WebContents* newtab = controller->GetWebContents();
319 ASSERT_TRUE(newtab); 318 ASSERT_TRUE(newtab);
320 319
321 EXPECT_NE(extension_url, newtab->GetMainFrame()->GetLastCommittedURL()); 320 EXPECT_NE(extension_url, newtab->GetMainFrame()->GetLastCommittedURL());
322 EXPECT_FALSE(newtab->GetMainFrame()->GetSiteInstance()->GetSiteURL().SchemeIs( 321 EXPECT_FALSE(newtab->GetMainFrame()->GetSiteInstance()->GetSiteURL().SchemeIs(
323 extensions::kExtensionScheme)); 322 extensions::kExtensionScheme));
324 323
325 // Verify that the blocking was recorded correctly in UMA. 324 // Verify that the blocking was recorded correctly in UMA.
326 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure", 325 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure",
327 2, /* FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION */ 326 2, /* FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION */
328 1); 327 1);
329 } 328 }
329
330 // Test that navigating to an extension URL is allowed on chrome:// and
331 // chrome-search:// pages, even for URLs that are not web-accessible.
332 // See https://crbug.com/662602.
333 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
334 NavigateToInaccessibleResourceFromChromeURL) {
335 // Mint an extension URL which is not web-accessible.
336 const extensions::Extension* extension = LoadExtension(
337 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"));
338 ASSERT_TRUE(extension);
339 GURL extension_url(extension->GetResourceURL("test.html"));
340
341 content::WebContents* tab =
342 browser()->tab_strip_model()->GetActiveWebContents();
343
344 // Navigate to the non-web-accessible URL from chrome:// and
345 // chrome-search:// pages. Verify that the page loads correctly.
346 GURL history_url(chrome::kChromeUIHistoryURL);
347 GURL ntp_url(chrome::kChromeSearchLocalNtpUrl);
348 ASSERT_TRUE(history_url.SchemeIs(content::kChromeUIScheme));
349 ASSERT_TRUE(ntp_url.SchemeIs(chrome::kChromeSearchScheme));
350 GURL start_urls[] = {history_url, ntp_url};
351 for (size_t i = 0; i < arraysize(start_urls); i++) {
352 ui_test_utils::NavigateToURL(browser(), start_urls[i]);
353 EXPECT_EQ(start_urls[i], tab->GetMainFrame()->GetLastCommittedURL());
354
355 content::TestNavigationObserver observer(tab);
356 ASSERT_TRUE(content::ExecuteScript(
357 tab, "location.href = '" + extension_url.spec() + "';"));
358 observer.Wait();
359 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL());
360 std::string result;
361 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
362 tab, "domAutomationController.send(document.body.innerText)", &result));
363 EXPECT_EQ("HOWDIE!!!", result);
364 }
365 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/chrome_content_browser_client_extensions_part.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698