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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" |
13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "net/base/mock_host_resolver.h" | 19 #include "net/base/mock_host_resolver.h" |
19 | 20 |
20 using content::OpenURLParams; | 21 using content::OpenURLParams; |
21 using content::Referrer; | 22 using content::Referrer; |
22 using content::WebContents; | 23 using content::WebContents; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // Tests that an extension page can call window.open to an extension URL and | 257 // Tests that an extension page can call window.open to an extension URL and |
257 // the new window has extension privileges. | 258 // the new window has extension privileges. |
258 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { | 259 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
259 ASSERT_TRUE(LoadExtension( | 260 ASSERT_TRUE(LoadExtension( |
260 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 261 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
261 | 262 |
262 GURL start_url(std::string("chrome-extension://") + | 263 GURL start_url(std::string("chrome-extension://") + |
263 last_loaded_extension_id_ + "/test.html"); | 264 last_loaded_extension_id_ + "/test.html"); |
264 ui_test_utils::NavigateToURL(browser(), start_url); | 265 ui_test_utils::NavigateToURL(browser(), start_url); |
265 WebContents* newtab; | 266 WebContents* newtab; |
266 ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetActiveWebContents(), | 267 ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
267 start_url.Resolve("newtab.html"), true, &newtab)); | 268 start_url.Resolve("newtab.html"), true, &newtab)); |
268 | 269 |
269 bool result = false; | 270 bool result = false; |
270 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 271 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
271 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); | 272 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
272 EXPECT_TRUE(result); | 273 EXPECT_TRUE(result); |
273 } | 274 } |
274 | 275 |
275 // Tests that if an extension page calls window.open to an invalid extension | 276 // Tests that if an extension page calls window.open to an invalid extension |
276 // URL, the browser doesn't crash. | 277 // URL, the browser doesn't crash. |
277 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { | 278 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
278 ASSERT_TRUE(LoadExtension( | 279 ASSERT_TRUE(LoadExtension( |
279 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 280 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
280 | 281 |
281 GURL start_url(std::string("chrome-extension://") + | 282 GURL start_url(std::string("chrome-extension://") + |
282 last_loaded_extension_id_ + "/test.html"); | 283 last_loaded_extension_id_ + "/test.html"); |
283 ui_test_utils::NavigateToURL(browser(), start_url); | 284 ui_test_utils::NavigateToURL(browser(), start_url); |
284 ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetActiveWebContents(), | 285 ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
285 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), | 286 GURL("chrome-extension://thisissurelynotavalidextensionid/newtab.html"), |
286 false, NULL)); | 287 false, NULL)); |
287 | 288 |
288 // If we got to this point, we didn't crash, so we're good. | 289 // If we got to this point, we didn't crash, so we're good. |
289 } | 290 } |
290 | 291 |
291 // Tests that calling window.open from the newtab page to an extension URL | 292 // Tests that calling window.open from the newtab page to an extension URL |
292 // gives the new window extension privileges - even though the opening page | 293 // gives the new window extension privileges - even though the opening page |
293 // does not have extension privileges, we break the script connection, so | 294 // does not have extension privileges, we break the script connection, so |
294 // there is no privilege leak. | 295 // there is no privilege leak. |
295 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { | 296 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
296 ASSERT_TRUE(LoadExtension( | 297 ASSERT_TRUE(LoadExtension( |
297 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 298 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
298 | 299 |
299 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 300 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
300 WebContents* newtab; | 301 WebContents* newtab; |
301 ASSERT_NO_FATAL_FAILURE(OpenWindow(browser()->GetActiveWebContents(), | 302 ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
302 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + | 303 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
303 "/newtab.html"), false, &newtab)); | 304 "/newtab.html"), false, &newtab)); |
304 | 305 |
305 // Extension API should succeed. | 306 // Extension API should succeed. |
306 bool result = false; | 307 bool result = false; |
307 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 308 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
308 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); | 309 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
309 EXPECT_TRUE(result); | 310 EXPECT_TRUE(result); |
310 } | 311 } |
OLD | NEW |