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

Side by Side Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

Issue 2657903005: Factor out core logic from OnCanAccessFile() and add tests for it (Closed)
Patch Set: android build Created 3 years, 11 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
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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 return;
eroman 2017/01/27 01:21:49 Is this return needed? (it looks like there won't
satorux1 2017/01/27 06:23:35 good point. removed!
546 #endif
547
548 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
549 // Chrome OS and Android don't have access to random files.
550 EXPECT_FALSE(IsAccessAllowed("/", ""));
551 EXPECT_FALSE(IsAccessAllowed("/foo.txt", ""));
552 #endif
553
554 #if defined(OS_CHROMEOS)
555 // Chrome OS allows the following directories.
556 EXPECT_TRUE(IsAccessAllowed("/home/chronos/user/Downloads", ""));
557 EXPECT_TRUE(IsAccessAllowed("/home/chronos/user/log", ""));
558 EXPECT_TRUE(IsAccessAllowed("/home/chronos/user/WebRTC Logs", ""));
559 EXPECT_TRUE(IsAccessAllowed("/media", ""));
560 EXPECT_TRUE(IsAccessAllowed("/opt/oem", ""));
561 EXPECT_TRUE(IsAccessAllowed("/usr/share/chromeos-assets", ""));
562 EXPECT_TRUE(IsAccessAllowed("/tmp", ""));
563 EXPECT_TRUE(IsAccessAllowed("/var/log", ""));
564 // Files under the directories are allowed.
565 EXPECT_TRUE(IsAccessAllowed("/tmp/foo.txt", ""));
566 // Make sure similar paths are not allowed.
567 EXPECT_FALSE(IsAccessAllowed("/home/chronos/user/log.txt", ""));
568 EXPECT_FALSE(IsAccessAllowed("/home/chronos/user", ""));
569 EXPECT_FALSE(IsAccessAllowed("/home/chronos", ""));
570
571 // If profile path is given, the following additional paths are allowed.
572 EXPECT_TRUE(IsAccessAllowed("/profile/Downloads", "/profile"));
573 EXPECT_TRUE(IsAccessAllowed("/profile/WebRTC Logs", "/profile"));
574
575 #elif defined(OS_ANDROID)
576 // Android allows the following directories.
577 EXPECT_TRUE(IsAccessAllowed("/sdcard", ""));
578 EXPECT_TRUE(IsAccessAllowed("/mnt/sdcard", ""));
579 // Files under the directories are allowed.
580 EXPECT_TRUE(IsAccessAllowed("/sdcard/foo.txt", ""));
581 // Make sure similar paths are not allowed.
582 EXPECT_FALSE(IsAccessAllowed("/mnt/sdcard.txt", ""));
583 EXPECT_FALSE(IsAccessAllowed("/mnt", ""));
584
585 // Files in external storage are allowed.
586 base::FilePath external_storage_path;
587 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
588 EXPECT_TRUE(IsAccessAllowed(
589 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), ""));
590 // The external storage root itself is not allowed.
591 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), ""));
592 #endif
593 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698