| 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" | |
| 15 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "chrome/common/extensions/extension_l10n_util.h" | 16 #include "chrome/common/extensions/extension_l10n_util.h" |
| 19 #include "chrome/common/extensions/extension_message_bundle.h" | 17 #include "chrome/common/extensions/extension_message_bundle.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "webkit/glue/resource_type.h" | 19 #include "webkit/glue/resource_type.h" |
| 22 | 20 |
| 23 namespace errors = extension_manifest_errors; | 21 namespace errors = extension_manifest_errors; |
| 24 namespace keys = extension_manifest_keys; | 22 namespace keys = extension_manifest_keys; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestDifferentCurrentLocale) { | 373 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestDifferentCurrentLocale) { |
| 376 DictionaryValue manifest; | 374 DictionaryValue manifest; |
| 377 manifest.SetString(keys::kDefaultLocale, "en_US"); | 375 manifest.SetString(keys::kDefaultLocale, "en_US"); |
| 378 manifest.SetString(keys::kCurrentLocale, "sr"); | 376 manifest.SetString(keys::kCurrentLocale, "sr"); |
| 379 | 377 |
| 380 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); | 378 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); |
| 381 | 379 |
| 382 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); | 380 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); |
| 383 } | 381 } |
| 384 | 382 |
| 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 resource_handler_.reset(new DummyResourceHandler()); | |
| 421 request_info_.reset(CreateNewResourceRequestInfo()); | |
| 422 } | |
| 423 | |
| 424 ResourceDispatcherHostRequestInfo* CreateNewResourceRequestInfo() { | |
| 425 return new ResourceDispatcherHostRequestInfo( | |
| 426 resource_handler_.get(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0, | |
| 427 "not important", "not important", | |
| 428 ResourceType::STYLESHEET, 0U, false, false, -1, -1); | |
| 429 } | |
| 430 | |
| 431 scoped_ptr<GURL> url_; | |
| 432 ResourceType::Type resource_type_; | |
| 433 scoped_ptr<DummyResourceHandler> resource_handler_; | |
| 434 scoped_ptr<ResourceDispatcherHostRequestInfo> request_info_; | |
| 435 }; | |
| 436 | |
| 437 TEST_F(ApplyMessageFilterPolicyTest, WrongScheme) { | |
| 438 url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); | |
| 439 extension_l10n_util::ApplyMessageFilterPolicy( | |
| 440 *url_, resource_type_, request_info_.get()); | |
| 441 | |
| 442 EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); | |
| 443 } | |
| 444 | |
| 445 TEST_F(ApplyMessageFilterPolicyTest, GoodScheme) { | |
| 446 extension_l10n_util::ApplyMessageFilterPolicy( | |
| 447 *url_, resource_type_, request_info_.get()); | |
| 448 | |
| 449 EXPECT_EQ(FilterPolicy::FILTER_EXTENSION_MESSAGES, | |
| 450 request_info_->filter_policy()); | |
| 451 } | |
| 452 | |
| 453 TEST_F(ApplyMessageFilterPolicyTest, GoodSchemeWithSecurityFilter) { | |
| 454 request_info_->set_filter_policy(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES); | |
| 455 extension_l10n_util::ApplyMessageFilterPolicy( | |
| 456 *url_, resource_type_, request_info_.get()); | |
| 457 | |
| 458 EXPECT_EQ(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES, | |
| 459 request_info_->filter_policy()); | |
| 460 } | |
| 461 | |
| 462 TEST_F(ApplyMessageFilterPolicyTest, GoodSchemeWrongResourceType) { | |
| 463 resource_type_ = ResourceType::MAIN_FRAME; | |
| 464 extension_l10n_util::ApplyMessageFilterPolicy( | |
| 465 *url_, resource_type_, request_info_.get()); | |
| 466 | |
| 467 EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); | |
| 468 } | |
| 469 | |
| 470 TEST_F(ApplyMessageFilterPolicyTest, WrongSchemeResourceAndFilter) { | |
| 471 url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); | |
| 472 resource_type_ = ResourceType::MEDIA; | |
| 473 request_info_->set_filter_policy(FilterPolicy::FILTER_ALL); | |
| 474 extension_l10n_util::ApplyMessageFilterPolicy( | |
| 475 *url_, resource_type_, request_info_.get()); | |
| 476 | |
| 477 EXPECT_EQ(FilterPolicy::FILTER_ALL, request_info_->filter_policy()); | |
| 478 } | |
| 479 | |
| 480 } // namespace | 383 } // namespace |
| OLD | NEW |