diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 21:17:32 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 21:17:32 +0000 |
commit | d80692b0a784183023239e6812e19bf810926e33 (patch) | |
tree | d207c7b04fb174a0e7fd36fcd5a0bed0c369fcfe | |
parent | ee93d54c7ae18cdb3414e053f92e287a34479670 (diff) | |
download | chromium_src-d80692b0a784183023239e6812e19bf810926e33.zip chromium_src-d80692b0a784183023239e6812e19bf810926e33.tar.gz chromium_src-d80692b0a784183023239e6812e19bf810926e33.tar.bz2 |
Support localization for browser actions and page action
tooltips.
BUG=25349
TEST=Browser test added.
Review URL: http://codereview.chromium.org/385096
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31945 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 103 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 0c02b92..a10446f 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -10,6 +10,7 @@ #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" +#include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/extension_updater.h" #include "chrome/browser/profile.h" @@ -256,6 +257,56 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { // Make sure the page action goes away when it's unloaded. ASSERT_TRUE(WaitForPageActionCountChangeTo(0)); } + +// Tests that tooltips of a browser action icon can be specified using UTF8. +// See http://crbug.com/25349. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationBrowserAction) { + FilePath extension_path(test_data_dir_.AppendASCII("browsertest") + .AppendASCII("title_localized")); + ASSERT_TRUE(LoadExtension(extension_path)); + + ExtensionsService* service = browser()->profile()->GetExtensionsService(); + const ExtensionList* extensions = service->extensions(); + ASSERT_EQ(1u, extensions->size()); + Extension* extension = extensions->at(0); + + EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n browser action").c_str(), + extension->description().c_str()); + EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), + extension->name().c_str()); + int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); + EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), + extension->browser_action()->GetTitle(tab_id).c_str()); +} + +// Tests that tooltips of a page action icon can be specified using UTF8. +// See http://crbug.com/25349. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { + FilePath extension_path(test_data_dir_.AppendASCII("browsertest") + .AppendASCII("title_localized_pa")); + ASSERT_TRUE(LoadExtension(extension_path)); + + // Any navigation prompts the location bar to load the page action. + FilePath test_dir; + PathService::Get(chrome::DIR_TEST_DATA, &test_dir); + FilePath path = extension_path.AppendASCII("simple.html"); + + ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(path)); + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); + + ExtensionsService* service = browser()->profile()->GetExtensionsService(); + const ExtensionList* extensions = service->extensions(); + ASSERT_EQ(1u, extensions->size()); + Extension* extension = extensions->at(0); + + EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), + extension->description().c_str()); + EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), + extension->name().c_str()); + int tab_id = ExtensionTabUtil::GetTabId(browser()->GetSelectedTabContents()); + EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur").c_str(), + extension->page_action()->GetTitle(tab_id).c_str()); +} #endif // defined(OS_WIN) || defined(OS_LINUX) GURL GetFeedUrl(HTTPTestServer* server, const std::wstring& feed_page) { diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 9ef3feb..f3395a7 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -117,7 +117,7 @@ void BrowserActionButton::UpdateState() { else if (!default_icon_.isNull()) SetIcon(default_icon_); - SetTooltipText(ASCIIToWide(browser_action()->GetTitle(tab_id))); + SetTooltipText(UTF8ToWide(browser_action()->GetTitle(tab_id))); GetParent()->SchedulePaint(); } diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index b10acc1..f0931e4 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -1406,7 +1406,7 @@ void LocationBarView::PageActionImageView::UpdateVisibility( if (visible) { // Set the tooltip. tooltip_ = page_action_->GetTitle(current_tab_id_); - SetTooltipText(ASCIIToWide(tooltip_)); + SetTooltipText(UTF8ToWide(tooltip_)); // Set the image. // It can come from three places. In descending order of priority: diff --git a/chrome/test/data/extensions/browsertest/title_localized/chrome-16.png b/chrome/test/data/extensions/browsertest/title_localized/chrome-16.png Binary files differnew file mode 100644 index 0000000..a3a4f3a --- /dev/null +++ b/chrome/test/data/extensions/browsertest/title_localized/chrome-16.png diff --git a/chrome/test/data/extensions/browsertest/title_localized/manifest.json b/chrome/test/data/extensions/browsertest/title_localized/manifest.json new file mode 100644 index 0000000..e1c614c --- /dev/null +++ b/chrome/test/data/extensions/browsertest/title_localized/manifest.json @@ -0,0 +1,10 @@ +{ + "description": "Hreggvi\u00F0ur: l10n browser action", + "name": "Hreggvi\u00F0ur is my name", + "browser_action": { + "default_title": "Hreggvi\u00F0ur", + "default_icon": "chrome-16.png" + }, + "permissions": [ "http://*/*" ], + "version": "1.0" +} diff --git a/chrome/test/data/extensions/browsertest/title_localized_pa/background.html b/chrome/test/data/extensions/browsertest/title_localized_pa/background.html new file mode 100644 index 0000000..59db970 --- /dev/null +++ b/chrome/test/data/extensions/browsertest/title_localized_pa/background.html @@ -0,0 +1,11 @@ +<html> +<script> + chrome.self.onConnect.addListener(function(port) { + port.onMessage.addListener(function(mybool) { + // Let Chrome know that the PageAction needs to be enabled for this tabId + // and for the url of this page. + chrome.pageAction.show(port.tab.id); + }); + }); +</script> +</html> diff --git a/chrome/test/data/extensions/browsertest/title_localized_pa/chrome-16.png b/chrome/test/data/extensions/browsertest/title_localized_pa/chrome-16.png Binary files differnew file mode 100644 index 0000000..a3a4f3a --- /dev/null +++ b/chrome/test/data/extensions/browsertest/title_localized_pa/chrome-16.png diff --git a/chrome/test/data/extensions/browsertest/title_localized_pa/manifest.json b/chrome/test/data/extensions/browsertest/title_localized_pa/manifest.json new file mode 100644 index 0000000..59091af --- /dev/null +++ b/chrome/test/data/extensions/browsertest/title_localized_pa/manifest.json @@ -0,0 +1,15 @@ +{ + "background_page": "background.html", + "content_scripts": [ { + "js": [ "script.js" ], + "matches": [ "http://*/*", "file://*.*" ] + } ], + "description": "Hreggvi\u00F0ur: l10n page action", + "name": "Hreggvi\u00F0ur is my name", + "page_action": { + "default_title": "Hreggvi\u00F0ur", + "default_icon": "chrome-16.png" + }, + "permissions": [ "http://*/*" ], + "version": "1.0" +} diff --git a/chrome/test/data/extensions/browsertest/title_localized_pa/script.js b/chrome/test/data/extensions/browsertest/title_localized_pa/script.js new file mode 100644 index 0000000..b602eb8 --- /dev/null +++ b/chrome/test/data/extensions/browsertest/title_localized_pa/script.js @@ -0,0 +1,7 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +if (window == top) { + chrome.extension.connect().postMessage(true); +} diff --git a/chrome/test/data/extensions/browsertest/title_localized_pa/simple.html b/chrome/test/data/extensions/browsertest/title_localized_pa/simple.html new file mode 100644 index 0000000..0006175 --- /dev/null +++ b/chrome/test/data/extensions/browsertest/title_localized_pa/simple.html @@ -0,0 +1,7 @@ +<html> +<head> +</head> +<body> +This is a dead simple page. +</body> +</html>
\ No newline at end of file |