| 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" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // Tests that if an extension page calls window.open to an invalid extension | 255 // Tests that if an extension page calls window.open to an invalid extension |
| 256 // URL, the browser doesn't crash. | 256 // URL, the browser doesn't crash. |
| 257 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { | 257 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
| 258 ASSERT_TRUE(LoadExtension( | 258 ASSERT_TRUE(LoadExtension( |
| 259 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 259 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 260 | 260 |
| 261 GURL start_url(std::string(extensions::kExtensionScheme) + | 261 GURL start_url(std::string(extensions::kExtensionScheme) + |
| 262 url::kStandardSchemeSeparator + | 262 url::kStandardSchemeSeparator + |
| 263 last_loaded_extension_id() + "/test.html"); | 263 last_loaded_extension_id() + "/test.html"); |
| 264 ui_test_utils::NavigateToURL(browser(), start_url); | 264 ui_test_utils::NavigateToURL(browser(), start_url); |
| 265 ASSERT_NO_FATAL_FAILURE( | 265 ASSERT_NO_FATAL_FAILURE(OpenWindow( |
| 266 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), | 266 browser()->tab_strip_model()->GetActiveWebContents(), |
| 267 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), | 267 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
| 268 false, NULL)); | 268 true, NULL)); |
| 269 | 269 |
| 270 // If we got to this point, we didn't crash, so we're good. | 270 // If we got to this point, we didn't crash, so we're good. |
| 271 } | 271 } |
| 272 | 272 |
| 273 // Tests that calling window.open from the newtab page to an extension URL | 273 // 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 | 274 // gives the new window extension privileges - even though the opening page |
| 275 // does not have extension privileges, we break the script connection, so | 275 // does not have extension privileges, we break the script connection, so |
| 276 // there is no privilege leak. | 276 // there is no privilege leak. |
| 277 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { | 277 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 278 ASSERT_TRUE(LoadExtension( | 278 ASSERT_TRUE(LoadExtension( |
| 279 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 279 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 280 | 280 |
| 281 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 281 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 282 WebContents* newtab = NULL; | 282 WebContents* newtab = NULL; |
| 283 ASSERT_NO_FATAL_FAILURE( | 283 ASSERT_NO_FATAL_FAILURE( |
| 284 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), | 284 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
| 285 GURL(std::string(extensions::kExtensionScheme) + | 285 GURL(std::string(extensions::kExtensionScheme) + |
| 286 url::kStandardSchemeSeparator + | 286 url::kStandardSchemeSeparator + |
| 287 last_loaded_extension_id() + "/newtab.html"), | 287 last_loaded_extension_id() + "/newtab.html"), |
| 288 false, | 288 true, &newtab)); |
| 289 &newtab)); | |
| 290 | 289 |
| 291 // Extension API should succeed. | 290 // Extension API should succeed. |
| 292 bool result = false; | 291 bool result = false; |
| 293 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", | 292 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 294 &result)); | 293 &result)); |
| 295 EXPECT_TRUE(result); | 294 EXPECT_TRUE(result); |
| 296 } | 295 } |
| 297 | 296 |
| 298 // Tests that calling window.open for an extension URL from a non-HTTP or HTTPS | 297 // Tests that calling window.open for an extension URL from a non-HTTP or HTTPS |
| 299 // URL on a new tab cannot access non-web-accessible resources. | 298 // URL on a new tab cannot access non-web-accessible resources. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 ASSERT_TRUE(content::ExecuteScript( | 361 ASSERT_TRUE(content::ExecuteScript( |
| 363 tab, "location.href = '" + extension_url.spec() + "';")); | 362 tab, "location.href = '" + extension_url.spec() + "';")); |
| 364 observer.Wait(); | 363 observer.Wait(); |
| 365 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL()); | 364 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL()); |
| 366 std::string result; | 365 std::string result; |
| 367 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 366 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 368 tab, "domAutomationController.send(document.body.innerText)", &result)); | 367 tab, "domAutomationController.send(document.body.innerText)", &result)); |
| 369 EXPECT_EQ("HOWDIE!!!", result); | 368 EXPECT_EQ("HOWDIE!!!", result); |
| 370 } | 369 } |
| 371 } | 370 } |
| OLD | NEW |