| 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/strings/utf_string_conversions.h" | 5 #include "base/strings/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_action_test_util.h" | 8 #include "chrome/browser/extensions/extension_action_test_util.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 17 #include "extensions/common/switches.h" | 17 #include "extensions/common/switches.h" |
| 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const std::string kFeedPage = "files/feeds/feed.html"; | 23 const std::string kFeedPage = "/feeds/feed.html"; |
| 23 const std::string kNoFeedPage = "files/feeds/no_feed.html"; | 24 const std::string kNoFeedPage = "/feeds/no_feed.html"; |
| 24 const std::string kLocalization = | 25 const std::string kLocalization = |
| 25 "files/extensions/browsertest/title_localized_pa/simple.html"; | 26 "/extensions/browsertest/title_localized_pa/simple.html"; |
| 26 | 27 |
| 27 const std::string kHashPageA = | 28 const std::string kHashPageA = |
| 28 "files/extensions/api_test/page_action/hash_change/test_page_A.html"; | 29 "/extensions/api_test/page_action/hash_change/test_page_A.html"; |
| 29 const std::string kHashPageAHash = kHashPageA + "#asdf"; | 30 const std::string kHashPageAHash = kHashPageA + "#asdf"; |
| 30 const std::string kHashPageB = | 31 const std::string kHashPageB = |
| 31 "files/extensions/api_test/page_action/hash_change/test_page_B.html"; | 32 "/extensions/api_test/page_action/hash_change/test_page_B.html"; |
| 32 | 33 |
| 33 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionCrash25562) { | 34 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionCrash25562) { |
| 34 ASSERT_TRUE(test_server()->Start()); | 35 ASSERT_TRUE(embedded_test_server()->Start()); |
| 35 | 36 |
| 36 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 37 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 37 switches::kAllowLegacyExtensionManifests); | 38 switches::kAllowLegacyExtensionManifests); |
| 38 | 39 |
| 39 // This page action will not show an icon, since it doesn't specify one but | 40 // This page action will not show an icon, since it doesn't specify one but |
| 40 // is included here to test for a crash (http://crbug.com/25562). | 41 // is included here to test for a crash (http://crbug.com/25562). |
| 41 ASSERT_TRUE(LoadExtension( | 42 ASSERT_TRUE(LoadExtension( |
| 42 test_data_dir_.AppendASCII("browsertest") | 43 test_data_dir_.AppendASCII("browsertest") |
| 43 .AppendASCII("crash_25562"))); | 44 .AppendASCII("crash_25562"))); |
| 44 | 45 |
| 45 // Navigate to the feed page. | 46 // Navigate to the feed page. |
| 46 GURL feed_url = test_server()->GetURL(kFeedPage); | 47 GURL feed_url = embedded_test_server()->GetURL(kFeedPage); |
| 47 ui_test_utils::NavigateToURL(browser(), feed_url); | 48 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 48 // We should now have one page action ready to go in the LocationBar. | 49 // We should now have one page action ready to go in the LocationBar. |
| 49 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 50 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // Tests that we can load page actions in the Omnibox. | 53 // Tests that we can load page actions in the Omnibox. |
| 53 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { | 54 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { |
| 54 ASSERT_TRUE(test_server()->Start()); | 55 ASSERT_TRUE(embedded_test_server()->Start()); |
| 55 | 56 |
| 56 ASSERT_TRUE(LoadExtension( | 57 ASSERT_TRUE(LoadExtension( |
| 57 test_data_dir_.AppendASCII("subscribe_page_action"))); | 58 test_data_dir_.AppendASCII("subscribe_page_action"))); |
| 58 | 59 |
| 59 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 60 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
| 60 | 61 |
| 61 // Navigate to the feed page. | 62 // Navigate to the feed page. |
| 62 GURL feed_url = test_server()->GetURL(kFeedPage); | 63 GURL feed_url = embedded_test_server()->GetURL(kFeedPage); |
| 63 ui_test_utils::NavigateToURL(browser(), feed_url); | 64 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 64 // We should now have one page action ready to go in the LocationBar. | 65 // We should now have one page action ready to go in the LocationBar. |
| 65 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 66 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 66 | 67 |
| 67 // Navigate to a page with no feed. | 68 // Navigate to a page with no feed. |
| 68 GURL no_feed = test_server()->GetURL(kNoFeedPage); | 69 GURL no_feed = embedded_test_server()->GetURL(kNoFeedPage); |
| 69 ui_test_utils::NavigateToURL(browser(), no_feed); | 70 ui_test_utils::NavigateToURL(browser(), no_feed); |
| 70 // Make sure the page action goes away. | 71 // Make sure the page action goes away. |
| 71 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 72 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
| 72 } | 73 } |
| 73 | 74 |
| 74 // Tests that we don't lose the page action icon on in-page navigations. | 75 // Tests that we don't lose the page action icon on in-page navigations. |
| 75 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) { | 76 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) { |
| 76 ASSERT_TRUE(test_server()->Start()); | 77 ASSERT_TRUE(embedded_test_server()->Start()); |
| 77 | 78 |
| 78 base::FilePath extension_path(test_data_dir_.AppendASCII("api_test") | 79 base::FilePath extension_path(test_data_dir_.AppendASCII("api_test") |
| 79 .AppendASCII("page_action") | 80 .AppendASCII("page_action") |
| 80 .AppendASCII("hash_change")); | 81 .AppendASCII("hash_change")); |
| 81 ASSERT_TRUE(LoadExtension(extension_path)); | 82 ASSERT_TRUE(LoadExtension(extension_path)); |
| 82 | 83 |
| 83 // Page action should become visible when we navigate here. | 84 // Page action should become visible when we navigate here. |
| 84 GURL feed_url = test_server()->GetURL(kHashPageA); | 85 GURL feed_url = embedded_test_server()->GetURL(kHashPageA); |
| 85 ui_test_utils::NavigateToURL(browser(), feed_url); | 86 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 86 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 87 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 87 | 88 |
| 88 // In-page navigation, page action should remain. | 89 // In-page navigation, page action should remain. |
| 89 feed_url = test_server()->GetURL(kHashPageAHash); | 90 feed_url = embedded_test_server()->GetURL(kHashPageAHash); |
| 90 ui_test_utils::NavigateToURL(browser(), feed_url); | 91 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 91 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 92 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 92 | 93 |
| 93 // Not an in-page navigation, page action should go away. | 94 // Not an in-page navigation, page action should go away. |
| 94 feed_url = test_server()->GetURL(kHashPageB); | 95 feed_url = embedded_test_server()->GetURL(kHashPageB); |
| 95 ui_test_utils::NavigateToURL(browser(), feed_url); | 96 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 96 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); | 97 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 // Tests that the location bar forgets about unloaded page actions. | 100 // Tests that the location bar forgets about unloaded page actions. |
| 100 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { | 101 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { |
| 101 ASSERT_TRUE(test_server()->Start()); | 102 ASSERT_TRUE(embedded_test_server()->Start()); |
| 102 | 103 |
| 103 base::FilePath extension_path( | 104 base::FilePath extension_path( |
| 104 test_data_dir_.AppendASCII("subscribe_page_action")); | 105 test_data_dir_.AppendASCII("subscribe_page_action")); |
| 105 ASSERT_TRUE(LoadExtension(extension_path)); | 106 ASSERT_TRUE(LoadExtension(extension_path)); |
| 106 | 107 |
| 107 // Navigation prompts the location bar to load page actions. | 108 // Navigation prompts the location bar to load page actions. |
| 108 GURL feed_url = test_server()->GetURL(kFeedPage); | 109 GURL feed_url = embedded_test_server()->GetURL(kFeedPage); |
| 109 ui_test_utils::NavigateToURL(browser(), feed_url); | 110 ui_test_utils::NavigateToURL(browser(), feed_url); |
| 110 content::WebContents* tab = | 111 content::WebContents* tab = |
| 111 browser()->tab_strip_model()->GetActiveWebContents(); | 112 browser()->tab_strip_model()->GetActiveWebContents(); |
| 112 EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab)); | 113 EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab)); |
| 113 | 114 |
| 114 UnloadExtension(last_loaded_extension_id()); | 115 UnloadExtension(last_loaded_extension_id()); |
| 115 | 116 |
| 116 // Make sure the page action goes away when it's unloaded. | 117 // Make sure the page action goes away when it's unloaded. |
| 117 EXPECT_EQ(0u, extension_action_test_util::GetTotalPageActionCount(tab)); | 118 EXPECT_EQ(0u, extension_action_test_util::GetTotalPageActionCount(tab)); |
| 118 } | 119 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 ReloadExtension(extensionA->id()); | 169 ReloadExtension(extensionA->id()); |
| 169 | 170 |
| 170 LOG(INFO) << "Test completed : " | 171 LOG(INFO) << "Test completed : " |
| 171 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 172 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 172 << " ms" << std::flush; | 173 << " ms" << std::flush; |
| 173 } | 174 } |
| 174 | 175 |
| 175 // Tests that tooltips of a page action icon can be specified using UTF8. | 176 // Tests that tooltips of a page action icon can be specified using UTF8. |
| 176 // See http://crbug.com/25349. | 177 // See http://crbug.com/25349. |
| 177 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { | 178 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { |
| 178 ASSERT_TRUE(test_server()->Start()); | 179 ASSERT_TRUE(embedded_test_server()->Start()); |
| 179 | 180 |
| 180 ExtensionRegistry* registry = | 181 ExtensionRegistry* registry = |
| 181 extensions::ExtensionRegistry::Get(browser()->profile()); | 182 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 182 const size_t size_before = registry->enabled_extensions().size(); | 183 const size_t size_before = registry->enabled_extensions().size(); |
| 183 | 184 |
| 184 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest") | 185 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest") |
| 185 .AppendASCII("title_localized_pa")); | 186 .AppendASCII("title_localized_pa")); |
| 186 const Extension* extension = LoadExtension(extension_path); | 187 const Extension* extension = LoadExtension(extension_path); |
| 187 ASSERT_TRUE(extension); | 188 ASSERT_TRUE(extension); |
| 188 | 189 |
| 189 // Any navigation prompts the location bar to load the page action. | 190 // Any navigation prompts the location bar to load the page action. |
| 190 GURL url = test_server()->GetURL(kLocalization); | 191 GURL url = embedded_test_server()->GetURL(kLocalization); |
| 191 ui_test_utils::NavigateToURL(browser(), url); | 192 ui_test_utils::NavigateToURL(browser(), url); |
| 192 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 193 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 193 | 194 |
| 194 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); | 195 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 195 | 196 |
| 196 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), | 197 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), |
| 197 extension->description().c_str()); | 198 extension->description().c_str()); |
| 198 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), | 199 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), |
| 199 extension->name().c_str()); | 200 extension->name().c_str()); |
| 200 int tab_id = ExtensionTabUtil::GetTabId( | 201 int tab_id = ExtensionTabUtil::GetTabId( |
| 201 browser()->tab_strip_model()->GetActiveWebContents()); | 202 browser()->tab_strip_model()->GetActiveWebContents()); |
| 202 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur").c_str(), | 203 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur").c_str(), |
| 203 ExtensionActionManager::Get(browser()->profile())-> | 204 ExtensionActionManager::Get(browser()->profile())-> |
| 204 GetPageAction(*extension)-> | 205 GetPageAction(*extension)-> |
| 205 GetTitle(tab_id).c_str()); | 206 GetTitle(tab_id).c_str()); |
| 206 } | 207 } |
| 207 | 208 |
| 208 } // namespace | 209 } // namespace |
| 209 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |