| OLD | NEW |
| 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/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 int64_t off_the_record_tx_bytes() const { return off_the_record_tx_bytes_; } | 116 int64_t off_the_record_tx_bytes() const { return off_the_record_tx_bytes_; } |
| 117 int64_t off_the_record_rx_bytes() const { return off_the_record_rx_bytes_; } | 117 int64_t off_the_record_rx_bytes() const { return off_the_record_rx_bytes_; } |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 int64_t on_the_record_tx_bytes_; | 120 int64_t on_the_record_tx_bytes_; |
| 121 int64_t on_the_record_rx_bytes_; | 121 int64_t on_the_record_rx_bytes_; |
| 122 int64_t off_the_record_tx_bytes_; | 122 int64_t off_the_record_tx_bytes_; |
| 123 int64_t off_the_record_rx_bytes_; | 123 int64_t off_the_record_rx_bytes_; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 // Helper function to make the IsAccessAllowed test concise. |
| 127 bool IsAccessAllowed(const std::string& path, |
| 128 const std::string& profile_path) { |
| 129 return ChromeNetworkDelegate::IsAccessAllowed( |
| 130 base::FilePath::FromUTF8Unsafe(path), |
| 131 base::FilePath::FromUTF8Unsafe(profile_path)); |
| 132 } |
| 133 |
| 126 } // namespace | 134 } // namespace |
| 127 | 135 |
| 128 class ChromeNetworkDelegateTest : public testing::Test { | 136 class ChromeNetworkDelegateTest : public testing::Test { |
| 129 public: | 137 public: |
| 130 ChromeNetworkDelegateTest() | 138 ChromeNetworkDelegateTest() |
| 131 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 139 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 132 context_(new net::TestURLRequestContext(true)) { | 140 context_(new net::TestURLRequestContext(true)) { |
| 133 #if BUILDFLAG(ENABLE_EXTENSIONS) | 141 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 134 forwarder_ = new extensions::EventRouterForwarder(); | 142 forwarder_ = new extensions::EventRouterForwarder(); |
| 135 #endif | 143 #endif |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 529 |
| 522 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 530 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 523 kBlockedFirstPartySite)); | 531 kBlockedFirstPartySite)); |
| 524 | 532 |
| 525 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, | 533 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, |
| 526 CONTENT_SETTING_BLOCK); | 534 CONTENT_SETTING_BLOCK); |
| 527 // Privacy mode is disabled as kAllowedSite is still getting cookies | 535 // Privacy mode is disabled as kAllowedSite is still getting cookies |
| 528 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, | 536 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, |
| 529 kBlockedFirstPartySite)); | 537 kBlockedFirstPartySite)); |
| 530 } | 538 } |
| 539 |
| 540 TEST(ChromeNetworkDelegateStaticTest, IsAccessAllowed) { |
| 541 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 542 // Platforms other than Chrome OS and Android have access to any files. |
| 543 EXPECT_TRUE(IsAccessAllowed("/", "")); |
| 544 EXPECT_TRUE(IsAccessAllowed("/foo.txt", "")); |
| 545 #endif |
| 546 |
| 547 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 548 // Chrome OS and Android don't have access to random files. |
| 549 EXPECT_FALSE(IsAccessAllowed("/", "")); |
| 550 EXPECT_FALSE(IsAccessAllowed("/foo.txt", "")); |
| 551 #endif |
| 552 |
| 553 #if defined(OS_CHROMEOS) |
| 554 // Chrome OS allows the following directories. |
| 555 EXPECT_TRUE(IsAccessAllowed("/home/chronos/user/Downloads", "")); |
| 556 EXPECT_TRUE(IsAccessAllowed("/home/chronos/user/log", "")); |
| 557 EXPECT_TRUE(IsAccessAllowed("/home/chronos/user/WebRTC Logs", "")); |
| 558 EXPECT_TRUE(IsAccessAllowed("/media", "")); |
| 559 EXPECT_TRUE(IsAccessAllowed("/opt/oem", "")); |
| 560 EXPECT_TRUE(IsAccessAllowed("/usr/share/chromeos-assets", "")); |
| 561 EXPECT_TRUE(IsAccessAllowed("/tmp", "")); |
| 562 EXPECT_TRUE(IsAccessAllowed("/var/log", "")); |
| 563 // Files under the directories are allowed. |
| 564 EXPECT_TRUE(IsAccessAllowed("/tmp/foo.txt", "")); |
| 565 // Make sure similar paths are not allowed. |
| 566 EXPECT_FALSE(IsAccessAllowed("/home/chronos/user/log.txt", "")); |
| 567 EXPECT_FALSE(IsAccessAllowed("/home/chronos/user", "")); |
| 568 EXPECT_FALSE(IsAccessAllowed("/home/chronos", "")); |
| 569 |
| 570 // If profile path is given, the following additional paths are allowed. |
| 571 EXPECT_TRUE(IsAccessAllowed("/profile/Downloads", "/profile")); |
| 572 EXPECT_TRUE(IsAccessAllowed("/profile/WebRTC Logs", "/profile")); |
| 573 |
| 574 #elif defined(OS_ANDROID) |
| 575 // Android allows the following directories. |
| 576 EXPECT_TRUE(IsAccessAllowed("/sdcard", "")); |
| 577 EXPECT_TRUE(IsAccessAllowed("/mnt/sdcard", "")); |
| 578 // Files under the directories are allowed. |
| 579 EXPECT_TRUE(IsAccessAllowed("/sdcard/foo.txt", "")); |
| 580 // Make sure similar paths are not allowed. |
| 581 EXPECT_FALSE(IsAccessAllowed("/mnt/sdcard.txt", "")); |
| 582 EXPECT_FALSE(IsAccessAllowed("/mnt", "")); |
| 583 |
| 584 // Files in external storage are allowed. |
| 585 base::FilePath external_storage_path; |
| 586 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); |
| 587 EXPECT_TRUE(IsAccessAllowed( |
| 588 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), "")); |
| 589 // The external storage root itself is not allowed. |
| 590 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), "")); |
| 591 #endif |
| 592 } |
| OLD | NEW |