| 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_service.h" | |
| 11 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
| 12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 18 #include "extensions/common/switches.h" | 17 #include "extensions/common/switches.h" |
| 19 | 18 |
| 20 namespace extensions { | 19 namespace extensions { |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 const std::string kFeedPage = "files/feeds/feed.html"; | 22 const std::string kFeedPage = "files/feeds/feed.html"; |
| 24 const std::string kNoFeedPage = "files/feeds/no_feed.html"; | 23 const std::string kNoFeedPage = "files/feeds/no_feed.html"; |
| 25 const std::string kLocalization = | 24 const std::string kLocalization = |
| 26 "files/extensions/browsertest/title_localized_pa/simple.html"; | 25 "files/extensions/browsertest/title_localized_pa/simple.html"; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 UnloadExtension(last_loaded_extension_id()); | 114 UnloadExtension(last_loaded_extension_id()); |
| 116 | 115 |
| 117 // Make sure the page action goes away when it's unloaded. | 116 // Make sure the page action goes away when it's unloaded. |
| 118 EXPECT_EQ(0u, extension_action_test_util::GetTotalPageActionCount(tab)); | 117 EXPECT_EQ(0u, extension_action_test_util::GetTotalPageActionCount(tab)); |
| 119 } | 118 } |
| 120 | 119 |
| 121 // Tests that we can load page actions in the Omnibox. | 120 // Tests that we can load page actions in the Omnibox. |
| 122 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) { | 121 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) { |
| 123 base::TimeTicks start_time = base::TimeTicks::Now(); | 122 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 124 | 123 |
| 125 ExtensionService* service = extensions::ExtensionSystem::Get( | 124 ExtensionRegistry* registry = |
| 126 browser()->profile())->extension_service(); | 125 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 127 | 126 |
| 128 size_t size_before = service->extensions()->size(); | 127 size_t size_before = registry->enabled_extensions().size(); |
| 129 | 128 |
| 130 base::FilePath base_path = test_data_dir_.AppendASCII("browsertest") | 129 base::FilePath base_path = test_data_dir_.AppendASCII("browsertest") |
| 131 .AppendASCII("crash_44415"); | 130 .AppendASCII("crash_44415"); |
| 132 // Load extension A. | 131 // Load extension A. |
| 133 const Extension* extensionA = LoadExtension(base_path.AppendASCII("ExtA")); | 132 const Extension* extensionA = LoadExtension(base_path.AppendASCII("ExtA")); |
| 134 ASSERT_TRUE(extensionA); | 133 ASSERT_TRUE(extensionA); |
| 135 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 134 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 136 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 135 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 137 | 136 |
| 138 LOG(INFO) << "Load extension A done : " | 137 LOG(INFO) << "Load extension A done : " |
| 139 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 138 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 140 << " ms" << std::flush; | 139 << " ms" << std::flush; |
| 141 | 140 |
| 142 // Load extension B. | 141 // Load extension B. |
| 143 const Extension* extensionB = LoadExtension(base_path.AppendASCII("ExtB")); | 142 const Extension* extensionB = LoadExtension(base_path.AppendASCII("ExtB")); |
| 144 ASSERT_TRUE(extensionB); | 143 ASSERT_TRUE(extensionB); |
| 145 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(2)); | 144 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(2)); |
| 146 ASSERT_EQ(size_before + 2, service->extensions()->size()); | 145 ASSERT_EQ(size_before + 2, registry->enabled_extensions().size()); |
| 147 | 146 |
| 148 LOG(INFO) << "Load extension B done : " | 147 LOG(INFO) << "Load extension B done : " |
| 149 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 148 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 150 << " ms" << std::flush; | 149 << " ms" << std::flush; |
| 151 | 150 |
| 152 std::string idA = extensionA->id(); | 151 std::string idA = extensionA->id(); |
| 153 ReloadExtension(extensionA->id()); | 152 ReloadExtension(extensionA->id()); |
| 154 // ExtensionA has changed, so refetch it. | 153 // ExtensionA has changed, so refetch it. |
| 155 ASSERT_EQ(size_before + 2, service->extensions()->size()); | 154 ASSERT_EQ(size_before + 2, registry->enabled_extensions().size()); |
| 156 extensionA = service->extensions()->GetByID(idA); | 155 extensionA = registry->enabled_extensions().GetByID(idA); |
| 157 | 156 |
| 158 LOG(INFO) << "Reload extension A done: " | 157 LOG(INFO) << "Reload extension A done: " |
| 159 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 158 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 160 << " ms" << std::flush; | 159 << " ms" << std::flush; |
| 161 | 160 |
| 162 ReloadExtension(extensionB->id()); | 161 ReloadExtension(extensionB->id()); |
| 163 | 162 |
| 164 LOG(INFO) << "Reload extension B done: " | 163 LOG(INFO) << "Reload extension B done: " |
| 165 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 164 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 166 << " ms" << std::flush; | 165 << " ms" << std::flush; |
| 167 | 166 |
| 168 // This is where it would crash, before http://crbug.com/44415 was fixed. | 167 // This is where it would crash, before http://crbug.com/44415 was fixed. |
| 169 ReloadExtension(extensionA->id()); | 168 ReloadExtension(extensionA->id()); |
| 170 | 169 |
| 171 LOG(INFO) << "Test completed : " | 170 LOG(INFO) << "Test completed : " |
| 172 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 171 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
| 173 << " ms" << std::flush; | 172 << " ms" << std::flush; |
| 174 } | 173 } |
| 175 | 174 |
| 176 // Tests that tooltips of a page action icon can be specified using UTF8. | 175 // Tests that tooltips of a page action icon can be specified using UTF8. |
| 177 // See http://crbug.com/25349. | 176 // See http://crbug.com/25349. |
| 178 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { | 177 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { |
| 179 ASSERT_TRUE(test_server()->Start()); | 178 ASSERT_TRUE(test_server()->Start()); |
| 180 | 179 |
| 181 ExtensionService* service = extensions::ExtensionSystem::Get( | 180 ExtensionRegistry* registry = |
| 182 browser()->profile())->extension_service(); | 181 extensions::ExtensionRegistry::Get(browser()->profile()); |
| 183 const size_t size_before = service->extensions()->size(); | 182 const size_t size_before = registry->enabled_extensions().size(); |
| 184 | 183 |
| 185 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest") | 184 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest") |
| 186 .AppendASCII("title_localized_pa")); | 185 .AppendASCII("title_localized_pa")); |
| 187 const Extension* extension = LoadExtension(extension_path); | 186 const Extension* extension = LoadExtension(extension_path); |
| 188 ASSERT_TRUE(extension); | 187 ASSERT_TRUE(extension); |
| 189 | 188 |
| 190 // Any navigation prompts the location bar to load the page action. | 189 // Any navigation prompts the location bar to load the page action. |
| 191 GURL url = test_server()->GetURL(kLocalization); | 190 GURL url = test_server()->GetURL(kLocalization); |
| 192 ui_test_utils::NavigateToURL(browser(), url); | 191 ui_test_utils::NavigateToURL(browser(), url); |
| 193 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 192 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
| 194 | 193 |
| 195 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 194 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 196 | 195 |
| 197 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), | 196 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), |
| 198 extension->description().c_str()); | 197 extension->description().c_str()); |
| 199 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), | 198 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), |
| 200 extension->name().c_str()); | 199 extension->name().c_str()); |
| 201 int tab_id = ExtensionTabUtil::GetTabId( | 200 int tab_id = ExtensionTabUtil::GetTabId( |
| 202 browser()->tab_strip_model()->GetActiveWebContents()); | 201 browser()->tab_strip_model()->GetActiveWebContents()); |
| 203 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur").c_str(), | 202 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur").c_str(), |
| 204 ExtensionActionManager::Get(browser()->profile())-> | 203 ExtensionActionManager::Get(browser()->profile())-> |
| 205 GetPageAction(*extension)-> | 204 GetPageAction(*extension)-> |
| 206 GetTitle(tab_id).c_str()); | 205 GetTitle(tab_id).c_str()); |
| 207 } | 206 } |
| 208 | 207 |
| 209 } // namespace | 208 } // namespace |
| 210 } // namespace extensions | 209 } // namespace extensions |
| OLD | NEW |