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

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

Issue 2830893002: Refactor of ExtensionNavigationThrottle (Closed)
Patch Set: \ Created 3 years, 7 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
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/common/url_constants.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/common/browser_side_navigation_policy.h"
25 #include "content/public/common/result_codes.h" 27 #include "content/public/common/result_codes.h"
26 #include "content/public/common/url_constants.h" 28 #include "content/public/common/url_constants.h"
27 #include "content/public/test/browser_test_utils.h" 29 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/test_navigation_observer.h" 30 #include "content/public/test/test_navigation_observer.h"
29 #include "extensions/browser/extension_host.h" 31 #include "extensions/browser/extension_host.h"
30 #include "extensions/browser/process_manager.h" 32 #include "extensions/browser/process_manager.h"
31 #include "extensions/common/constants.h" 33 #include "extensions/common/constants.h"
32 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
33 #include "extensions/test/extension_test_message_listener.h" 35 #include "extensions/test/extension_test_message_listener.h"
34 #include "extensions/test/result_catcher.h" 36 #include "extensions/test/result_catcher.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 ASSERT_TRUE(LoadExtension( 239 ASSERT_TRUE(LoadExtension(
238 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); 240 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
239 241
240 GURL start_url(std::string(extensions::kExtensionScheme) + 242 GURL start_url(std::string(extensions::kExtensionScheme) +
241 url::kStandardSchemeSeparator + 243 url::kStandardSchemeSeparator +
242 last_loaded_extension_id() + "/test.html"); 244 last_loaded_extension_id() + "/test.html");
243 ui_test_utils::NavigateToURL(browser(), start_url); 245 ui_test_utils::NavigateToURL(browser(), start_url);
244 WebContents* newtab = NULL; 246 WebContents* newtab = NULL;
245 ASSERT_NO_FATAL_FAILURE( 247 ASSERT_NO_FATAL_FAILURE(
246 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), 248 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(),
247 start_url.Resolve("newtab.html"), true, &newtab)); 249 start_url.Resolve("newtab.html"), true, &newtab));
248 250
249 bool result = false; 251 bool result = false;
250 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", 252 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()",
251 &result)); 253 &result));
252 EXPECT_TRUE(result); 254 EXPECT_TRUE(result);
253 } 255 }
254 256
255 // Tests that if an extension page calls window.open to an invalid extension 257 // Tests that if an extension page calls window.open to an invalid extension
256 // URL, the browser doesn't crash. 258 // URL, the browser doesn't crash.
257 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { 259 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
258 ASSERT_TRUE(LoadExtension( 260 const extensions::Extension* extension = LoadExtension(
259 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); 261 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"));
262 ASSERT_TRUE(extension);
260 263
261 GURL start_url(std::string(extensions::kExtensionScheme) + 264 GURL start_url = extension->GetResourceURL("/test.html");
262 url::kStandardSchemeSeparator +
263 last_loaded_extension_id() + "/test.html");
264 ui_test_utils::NavigateToURL(browser(), start_url); 265 ui_test_utils::NavigateToURL(browser(), start_url);
265 ASSERT_NO_FATAL_FAILURE( 266 WebContents* newtab = nullptr;
266 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), 267 bool expect_error_page_in_new_process =
268 content::IsBrowserSideNavigationEnabled();
269 ASSERT_NO_FATAL_FAILURE(OpenWindow(
270 browser()->tab_strip_model()->GetActiveWebContents(),
267 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), 271 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"),
268 false, NULL)); 272 expect_error_page_in_new_process, &newtab));
269 273
270 // If we got to this point, we didn't crash, so we're good. 274 // This is expected to commit an error page.
275 ASSERT_EQ(content::PAGE_TYPE_ERROR,
276 newtab->GetController().GetLastCommittedEntry()->GetPageType());
277
278 std::string document_body;
279 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
280 newtab, "domAutomationController.send(document.body.innerText.trim());",
281 &document_body));
282
283 // Currently, in this test, the error page is blocked by CSP. This is
284 // https://crbug.com/703801.
285 EXPECT_EQ("", document_body);
271 } 286 }
272 287
273 // Tests that calling window.open from the newtab page to an extension URL 288 // Tests that calling window.open from the newtab page to an extension URL
274 // gives the new window extension privileges - even though the opening page 289 // gives the new window extension privileges - even though the opening page
275 // does not have extension privileges, we break the script connection, so 290 // does not have extension privileges, we break the script connection, so
276 // there is no privilege leak. 291 // there is no privilege leak.
277 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { 292 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
278 ASSERT_TRUE(LoadExtension( 293 ASSERT_TRUE(LoadExtension(
279 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); 294 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
280 295
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ASSERT_TRUE(content::ExecuteScript( 377 ASSERT_TRUE(content::ExecuteScript(
363 tab, "location.href = '" + extension_url.spec() + "';")); 378 tab, "location.href = '" + extension_url.spec() + "';"));
364 observer.Wait(); 379 observer.Wait();
365 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL()); 380 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL());
366 std::string result; 381 std::string result;
367 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 382 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
368 tab, "domAutomationController.send(document.body.innerText)", &result)); 383 tab, "domAutomationController.send(document.body.innerText)", &result));
369 EXPECT_EQ("HOWDIE!!!", result); 384 EXPECT_EQ("HOWDIE!!!", result);
370 } 385 }
371 } 386 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/process_manager_browsertest.cc ('k') | chrome/browser/ui/toolbar/toolbar_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698