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

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

Issue 2454563003: Fix web accessible resource checks in ShouldAllowOpenURL (Closed)
Patch Set: Rebase 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 "build/build_config.h" 10 #include "build/build_config.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/result_codes.h" 24 #include "content/public/common/result_codes.h"
21 #include "content/public/common/url_constants.h" 25 #include "content/public/common/url_constants.h"
22 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
23 #include "extensions/browser/extension_host.h" 27 #include "extensions/browser/extension_host.h"
24 #include "extensions/browser/process_manager.h" 28 #include "extensions/browser/process_manager.h"
25 #include "extensions/common/constants.h" 29 #include "extensions/common/constants.h"
26 #include "extensions/common/extension.h" 30 #include "extensions/common/extension.h"
27 #include "extensions/test/extension_test_message_listener.h" 31 #include "extensions/test/extension_test_message_listener.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 last_loaded_extension_id() + "/newtab.html"), 281 last_loaded_extension_id() + "/newtab.html"),
278 false, 282 false,
279 &newtab)); 283 &newtab));
280 284
281 // Extension API should succeed. 285 // Extension API should succeed.
282 bool result = false; 286 bool result = false;
283 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", 287 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
284 &result)); 288 &result));
285 EXPECT_TRUE(result); 289 EXPECT_TRUE(result);
286 } 290 }
291
292 // 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.
294 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest,
295 WindowOpenInaccessibleResourceFromDataURL) {
296 base::HistogramTester uma;
297 ASSERT_TRUE(LoadExtension(
298 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
299
300 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,foo"));
301
302 // test.html is not web-accessible and should not be loaded.
303 GURL extension_url(std::string(extensions::kExtensionScheme) +
Devlin 2016/11/02 16:19:22 nit: extension_url = Extension::GetResourceURL(
alexmos 2016/11/02 17:32:46 Done.
304 url::kStandardSchemeSeparator +
305 last_loaded_extension_id() + "/test.html");
306 content::WindowedNotificationObserver windowed_observer(
307 content::NOTIFICATION_LOAD_STOP,
308 content::NotificationService::AllSources());
309 ASSERT_TRUE(content::ExecuteScript(
310 browser()->tab_strip_model()->GetActiveWebContents(),
311 "window.open('" + extension_url.spec() + "');"));
312 windowed_observer.Wait();
313 content::NavigationController* controller =
314 content::Source<content::NavigationController>(windowed_observer.source())
315 .ptr();
316 content::WebContents* newtab = controller->GetWebContents();
317 ASSERT_TRUE(newtab);
318
319 EXPECT_NE(extension_url, newtab->GetMainFrame()->GetLastCommittedURL());
320 EXPECT_NE(std::string(extensions::kExtensionScheme),
321 newtab->GetMainFrame()->GetSiteInstance()->GetSiteURL().scheme());
Devlin 2016/11/02 16:19:22 Can we check what the page is supposed to be? (i.
alexmos 2016/11/02 17:32:46 See my previous comment - ShouldAllowOpenURL doesn
322
323 // Verify that the blocking was recorded correctly in UMA.
324 uma.ExpectUniqueSample("Extensions.ShouldAllowOpenURL.Failure",
325 2, /* FAILURE_SCHEME_NOT_HTTP_OR_HTTPS_OR_EXTENSION */
326 1);
327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698