| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/ref_counted.h" | 5 #include "base/ref_counted.h" |
| 6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
| 7 #include "chrome/browser/browser_list.h" | 7 #include "chrome/browser/browser_list.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" | 8 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
| 12 #include "chrome/browser/extensions/extensions_service.h" | 12 #include "chrome/browser/extensions/extensions_service.h" |
| 13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/browser/renderer_host/site_instance.h" | 14 #include "chrome/browser/renderer_host/site_instance.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #if defined(TOOLKIT_GTK) | 16 #if defined(TOOLKIT_GTK) |
| 17 #include "chrome/browser/gtk/extension_shelf_gtk.h" | 17 #include "chrome/browser/gtk/extension_shelf_gtk.h" |
| 18 #else | 18 #else |
| 19 #include "chrome/browser/views/extensions/extension_shelf.h" | 19 #include "chrome/browser/views/extensions/extension_shelf.h" |
| 20 #endif // defined(TOOLKIT_GTK) | 20 #endif // defined(TOOLKIT_GTK) |
| 21 | 21 |
| 22 #include "chrome/browser/views/frame/browser_view.h" | 22 #include "chrome/browser/views/frame/browser_view.h" |
| 23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/extensions/extension_error_reporter.h" | 24 #include "chrome/common/extensions/extension_error_reporter.h" |
| 25 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/test/ui_test_utils.h" | 27 #include "chrome/test/ui_test_utils.h" |
| 28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 29 | 29 |
| 30 // ID assigned to the first unpacked extension loaded by LoadExtension(). | |
| 31 #define kDefaultExtensionID "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | |
| 32 | |
| 33 const std::wstring kSubscribePage = | 30 const std::wstring kSubscribePage = |
| 34 L"files/extensions/samples/subscribe_page_action/subscribe.html"; | 31 L"files/extensions/samples/subscribe_page_action/subscribe.html"; |
| 35 const std::wstring kValidFeed0 = L"files/feeds/feed_script.xml"; | 32 const std::wstring kValidFeed0 = L"files/feeds/feed_script.xml"; |
| 36 const std::wstring kValidFeed1 = L"files/feeds/feed1.xml"; | 33 const std::wstring kValidFeed1 = L"files/feeds/feed1.xml"; |
| 37 const std::wstring kValidFeed2 = L"files/feeds/feed2.xml"; | 34 const std::wstring kValidFeed2 = L"files/feeds/feed2.xml"; |
| 38 const std::wstring kValidFeed3 = L"files/feeds/feed3.xml"; | 35 const std::wstring kValidFeed3 = L"files/feeds/feed3.xml"; |
| 39 const std::wstring kValidFeed4 = L"files/feeds/feed4.xml"; | 36 const std::wstring kValidFeed4 = L"files/feeds/feed4.xml"; |
| 40 const std::wstring kValidFeed5 = L"files/feeds/feed5.xml"; | 37 const std::wstring kValidFeed5 = L"files/feeds/feed5.xml"; |
| 41 const std::wstring kInvalidFeed1 = L"files/feeds/feed_invalid1.xml"; | 38 const std::wstring kInvalidFeed1 = L"files/feeds/feed_invalid1.xml"; |
| 42 const std::wstring kInvalidFeed2 = L"files/feeds/feed_invalid2.xml"; | 39 const std::wstring kInvalidFeed2 = L"files/feeds/feed_invalid2.xml"; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 240 |
| 244 // Navigation prompts the location bar to load page actions. | 241 // Navigation prompts the location bar to load page actions. |
| 245 FilePath test_dir; | 242 FilePath test_dir; |
| 246 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); | 243 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); |
| 247 FilePath feed = test_dir.AppendASCII("feeds") | 244 FilePath feed = test_dir.AppendASCII("feeds") |
| 248 .AppendASCII("feed.html"); | 245 .AppendASCII("feed.html"); |
| 249 | 246 |
| 250 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(feed)); | 247 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(feed)); |
| 251 ASSERT_TRUE(WaitForPageActionCountChangeTo(1)); | 248 ASSERT_TRUE(WaitForPageActionCountChangeTo(1)); |
| 252 | 249 |
| 253 UnloadExtension(kDefaultExtensionID); | 250 UnloadExtension(last_loaded_extension_id_); |
| 254 | 251 |
| 255 // Make sure the page action goes away when it's unloaded. | 252 // Make sure the page action goes away when it's unloaded. |
| 256 ASSERT_TRUE(WaitForPageActionCountChangeTo(0)); | 253 ASSERT_TRUE(WaitForPageActionCountChangeTo(0)); |
| 257 } | 254 } |
| 258 #endif // defined(OS_WIN) || defined(OS_LINUX) | 255 #endif // defined(OS_WIN) || defined(OS_LINUX) |
| 259 | 256 |
| 260 GURL GetFeedUrl(HTTPTestServer* server, const std::wstring& feed_page) { | 257 GURL GetFeedUrl(HTTPTestServer* server, const std::wstring& feed_page) { |
| 261 static GURL base_url = server->TestServerPageW(kSubscribePage); | 258 static GURL base_url = server->TestServerPageW(kSubscribePage); |
| 262 GURL feed_url = server->TestServerPageW(feed_page); | 259 GURL feed_url = server->TestServerPageW(feed_page); |
| 263 return GURL(base_url.spec() + std::string("?") + feed_url.spec() + | 260 return GURL(base_url.spec() + std::string("?") + feed_url.spec() + |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 } | 612 } |
| 616 | 613 |
| 617 // Tests that an extension page can call window.open to an extension URL and | 614 // Tests that an extension page can call window.open to an extension URL and |
| 618 // the new window has extension privileges. | 615 // the new window has extension privileges. |
| 619 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { | 616 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
| 620 ASSERT_TRUE(LoadExtension( | 617 ASSERT_TRUE(LoadExtension( |
| 621 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 618 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 622 | 619 |
| 623 TabContents* newtab = WindowOpenHelper( | 620 TabContents* newtab = WindowOpenHelper( |
| 624 browser(), | 621 browser(), |
| 625 GURL("chrome-extension://" kDefaultExtensionID "/test.html"), | 622 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 623 "/test.html"), |
| 626 "newtab.html"); | 624 "newtab.html"); |
| 627 | 625 |
| 628 bool result = false; | 626 bool result = false; |
| 629 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 627 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 630 newtab->render_view_host(), L"", L"testExtensionApi()", &result); | 628 newtab->render_view_host(), L"", L"testExtensionApi()", &result); |
| 631 EXPECT_TRUE(result); | 629 EXPECT_TRUE(result); |
| 632 } | 630 } |
| 633 | 631 |
| 634 // Tests that if an extension page calls window.open to an invalid extension | 632 // Tests that if an extension page calls window.open to an invalid extension |
| 635 // URL, the browser doesn't crash. | 633 // URL, the browser doesn't crash. |
| 636 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { | 634 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) { |
| 637 ASSERT_TRUE(LoadExtension( | 635 ASSERT_TRUE(LoadExtension( |
| 638 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 636 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 639 | 637 |
| 640 WindowOpenHelper( | 638 WindowOpenHelper( |
| 641 browser(), | 639 browser(), |
| 642 GURL("chrome-extension://" kDefaultExtensionID "/test.html"), | 640 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 641 "/test.html"), |
| 643 "chrome-extension://thisissurelynotavalidextensionid/newtab.html"); | 642 "chrome-extension://thisissurelynotavalidextensionid/newtab.html"); |
| 644 | 643 |
| 645 // If we got to this point, we didn't crash, so we're good. | 644 // If we got to this point, we didn't crash, so we're good. |
| 646 } | 645 } |
| 647 | 646 |
| 648 // Tests that calling window.open from the newtab page to an extension URL | 647 // Tests that calling window.open from the newtab page to an extension URL |
| 649 // does not give the new window extension privileges - because the opening page | 648 // does not give the new window extension privileges - because the opening page |
| 650 // does not have extension privileges. | 649 // does not have extension privileges. |
| 651 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { | 650 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) { |
| 652 ASSERT_TRUE(LoadExtension( | 651 ASSERT_TRUE(LoadExtension( |
| 653 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 652 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 654 | 653 |
| 655 TabContents* newtab = WindowOpenHelper( | 654 TabContents* newtab = WindowOpenHelper( |
| 656 browser(), | 655 browser(), |
| 657 GURL("about:blank"), | 656 GURL("about:blank"), |
| 658 "chrome-extension://" kDefaultExtensionID "/newtab.html"); | 657 std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 658 "/newtab.html"); |
| 659 | 659 |
| 660 // Extension API should fail. | 660 // Extension API should fail. |
| 661 bool result = false; | 661 bool result = false; |
| 662 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 662 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 663 newtab->render_view_host(), L"", L"testExtensionApi()", &result); | 663 newtab->render_view_host(), L"", L"testExtensionApi()", &result); |
| 664 EXPECT_FALSE(result); | 664 EXPECT_FALSE(result); |
| 665 } | 665 } |
| 666 | 666 |
| 667 // Tests that a renderer's plugin list is properly updated when we load and | 667 // Tests that a renderer's plugin list is properly updated when we load and |
| 668 // unload an extension that contains a plugin. | 668 // unload an extension that contains a plugin. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 tab->render_view_host(), L"", L"testPluginWorks()", &result); | 707 tab->render_view_host(), L"", L"testPluginWorks()", &result); |
| 708 EXPECT_TRUE(result); | 708 EXPECT_TRUE(result); |
| 709 browser()->Reload(); | 709 browser()->Reload(); |
| 710 ui_test_utils::WaitForNavigationInCurrentTab(browser()); | 710 ui_test_utils::WaitForNavigationInCurrentTab(browser()); |
| 711 | 711 |
| 712 ui_test_utils::ExecuteJavaScriptAndExtractBool( | 712 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 713 tab->render_view_host(), L"", L"testPluginWorks()", &result); | 713 tab->render_view_host(), L"", L"testPluginWorks()", &result); |
| 714 EXPECT_FALSE(result); | 714 EXPECT_FALSE(result); |
| 715 } | 715 } |
| 716 #endif | 716 #endif |
| OLD | NEW |