| 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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/extensions/extension_action.h" | 6 #include "chrome/browser/extensions/extension_action.h" |
| 7 #include "chrome/browser/extensions/extension_action_manager.h" | 7 #include "chrome/browser/extensions/extension_action_manager.h" |
| 8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/extensions/api/content_scripts/content_scripts_handler.h
" |
| 15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/manifest_handler.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 17 | 19 |
| 18 namespace extensions { | 20 namespace extensions { |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 const std::string kFeedPage = "files/feeds/feed.html"; | 23 const std::string kFeedPage = "files/feeds/feed.html"; |
| 22 const std::string kNoFeedPage = "files/feeds/no_feed.html"; | 24 const std::string kNoFeedPage = "files/feeds/no_feed.html"; |
| 23 const std::string kLocalization = | 25 const std::string kLocalization = |
| 24 "files/extensions/browsertest/title_localized_pa/simple.html"; | 26 "files/extensions/browsertest/title_localized_pa/simple.html"; |
| 25 | 27 |
| 26 const std::string kHashPageA = | 28 const std::string kHashPageA = |
| 27 "files/extensions/api_test/page_action/hash_change/test_page_A.html"; | 29 "files/extensions/api_test/page_action/hash_change/test_page_A.html"; |
| 28 const std::string kHashPageAHash = kHashPageA + "#asdf"; | 30 const std::string kHashPageAHash = kHashPageA + "#asdf"; |
| 29 const std::string kHashPageB = | 31 const std::string kHashPageB = |
| 30 "files/extensions/api_test/page_action/hash_change/test_page_B.html"; | 32 "files/extensions/api_test/page_action/hash_change/test_page_B.html"; |
| 31 | 33 |
| 32 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionCrash25562) { | 34 class PageActionBrowserTest : public ExtensionBrowserTest { |
| 35 protected: |
| 36 virtual void SetUpOnMainThread() OVERRIDE { |
| 37 ExtensionBrowserTest::SetUpOnMainThread(); |
| 38 (new ContentScriptsHandler)->Register(); |
| 39 } |
| 40 |
| 41 virtual void CleanUpOnMainThread() OVERRIDE { |
| 42 ManifestHandler::ClearRegistryForTesting(); |
| 43 ExtensionBrowserTest::CleanUpOnMainThread(); |
| 44 } |
| 45 }; |
| 46 |
| 47 IN_PROC_BROWSER_TEST_F(PageActionBrowserTest, PageActionCrash25562) { |
| 33 ASSERT_TRUE(test_server()->Start()); | 48 ASSERT_TRUE(test_server()->Start()); |
| 34 | 49 |
| 35 CommandLine::ForCurrentProcess()->AppendSwitch( | 50 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 36 switches::kAllowLegacyExtensionManifests); | 51 switches::kAllowLegacyExtensionManifests); |
| 37 | 52 |
| 38 // This page action will not show an icon, since it doesn't specify one but | 53 // This page action will not show an icon, since it doesn't specify one but |
| 39 // is included here to test for a crash (http://crbug.com/25562). | 54 // is included here to test for a crash (http://crbug.com/25562). |
| 40 ASSERT_TRUE(LoadExtension( | 55 ASSERT_TRUE(LoadExtension( |
| 41 test_data_dir_.AppendASCII("browsertest") | 56 test_data_dir_.AppendASCII("browsertest") |
| 42 .AppendASCII("crash_25562"))); | 57 .AppendASCII("crash_25562"))); |
| 43 | 58 |
| 44 // Navigate to the feed page. | 59 // Navigate to the feed page. |
| 45 GURL feed_url = test_server()->GetURL(kFeedPage); | 60 GURL feed_url = test_server()->GetURL(kFeedPage); |
| 46 ui_test_utils::NavigateToURL(browser(), feed_url); | 61 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 47 // We should now have one page action ready to go in the LocationBar. | 62 // We should now have one page action ready to go in the LocationBar. |
| 48 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 63 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 49 } | 64 } |
| 50 | 65 |
| 51 // Tests that we can load page actions in the Omnibox. | 66 // Tests that we can load page actions in the Omnibox. |
| 52 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { | 67 IN_PROC_BROWSER_TEST_F(PageActionBrowserTest, PageAction) { |
| 53 ASSERT_TRUE(test_server()->Start()); | 68 ASSERT_TRUE(test_server()->Start()); |
| 54 | 69 |
| 55 ASSERT_TRUE(LoadExtension( | 70 ASSERT_TRUE(LoadExtension( |
| 56 test_data_dir_.AppendASCII("subscribe_page_action"))); | 71 test_data_dir_.AppendASCII("subscribe_page_action"))); |
| 57 | 72 |
| 58 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 73 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
| 59 | 74 |
| 60 // Navigate to the feed page. | 75 // Navigate to the feed page. |
| 61 GURL feed_url = test_server()->GetURL(kFeedPage); | 76 GURL feed_url = test_server()->GetURL(kFeedPage); |
| 62 ui_test_utils::NavigateToURL(browser(), feed_url); | 77 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 63 // We should now have one page action ready to go in the LocationBar. | 78 // We should now have one page action ready to go in the LocationBar. |
| 64 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 79 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 65 | 80 |
| 66 // Navigate to a page with no feed. | 81 // Navigate to a page with no feed. |
| 67 GURL no_feed = test_server()->GetURL(kNoFeedPage); | 82 GURL no_feed = test_server()->GetURL(kNoFeedPage); |
| 68 ui_test_utils::NavigateToURL(browser(), no_feed); | 83 ui_test_utils::NavigateToURL(browser(), no_feed); |
| 69 // Make sure the page action goes away. | 84 // Make sure the page action goes away. |
| 70 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 85 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
| 71 } | 86 } |
| 72 | 87 |
| 73 // Tests that we don't lose the page action icon on in-page navigations. | 88 // Tests that we don't lose the page action icon on in-page navigations. |
| 74 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) { | 89 IN_PROC_BROWSER_TEST_F(PageActionBrowserTest, PageActionInPageNavigation) { |
| 75 ASSERT_TRUE(test_server()->Start()); | 90 ASSERT_TRUE(test_server()->Start()); |
| 76 | 91 |
| 77 base::FilePath extension_path(test_data_dir_.AppendASCII("api_test") | 92 base::FilePath extension_path(test_data_dir_.AppendASCII("api_test") |
| 78 .AppendASCII("page_action") | 93 .AppendASCII("page_action") |
| 79 .AppendASCII("hash_change")); | 94 .AppendASCII("hash_change")); |
| 80 ASSERT_TRUE(LoadExtension(extension_path)); | 95 ASSERT_TRUE(LoadExtension(extension_path)); |
| 81 | 96 |
| 82 // Page action should become visible when we navigate here. | 97 // Page action should become visible when we navigate here. |
| 83 GURL feed_url = test_server()->GetURL(kHashPageA); | 98 GURL feed_url = test_server()->GetURL(kHashPageA); |
| 84 ui_test_utils::NavigateToURL(browser(), feed_url); | 99 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 85 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 100 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 86 | 101 |
| 87 // In-page navigation, page action should remain. | 102 // In-page navigation, page action should remain. |
| 88 feed_url = test_server()->GetURL(kHashPageAHash); | 103 feed_url = test_server()->GetURL(kHashPageAHash); |
| 89 ui_test_utils::NavigateToURL(browser(), feed_url); | 104 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 90 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 105 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 91 | 106 |
| 92 // Not an in-page navigation, page action should go away. | 107 // Not an in-page navigation, page action should go away. |
| 93 feed_url = test_server()->GetURL(kHashPageB); | 108 feed_url = test_server()->GetURL(kHashPageB); |
| 94 ui_test_utils::NavigateToURL(browser(), feed_url); | 109 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 95 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 110 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
| 96 } | 111 } |
| 97 | 112 |
| 98 // Tests that the location bar forgets about unloaded page actions. | 113 // Tests that the location bar forgets about unloaded page actions. |
| 99 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { | 114 IN_PROC_BROWSER_TEST_F(PageActionBrowserTest, UnloadPageAction) { |
| 100 ASSERT_TRUE(test_server()->Start()); | 115 ASSERT_TRUE(test_server()->Start()); |
| 101 | 116 |
| 102 base::FilePath extension_path( | 117 base::FilePath extension_path( |
| 103 test_data_dir_.AppendASCII("subscribe_page_action")); | 118 test_data_dir_.AppendASCII("subscribe_page_action")); |
| 104 ASSERT_TRUE(LoadExtension(extension_path)); | 119 ASSERT_TRUE(LoadExtension(extension_path)); |
| 105 | 120 |
| 106 // Navigation prompts the location bar to load page actions. | 121 // Navigation prompts the location bar to load page actions. |
| 107 GURL feed_url = test_server()->GetURL(kFeedPage); | 122 GURL feed_url = test_server()->GetURL(kFeedPage); |
| 108 ui_test_utils::NavigateToURL(browser(), feed_url); | 123 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 109 ASSERT_TRUE(WaitForPageActionCountChangeTo(1)); | 124 ASSERT_TRUE(WaitForPageActionCountChangeTo(1)); |
| 110 | 125 |
| 111 UnloadExtension(last_loaded_extension_id_); | 126 UnloadExtension(last_loaded_extension_id_); |
| 112 | 127 |
| 113 // Make sure the page action goes away when it's unloaded. | 128 // Make sure the page action goes away when it's unloaded. |
| 114 ASSERT_TRUE(WaitForPageActionCountChangeTo(0)); | 129 ASSERT_TRUE(WaitForPageActionCountChangeTo(0)); |
| 115 } | 130 } |
| 116 | 131 |
| 117 // Tests that we can load page actions in the Omnibox. | 132 // Tests that we can load page actions in the Omnibox. |
| 118 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) { | 133 IN_PROC_BROWSER_TEST_F(PageActionBrowserTest, PageActionRefreshCrash) { |
| 119 base::TimeTicks start_time = base::TimeTicks::Now(); | 134 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 120 | 135 |
| 121 ExtensionService* service = extensions::ExtensionSystem::Get( | 136 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 122 browser()->profile())->extension_service(); | 137 browser()->profile())->extension_service(); |
| 123 | 138 |
| 124 size_t size_before = service->extensions()->size(); | 139 size_t size_before = service->extensions()->size(); |
| 125 | 140 |
| 126 base::FilePath base_path = test_data_dir_.AppendASCII("browsertest") | 141 base::FilePath base_path = test_data_dir_.AppendASCII("browsertest") |
| 127 .AppendASCII("crash_44415"); | 142 .AppendASCII("crash_44415"); |
| 128 // Load extension A. | 143 // Load extension A. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // This is where it would crash, before http://crbug.com/44415 was fixed. | 179 // This is where it would crash, before http://crbug.com/44415 was fixed. |
| 165 ReloadExtension(extensionA->id()); | 180 ReloadExtension(extensionA->id()); |
| 166 | 181 |
| 167 LOG(INFO) << "Test completed : " | 182 LOG(INFO) << "Test completed : " |
| 168 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 183 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 169 << " ms" << std::flush; | 184 << " ms" << std::flush; |
| 170 } | 185 } |
| 171 | 186 |
| 172 // Tests that tooltips of a page action icon can be specified using UTF8. | 187 // Tests that tooltips of a page action icon can be specified using UTF8. |
| 173 // See http://crbug.com/25349. | 188 // See http://crbug.com/25349. |
| 174 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { | 189 IN_PROC_BROWSER_TEST_F(PageActionBrowserTest, TitleLocalizationPageAction) { |
| 175 ASSERT_TRUE(test_server()->Start()); | 190 ASSERT_TRUE(test_server()->Start()); |
| 176 | 191 |
| 177 ExtensionService* service = extensions::ExtensionSystem::Get( | 192 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 178 browser()->profile())->extension_service(); | 193 browser()->profile())->extension_service(); |
| 179 const size_t size_before = service->extensions()->size(); | 194 const size_t size_before = service->extensions()->size(); |
| 180 | 195 |
| 181 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest") | 196 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest") |
| 182 .AppendASCII("title_localized_pa")); | 197 .AppendASCII("title_localized_pa")); |
| 183 const Extension* extension = LoadExtension(extension_path); | 198 const Extension* extension = LoadExtension(extension_path); |
| 184 ASSERT_TRUE(extension); | 199 ASSERT_TRUE(extension); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 197 int tab_id = ExtensionTabUtil::GetTabId( | 212 int tab_id = ExtensionTabUtil::GetTabId( |
| 198 browser()->tab_strip_model()->GetActiveWebContents()); | 213 browser()->tab_strip_model()->GetActiveWebContents()); |
| 199 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), | 214 EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), |
| 200 ExtensionActionManager::Get(browser()->profile())-> | 215 ExtensionActionManager::Get(browser()->profile())-> |
| 201 GetPageAction(*extension)-> | 216 GetPageAction(*extension)-> |
| 202 GetTitle(tab_id).c_str()); | 217 GetTitle(tab_id).c_str()); |
| 203 } | 218 } |
| 204 | 219 |
| 205 } // namespace | 220 } // namespace |
| 206 } // namespace extensions | 221 } // namespace extensions |
| OLD | NEW |