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

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: 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
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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 322
321 EXPECT_NE(extension_url, newtab->GetMainFrame()->GetLastCommittedURL()); 323 EXPECT_NE(extension_url, newtab->GetMainFrame()->GetLastCommittedURL());
322 EXPECT_FALSE(newtab->GetMainFrame()->GetSiteInstance()->GetSiteURL().SchemeIs( 324 EXPECT_FALSE(newtab->GetMainFrame()->GetSiteInstance()->GetSiteURL().SchemeIs(
323 extensions::kExtensionScheme)); 325 extensions::kExtensionScheme));
324 326
325 // Verify that the blocking was recorded correctly in UMA. 327 // Verify that the blocking was recorded correctly in UMA.
326 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure", 328 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure",
327 2, /* FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION */ 329 2, /* FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION */
328 1); 330 1);
329 } 331 }
332
333 // Test that navigating to an extension URL is allowed on chrome:// and
334 // chrome-search:// pages, even for URLs that are not web-accessible.
335 // See https://crbug.com/662602.
336 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
337 NavigateToInaccessibleResourceFromChromeURL) {
338 // Mint an extension URL which is not web-accessible.
339 ASSERT_TRUE(LoadExtension(
340 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
341 GURL extension_url(extensions::Extension::GetResourceURL(
342 extensions::Extension::GetBaseURLFromExtensionId(
343 last_loaded_extension_id()),
Devlin 2016/11/09 21:54:43 This might be cleaner as: const Extension* extensi
alexmos 2016/11/09 22:20:31 Done for both tests. Much cleaner, thanks for the
344 "test.html"));
345
346 content::WebContents* tab =
347 browser()->tab_strip_model()->GetActiveWebContents();
348
349 // Navigate to the non-web-accessible URL from chrome:// and
350 // chrome-search:// pages. Verify that the page loads correctly.
351 GURL history_url(chrome::kChromeUIHistoryURL);
352 GURL ntp_url(chrome::kChromeSearchLocalNtpUrl);
353 ASSERT_TRUE(history_url.SchemeIs(content::kChromeUIScheme));
354 ASSERT_TRUE(ntp_url.SchemeIs(chrome::kChromeSearchScheme));
355 GURL start_urls[] = {history_url, ntp_url};
356 for (size_t i = 0; i < arraysize(start_urls); i++) {
357 ui_test_utils::NavigateToURL(browser(), start_urls[i]);
358 EXPECT_EQ(start_urls[i], tab->GetMainFrame()->GetLastCommittedURL());
359
360 content::TestNavigationObserver observer(tab);
361 ASSERT_TRUE(content::ExecuteScript(
362 tab, "location.href = '" + extension_url.spec() + "';"));
363 observer.Wait();
364 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL());
365 std::string result;
366 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
367 tab, "domAutomationController.send(document.body.innerText)", &result));
368 EXPECT_EQ("HOWDIE!!!", result);
369 }
370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698