Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1605)

Side by Side Diff: chrome/browser/intents/cws_intents_registry_unittest.cc

Issue 10837130: Set locale for extension tests, keep it from affecting global state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/intents/cws_intents_registry.h" 5 #include "chrome/browser/intents/cws_intents_registry.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 "\"image/png\", \"image/jpg\"],\n \"path\" : \"//services/edit\",\n" 144 "\"image/png\", \"image/jpg\"],\n \"path\" : \"//services/edit\",\n"
145 " \"title\" : \"Sample Editing Intent\",\n \"disposition\" : " 145 " \"title\" : \"Sample Editing Intent\",\n \"disposition\" : "
146 "\"inline\"\n },\n \"http://webintents.org/share\" : {\n " 146 "\"inline\"\n },\n \"http://webintents.org/share\" : {\n "
147 "\"type\" : [\"text/plain\", \"image/jpg\"],\n \"path\" : " 147 "\"type\" : [\"text/plain\", \"image/jpg\"],\n \"path\" : "
148 "\"//services/share\",\n \"title\" : \"Sample sharing Intent\",\n" 148 "\"//services/share\",\n \"title\" : \"Sample sharing Intent\",\n"
149 " \"disposition\" : \"inline\"\n }\n }\n}\n"; 149 " \"disposition\" : \"inline\"\n }\n }\n}\n";
150 150
151 const char kEditAction[] = "http://webintents.org/edit"; 151 const char kEditAction[] = "http://webintents.org/edit";
152 const char kImagePngType[] = "image/png"; 152 const char kImagePngType[] = "image/png";
153 153
154 class ScopedLocale {
155 public:
156 ScopedLocale() : locale_(extension_l10n_util::CurrentLocaleOrDefault()) {}
157 ~ScopedLocale() { extension_l10n_util::SetProcessLocale(locale_); }
158 std::string locale_;
159 };
160
161 class CWSIntentsRegistryTest : public testing::Test { 154 class CWSIntentsRegistryTest : public testing::Test {
162 public: 155 public:
163 virtual void SetUp() { 156 virtual void SetUp() {
164 scoped_refptr<TestURLRequestContextGetter> context_getter( 157 scoped_refptr<TestURLRequestContextGetter> context_getter(
165 new TestURLRequestContextGetter(ui_loop_.message_loop_proxy())); 158 new TestURLRequestContextGetter(ui_loop_.message_loop_proxy()));
166 registry_.reset(context_getter); 159 registry_.reset(context_getter);
167 } 160 }
168 161
169 virtual void TearDown() { 162 virtual void TearDown() {
170 // Pump messages posted by the main thread. 163 // Pump messages posted by the main thread.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 GURL url = CWSIntentsRegistry::BuildQueryURL(ASCIIToUTF16("action"), 227 GURL url = CWSIntentsRegistry::BuildQueryURL(ASCIIToUTF16("action"),
235 ASCIIToUTF16("mime/type")); 228 ASCIIToUTF16("mime/type"));
236 229
237 EXPECT_EQ(kExpectedURL, url.spec().substr(0, kExpectedURL.size())); 230 EXPECT_EQ(kExpectedURL, url.spec().substr(0, kExpectedURL.size()));
238 } 231 }
239 232
240 // Test for match to the application locale - i.e. if running in "en", 233 // Test for match to the application locale - i.e. if running in "en",
241 // registry will use locale_data for "en" key, with or without "all" 234 // registry will use locale_data for "en" key, with or without "all"
242 // locale_data present. 235 // locale_data present.
243 TEST_F(CWSIntentsRegistryTest, LocalizeMatchingLocale) { 236 TEST_F(CWSIntentsRegistryTest, LocalizeMatchingLocale) {
244 ScopedLocale restoreLocaleOnExit; 237 extension_l10n_util::ScopedLocaleForTest restoreLocaleOnExit;
245 238
246 std::string response = kCWSResponseValidL10n; 239 std::string response = kCWSResponseValidL10n;
247 response += kLocaleDataEn + std::string(","); 240 response += kLocaleDataEn + std::string(",");
248 response += kLocaleDataAll + std::string(","); 241 response += kLocaleDataAll + std::string(",");
249 response += kLocaleDataDe; 242 response += kLocaleDataDe;
250 response += kCWSResponseValidL10nPostfix; 243 response += kCWSResponseValidL10nPostfix;
251 244
252 // Picks the proper locale_data based on application locale. 245 // Picks the proper locale_data based on application locale.
253 extension_l10n_util::SetProcessLocale("en"); 246 extension_l10n_util::SetProcessLocale("en");
254 RunRequest(kEditAction, kImagePngType, response); 247 RunRequest(kEditAction, kImagePngType, response);
(...skipping 19 matching lines...) Expand all
274 // localization data exists. 267 // localization data exists.
275 response = kCWSResponseValidL10n; 268 response = kCWSResponseValidL10n;
276 response += kLocaleDataEn; 269 response += kLocaleDataEn;
277 response += kCWSResponseValidL10nPostfix; 270 response += kCWSResponseValidL10nPostfix;
278 extension_l10n_util::SetProcessLocale("de"); 271 extension_l10n_util::SetProcessLocale("de");
279 RunRequest(kEditAction, kImagePngType, response); 272 RunRequest(kEditAction, kImagePngType, response);
280 ASSERT_EQ(1UL, extensions_.size()); 273 ASSERT_EQ(1UL, extensions_.size());
281 EXPECT_EQ(std::string("__MSG_name__"), 274 EXPECT_EQ(std::string("__MSG_name__"),
282 UTF16ToUTF8(extensions_[0].name)); 275 UTF16ToUTF8(extensions_[0].name));
283 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.cc ('k') | chrome/common/extensions/extension_l10n_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698