Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 25 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
| 26 #include "content/public/common/url_constants.h" | 27 #include "content/public/common/url_constants.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 28 #include "content/public/test/test_navigation_observer.h" | 29 #include "content/public/test/test_navigation_observer.h" |
| 29 #include "extensions/browser/extension_host.h" | 30 #include "extensions/browser/extension_host.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 ASSERT_TRUE(LoadExtension( | 234 ASSERT_TRUE(LoadExtension( |
| 234 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 235 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 235 | 236 |
| 236 GURL start_url(std::string(extensions::kExtensionScheme) + | 237 GURL start_url(std::string(extensions::kExtensionScheme) + |
| 237 url::kStandardSchemeSeparator + | 238 url::kStandardSchemeSeparator + |
| 238 last_loaded_extension_id() + "/test.html"); | 239 last_loaded_extension_id() + "/test.html"); |
| 239 ui_test_utils::NavigateToURL(browser(), start_url); | 240 ui_test_utils::NavigateToURL(browser(), start_url); |
| 240 WebContents* newtab = NULL; | 241 WebContents* newtab = NULL; |
| 241 ASSERT_NO_FATAL_FAILURE( | 242 ASSERT_NO_FATAL_FAILURE( |
| 242 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), | 243 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
| 243 start_url.Resolve("newtab.html"), true, &newtab)); | 244 start_url.Resolve("newtab.html"), true, &newtab)); |
| 244 | 245 |
| 245 bool result = false; | 246 bool result = false; |
| 246 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", | 247 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 247 &result)); | 248 &result)); |
| 248 EXPECT_TRUE(result); | 249 EXPECT_TRUE(result); |
| 249 } | 250 } |
| 250 | 251 |
| 251 // Tests that if an extension page calls window.open to an invalid extension | 252 // Tests that if an extension page calls window.open to an invalid extension |
| 252 // URL, the browser doesn't crash. | 253 // URL, the browser doesn't crash. |
| 253 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { | 254 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
|
ncarter (slow)
2017/05/01 21:50:37
Also incidental cleanup (this test had been failin
| |
| 254 ASSERT_TRUE(LoadExtension( | 255 const extensions::Extension* extension = LoadExtension( |
| 255 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 256 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")); |
| 257 ASSERT_TRUE(extension); | |
| 256 | 258 |
| 257 GURL start_url(std::string(extensions::kExtensionScheme) + | 259 GURL start_url = extension->GetResourceURL("/test.html"); |
| 258 url::kStandardSchemeSeparator + | |
| 259 last_loaded_extension_id() + "/test.html"); | |
| 260 ui_test_utils::NavigateToURL(browser(), start_url); | 260 ui_test_utils::NavigateToURL(browser(), start_url); |
| 261 ASSERT_NO_FATAL_FAILURE( | 261 WebContents* newtab = nullptr; |
| 262 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), | 262 ASSERT_NO_FATAL_FAILURE(OpenWindow( |
| 263 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 263 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), | 264 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
| 264 false, NULL)); | 265 false, &newtab)); |
| 266 | |
| 267 // This is expected to commit an error page. | |
| 268 ASSERT_EQ(content::PAGE_TYPE_ERROR, | |
| 269 newtab->GetController().GetLastCommittedEntry()->GetPageType()); | |
| 265 | 270 |
| 266 // If we got to this point, we didn't crash, so we're good. | 271 // If we got to this point, we didn't crash, so we're good. |
| 267 } | 272 } |
| 268 | 273 |
| 269 // Tests that calling window.open from the newtab page to an extension URL | 274 // Tests that calling window.open from the newtab page to an extension URL |
| 270 // gives the new window extension privileges - even though the opening page | 275 // gives the new window extension privileges - even though the opening page |
| 271 // does not have extension privileges, we break the script connection, so | 276 // does not have extension privileges, we break the script connection, so |
| 272 // there is no privilege leak. | 277 // there is no privilege leak. |
| 273 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { | 278 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 274 ASSERT_TRUE(LoadExtension( | 279 ASSERT_TRUE(LoadExtension( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 ASSERT_TRUE(content::ExecuteScript( | 363 ASSERT_TRUE(content::ExecuteScript( |
| 359 tab, "location.href = '" + extension_url.spec() + "';")); | 364 tab, "location.href = '" + extension_url.spec() + "';")); |
| 360 observer.Wait(); | 365 observer.Wait(); |
| 361 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL()); | 366 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL()); |
| 362 std::string result; | 367 std::string result; |
| 363 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 368 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 364 tab, "domAutomationController.send(document.body.innerText)", &result)); | 369 tab, "domAutomationController.send(document.body.innerText)", &result)); |
| 365 EXPECT_EQ("HOWDIE!!!", result); | 370 EXPECT_EQ("HOWDIE!!!", result); |
| 366 } | 371 } |
| 367 } | 372 } |
| OLD | NEW |