diff options
author | zhaoqin@google.com <zhaoqin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 15:17:44 +0000 |
---|---|---|
committer | zhaoqin@google.com <zhaoqin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-27 15:17:44 +0000 |
commit | 737646f8442352d8fb6a0f5be6728617d842a8e1 (patch) | |
tree | e96a3d2e00f6efa1f65dbb19e603e19a2a80ead2 /chrome/browser/intents | |
parent | e3a682b3f826c18ded918024b62da7e7c4c796f0 (diff) | |
download | chromium_src-737646f8442352d8fb6a0f5be6728617d842a8e1.zip chromium_src-737646f8442352d8fb6a0f5be6728617d842a8e1.tar.gz chromium_src-737646f8442352d8fb6a0f5be6728617d842a8e1.tar.bz2 |
Revert 148720 - [Web Intents] Localization of intent titles for CWS suggestions
R=mpcomplete@chromium.org,gbillock@chromium.org
BUG=130432
TEST=CWSIntentsRegistryTest.LocalizeMatchingLocale:ExtensionL10nUtil.GetAllFallbackLocales:ExtensionL10nUtil.LoadMessageCatalogs*
Review URL: https://chromiumcodereview.appspot.com/10790087
TBR=groby@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10821068
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/intents')
-rw-r--r-- | chrome/browser/intents/cws_intents_registry.cc | 45 | ||||
-rw-r--r-- | chrome/browser/intents/cws_intents_registry.h | 5 | ||||
-rw-r--r-- | chrome/browser/intents/cws_intents_registry_unittest.cc | 180 |
3 files changed, 31 insertions, 199 deletions
diff --git a/chrome/browser/intents/cws_intents_registry.cc b/chrome/browser/intents/cws_intents_registry.cc index 96fd943..78fc48b 100644 --- a/chrome/browser/intents/cws_intents_registry.cc +++ b/chrome/browser/intents/cws_intents_registry.cc @@ -10,8 +10,6 @@ #include "base/stl_util.h" #include "base/string16.h" #include "base/utf_string_conversions.h" -#include "chrome/common/extensions/extension_l10n_util.h" -#include "chrome/common/extensions/message_bundle.h" #include "chrome/browser/intents/api_key.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/webdata/web_data_service.h" @@ -40,17 +38,6 @@ const char kMaxSuggestions[] = "15"; const char kCWSIntentServiceURL[] = "https://www.googleapis.com/chromewebstore/v1.1b/items/intent"; -// Determines if a string is a candidate for localization. -bool ShouldLocalize(const std::string& value) { - std::string::size_type index = 0; - index = value.find(extensions::MessageBundle::kMessageBegin); - if (index == std::string::npos) - return false; - - index = value.find(extensions::MessageBundle::kMessageEnd, index); - return (index != std::string::npos); -} - // Parses a JSON |response| from the CWS into a list of suggested extensions, // stored in |intents|. |intents| must not be NULL. void ParseResponse(const std::string& response, @@ -105,38 +92,6 @@ void ParseResponse(const std::string& response, continue; info.icon_url = GURL(url_string); - // Need to parse CWS reply, since it is not pre-l10n'd. - ListValue* all_locales = NULL; - if (ShouldLocalize(UTF16ToUTF8(info.name)) && - item->GetList("locale_data", &all_locales)) { - std::map<std::string, std::string> localized_title; - - for (ListValue::const_iterator locale_iter(all_locales->begin()); - locale_iter != all_locales->end(); ++locale_iter) { - DictionaryValue* locale = static_cast<DictionaryValue*>(*locale_iter); - - std::string locale_id, title; - if (!locale->GetString("locale_string", &locale_id) || - !locale->GetString("title", &title)) - continue; - - localized_title[locale_id] = title; - } - - std::vector<std::string> valid_locales; - extension_l10n_util::GetAllFallbackLocales( - extension_l10n_util::CurrentLocaleOrDefault(), - "all", - &valid_locales); - for (std::vector<std::string>::iterator iter = valid_locales.begin(); - iter != valid_locales.end(); ++iter) { - if (localized_title.count(*iter)) { - info.name = UTF8ToUTF16(localized_title[*iter]); - break; - } - } - } - intents->push_back(info); } } diff --git a/chrome/browser/intents/cws_intents_registry.h b/chrome/browser/intents/cws_intents_registry.h index 16e1b27..e5f9cec 100644 --- a/chrome/browser/intents/cws_intents_registry.h +++ b/chrome/browser/intents/cws_intents_registry.h @@ -17,8 +17,6 @@ namespace net { class URLRequestContextGetter; } -class CWSIntentsRegistryForTest; - // Handles storing and retrieving of web intents in the web database. // The registry provides filtering logic to retrieve specific types of intents. class CWSIntentsRegistry : public ProfileKeyedService, @@ -58,7 +56,8 @@ class CWSIntentsRegistry : public ProfileKeyedService, // Make sure that only CWSIntentsRegistryFactory can create an instance of // CWSIntentsRegistry. friend class CWSIntentsRegistryFactory; - friend class ::CWSIntentsRegistryForTest; + FRIEND_TEST_ALL_PREFIXES(CWSIntentsRegistryTest, ValidQuery); + FRIEND_TEST_ALL_PREFIXES(CWSIntentsRegistryTest, InvalidQuery); struct IntentsQuery; diff --git a/chrome/browser/intents/cws_intents_registry_unittest.cc b/chrome/browser/intents/cws_intents_registry_unittest.cc index ab1d1ea..920f2ab 100644 --- a/chrome/browser/intents/cws_intents_registry_unittest.cc +++ b/chrome/browser/intents/cws_intents_registry_unittest.cc @@ -8,29 +8,10 @@ #include "base/bind_helpers.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" -#include "chrome/common/extensions/extension_l10n_util.h" #include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -// Create a CWSIntentsRegistry proxy for testing purposes. -// Needs to be non-anonymous so it can be friended. -class CWSIntentsRegistryForTest { -public: - CWSIntentsRegistryForTest() : registry_(NULL) {} - ~CWSIntentsRegistryForTest() { delete registry_; } - - void reset(net::URLRequestContextGetter* context) { - delete registry_; - registry_ = new CWSIntentsRegistry(context); - } - - CWSIntentsRegistry* operator->() { return registry_; } - -private: - CWSIntentsRegistry* registry_; -}; - namespace { const char kCWSResponseInvalid[] = @@ -73,66 +54,10 @@ const char kCWSResponseValid[] = " \"family_safe\":true," " \"icon_url\":\"http://qa-lighthouse.sandbox.google.com/image/" "QzPnRCYCBbBGI99ZkGxkp-NNJ488IkkiTyCgynFEeDTJHcw4tHl3csmjTQ\"}]}"; - -const char kCWSResponseValidL10n[] = - "{\"kind\":\"chromewebstore#itemList\"," - " \"total_items\":1," - " \"start_index\":0," - " \"items\":[ " - " {\"kind\":\"chromewebstore#item\"," - " \"id\":\"nhkckhebbbncbkefhcpcgepcgfaclehe\"," - " \"type\":\"APPLICATION\"," - " \"num_ratings\":0," - " \"average_rating\":0.0," - " \"manifest\":\"{\\n\\\"update_url\\\":\\" - "\"http://0.tbhome_staging.dserver.download-qa.td.borg.google.com/" - "service/update2/crx\\\",\\n \\\"name\\\": \\\"__MSG_name__\\\"" - ",\\n \\\"description\\\": \\\"Do stuff\\\",\\n \\\"version\\\": " - "\\\"1.2.19\\\",\\n \\\"app\\\": {\\n \\\"urls\\\": [ \\n ]," - "\\n \\\"launch\\\": {\\n \\\"web_url\\\": \\" - "\"http://siddharthasaha.net/\\\"\\n }\\n },\\n \\\"icons\\\": " - "{\\n \\\"128\\\": \\\"icon128.png\\\"\\n },\\n \\\"permissions\\\":" - " [\\n \\\"unlimitedStorage\\\",\\n \\\"notifications\\\"\\n ],\\n" - " \\\"intents\\\": {\\n \\\"http://webintents.org/edit\\\" : {\\n " - "\\\"type\\\" : [\\\"image/png\\\", \\\"image/jpg\\\"],\\n \\\"path\\" - "\" : \\\"//services/edit\\\",\\n \\\"title\\\" : " - "\\\"Sample Editing Intent\\\",\\n \\\"disposition\\\" : \\\"inline\\" - "\"\\n },\\n \\\"http://webintents.org/share\\\" : " - "{\\n \\\"type\\\" : [\\\"text/plain\\\", \\\"image/jpg\\\"]," - "\\n \\\"path\\\" : \\\"//services/share\\\",\\n \\\"title\\\" : " - "\\\"Sample sharing Intent\\\",\\n \\\"disposition\\\" : " - "\\\"inline\\\"\\n }\\n }\\n}\\n\"," - " \"family_safe\":true," - " \"icon_url\":\"http://qa-lighthouse.sandbox.google.com/image/" - "QzPnRCYCBbBGI99ZkGxkp-NNJ488IkkiTyCgynFEeDTJHcw4tHl3csmjTQ\"," - "\"locale_data\": ["; - -const char kCWSResponseValidL10nPostfix[] = -"]}]}"; - -const char kLocaleDataEn[] = - "{" - " \"locale_string\": \"en\"," - " \"title\": \"Localized EN\"" - "}"; - -const char kLocaleDataDe[] = - "{" - " \"locale_string\": \"de\"," - " \"title\": \"Localized DE\"" - "}"; - -const char kLocaleDataAll[] = - "{" - " \"locale_string\": \"all\"," - " \"title\": \"Localized ALL\"" - "}"; - -const char kValidIconURL[] = +const char kValidIconURL[]= "http://qa-lighthouse.sandbox.google.com/image/" "QzPnRCYCBbBGI99ZkGxkp-NNJ488IkkiTyCgynFEeDTJHcw4tHl3csmjTQ"; - -const char kValidManifest[] = +const char kValidManifest[]= "{\n\"update_url\":\"http://0.tbhome_staging.dserver.download-qa.td.borg." "google.com/service/update2/crx\",\n \"name\": \"Sidd's Intent App\",\n" " \"description\": \"Do stuff\",\n \"version\": \"1.2.19\",\n \"app\":" @@ -148,22 +73,9 @@ const char kValidManifest[] = "\"//services/share\",\n \"title\" : \"Sample sharing Intent\",\n" " \"disposition\" : \"inline\"\n }\n }\n}\n"; -const char kEditAction[] = "http://webintents.org/edit"; -const char kImagePngType[] = "image/png"; - -class ScopedLocale { - public: - ScopedLocale() : locale_(extension_l10n_util::CurrentLocaleOrDefault()) {} - ~ScopedLocale() { extension_l10n_util::SetProcessLocale(locale_); } - std::string locale_; -}; - class CWSIntentsRegistryTest : public testing::Test { public: - virtual void SetUp() { - scoped_refptr<TestURLRequestContextGetter> context_getter_( - new TestURLRequestContextGetter(ui_loop_.message_loop_proxy())); - registry_.reset(context_getter_); + CWSIntentsRegistryTest() : test_factory_(NULL) { } virtual void TearDown() { @@ -180,34 +92,35 @@ class CWSIntentsRegistryTest : public testing::Test { extensions_ = extensions; } - void RunRequest(const std::string& action, const std::string& mime, + void SetFakeResponse(const std::string& action, const std::string& mime, const std::string& response) { - extensions_.clear(); - - net::FakeURLFetcherFactory test_factory; - test_factory.SetFakeResponse( + test_factory_.SetFakeResponse( CWSIntentsRegistry::BuildQueryURL( ASCIIToUTF16(action),ASCIIToUTF16(mime)).spec(), response, true); - - registry_->GetIntentServices(ASCIIToUTF16(action), - ASCIIToUTF16(mime), - base::Bind(&CWSIntentsRegistryTest::Callback, - base::Unretained(this))); - WaitForResults(); } + CWSIntentsRegistry::IntentExtensionList extensions_; + net::FakeURLFetcherFactory test_factory_; protected: - CWSIntentsRegistryForTest registry_; - CWSIntentsRegistry::IntentExtensionList extensions_; MessageLoop ui_loop_; }; } // namespace TEST_F(CWSIntentsRegistryTest, ValidQuery) { - RunRequest(kEditAction, kImagePngType,kCWSResponseValid); + const scoped_refptr<TestURLRequestContextGetter> context_getter( + new TestURLRequestContextGetter(ui_loop_.message_loop_proxy())); + SetFakeResponse("http://webintents.org/edit", "*/png", kCWSResponseValid); + + CWSIntentsRegistry registry(context_getter); + registry.GetIntentServices(ASCIIToUTF16("http://webintents.org/edit"), + ASCIIToUTF16("*/png"), + base::Bind(&CWSIntentsRegistryTest::Callback, + base::Unretained(this))); + + WaitForResults(); ASSERT_EQ(1UL, extensions_.size()); EXPECT_EQ(0, extensions_[0].num_ratings); @@ -221,7 +134,17 @@ TEST_F(CWSIntentsRegistryTest, ValidQuery) { } TEST_F(CWSIntentsRegistryTest, InvalidQuery) { - RunRequest("foo", "foo",kCWSResponseInvalid); + const scoped_refptr<TestURLRequestContextGetter> context_getter( + new TestURLRequestContextGetter(ui_loop_.message_loop_proxy())); + SetFakeResponse("foo", "foo", kCWSResponseInvalid); + + CWSIntentsRegistry registry(context_getter); + registry.GetIntentServices(ASCIIToUTF16("foo"), + ASCIIToUTF16("foo"), + base::Bind(&CWSIntentsRegistryTest::Callback, + base::Unretained(this))); + + WaitForResults(); EXPECT_EQ(0UL, extensions_.size()); } @@ -234,48 +157,3 @@ TEST_F(CWSIntentsRegistryTest, BuildQueryURL) { EXPECT_EQ(kExpectedURL, url.spec().substr(0, kExpectedURL.size())); } - -// Test for match to the application locale - i.e. if running in "en", -// registry will use locale_data for "en" key, with or without "all" -// locale_data present. -TEST_F(CWSIntentsRegistryTest, LocalizeMatchingLocale) { - ScopedLocale restoreLocaleOnExit; - - std::string response = kCWSResponseValidL10n; - response += kLocaleDataEn + std::string(","); - response += kLocaleDataAll + std::string(","); - response += kLocaleDataDe; - response += kCWSResponseValidL10nPostfix; - - // Picks the proper locale_data based on application locale. - extension_l10n_util::SetProcessLocale("en"); - RunRequest(kEditAction, kImagePngType, response); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("Localized EN"), - UTF16ToUTF8(extensions_[0].name)); - - extension_l10n_util::SetProcessLocale("de"); - RunRequest(kEditAction, kImagePngType, response); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("Localized DE"), - UTF16ToUTF8(extensions_[0].name)); - - // Falls back to locale_data for "All" if unknown application locale. - extension_l10n_util::SetProcessLocale("fr"); - RunRequest(kEditAction, kImagePngType, std::string(kCWSResponseValidL10n) + - kLocaleDataAll + kCWSResponseValidL10nPostfix); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("Localized ALL"), - UTF16ToUTF8(extensions_[0].name)); - - // Keeps original content if unknown application locale and no "all" - // localization data exists. - response = kCWSResponseValidL10n; - response += kLocaleDataEn; - response += kCWSResponseValidL10nPostfix; - extension_l10n_util::SetProcessLocale("de"); - RunRequest(kEditAction, kImagePngType, response); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("__MSG_name__"), - UTF16ToUTF8(extensions_[0].name)); -} |