OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/linked_ptr.h" | 8 #include "base/linked_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 14 #include "chrome/browser/renderer_host/resource_handler.h" |
13 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
15 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
16 #include "chrome/common/extensions/extension_l10n_util.h" | 18 #include "chrome/common/extensions/extension_l10n_util.h" |
17 #include "chrome/common/extensions/extension_message_bundle.h" | 19 #include "chrome/common/extensions/extension_message_bundle.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "webkit/glue/resource_type.h" |
19 | 22 |
20 namespace errors = extension_manifest_errors; | 23 namespace errors = extension_manifest_errors; |
21 namespace keys = extension_manifest_keys; | 24 namespace keys = extension_manifest_keys; |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
25 TEST(ExtensionL10nUtil, GetValidLocalesEmptyLocaleFolder) { | 28 TEST(ExtensionL10nUtil, GetValidLocalesEmptyLocaleFolder) { |
26 ScopedTempDir temp; | 29 ScopedTempDir temp; |
27 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 30 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
28 | 31 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestDifferentCurrentLocale) { | 375 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestDifferentCurrentLocale) { |
373 DictionaryValue manifest; | 376 DictionaryValue manifest; |
374 manifest.SetString(keys::kDefaultLocale, "en_US"); | 377 manifest.SetString(keys::kDefaultLocale, "en_US"); |
375 manifest.SetString(keys::kCurrentLocale, "sr"); | 378 manifest.SetString(keys::kCurrentLocale, "sr"); |
376 | 379 |
377 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); | 380 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); |
378 | 381 |
379 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); | 382 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); |
380 } | 383 } |
381 | 384 |
| 385 class DummyResourceHandler : public ResourceHandler { |
| 386 public: |
| 387 DummyResourceHandler() {} |
| 388 |
| 389 bool OnRequestRedirected(int request_id, const GURL& url, |
| 390 ResourceResponse* response, bool* defer) { |
| 391 return true; |
| 392 } |
| 393 |
| 394 bool OnResponseStarted(int request_id, ResourceResponse* response) { |
| 395 return true; |
| 396 } |
| 397 |
| 398 bool OnWillRead( |
| 399 int request_id, net::IOBuffer** buf, int* buf_size, int min_size) { |
| 400 return true; |
| 401 } |
| 402 |
| 403 bool OnReadCompleted(int request_id, int* bytes_read) { return true; } |
| 404 |
| 405 bool OnResponseCompleted( |
| 406 int request_id, const URLRequestStatus& status, const std::string& info) { |
| 407 return true; |
| 408 } |
| 409 |
| 410 private: |
| 411 DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); |
| 412 }; |
| 413 |
| 414 class ApplyMessageFilterPolicyTest : public testing::Test { |
| 415 protected: |
| 416 void SetUp() { |
| 417 url_.reset(new GURL( |
| 418 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); |
| 419 resource_type_ = ResourceType::STYLESHEET; |
| 420 request_info_.reset(CreateNewResourceRequestInfo()); |
| 421 } |
| 422 |
| 423 ResourceDispatcherHostRequestInfo* CreateNewResourceRequestInfo() { |
| 424 return new ResourceDispatcherHostRequestInfo( |
| 425 new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0, |
| 426 "not important", "not important", |
| 427 ResourceType::STYLESHEET, 0U, false, false, -1, -1); |
| 428 } |
| 429 |
| 430 scoped_ptr<GURL> url_; |
| 431 ResourceType::Type resource_type_; |
| 432 scoped_ptr<ResourceDispatcherHostRequestInfo> request_info_; |
| 433 }; |
| 434 |
| 435 TEST_F(ApplyMessageFilterPolicyTest, WrongScheme) { |
| 436 url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); |
| 437 extension_l10n_util::ApplyMessageFilterPolicy( |
| 438 *url_, resource_type_, request_info_.get()); |
| 439 |
| 440 EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); |
| 441 } |
| 442 |
| 443 TEST_F(ApplyMessageFilterPolicyTest, GoodScheme) { |
| 444 extension_l10n_util::ApplyMessageFilterPolicy( |
| 445 *url_, resource_type_, request_info_.get()); |
| 446 |
| 447 EXPECT_EQ(FilterPolicy::FILTER_EXTENSION_MESSAGES, |
| 448 request_info_->filter_policy()); |
| 449 } |
| 450 |
| 451 TEST_F(ApplyMessageFilterPolicyTest, GoodSchemeWithSecurityFilter) { |
| 452 request_info_->set_filter_policy(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES); |
| 453 extension_l10n_util::ApplyMessageFilterPolicy( |
| 454 *url_, resource_type_, request_info_.get()); |
| 455 |
| 456 EXPECT_EQ(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES, |
| 457 request_info_->filter_policy()); |
| 458 } |
| 459 |
| 460 TEST_F(ApplyMessageFilterPolicyTest, GoodSchemeWrongResourceType) { |
| 461 resource_type_ = ResourceType::MAIN_FRAME; |
| 462 extension_l10n_util::ApplyMessageFilterPolicy( |
| 463 *url_, resource_type_, request_info_.get()); |
| 464 |
| 465 EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); |
| 466 } |
| 467 |
| 468 TEST_F(ApplyMessageFilterPolicyTest, WrongSchemeResourceAndFilter) { |
| 469 url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); |
| 470 resource_type_ = ResourceType::MEDIA; |
| 471 request_info_->set_filter_policy(FilterPolicy::FILTER_ALL); |
| 472 extension_l10n_util::ApplyMessageFilterPolicy( |
| 473 *url_, resource_type_, request_info_.get()); |
| 474 |
| 475 EXPECT_EQ(FilterPolicy::FILTER_ALL, request_info_->filter_policy()); |
| 476 } |
| 477 |
382 } // namespace | 478 } // namespace |
OLD | NEW |