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

Side by Side Diff: chrome/browser/chromeos/base/file_flusher_unittest.cc

Issue 2318023002: //chrome/browser/chromeos: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Address comment and also remove non-trivial cases Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/chromeos/base/file_flusher.h" 5 #include "chrome/browser/chromeos/base/file_flusher.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 void SetUp() override { 44 void SetUp() override {
45 // Create test files under a temp dir. 45 // Create test files under a temp dir.
46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
47 47
48 const size_t kNumDirs = 2; 48 const size_t kNumDirs = 2;
49 const size_t kNumFiles = 3; 49 const size_t kNumFiles = 3;
50 for (size_t i = 1; i <= kNumDirs; ++i) { 50 for (size_t i = 1; i <= kNumDirs; ++i) {
51 for (size_t j = 1; j <= kNumFiles; ++j) { 51 for (size_t j = 1; j <= kNumFiles; ++j) {
52 const std::string path = base::StringPrintf("dir%zu/file%zu", i, j); 52 const std::string path = base::StringPrintf("dir%zu/file%zu", i, j);
53 const std::string content = base::StringPrintf("content %zu %zu", i, j); 53 const std::string content = base::StringPrintf("content %zu %zu", i, j);
54 WriteStringToFile(temp_dir_.path().AppendASCII(path), content); 54 WriteStringToFile(temp_dir_.GetPath().AppendASCII(path), content);
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 void TearDown() override { 59 void TearDown() override {
60 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 60 content::BrowserThread::GetBlockingPool()->FlushForTesting();
61 base::RunLoop().RunUntilIdle(); 61 base::RunLoop().RunUntilIdle();
62 } 62 }
63 63
64 std::unique_ptr<FileFlusher> CreateFileFlusher() { 64 std::unique_ptr<FileFlusher> CreateFileFlusher() {
65 std::unique_ptr<FileFlusher> flusher(new FileFlusher); 65 std::unique_ptr<FileFlusher> flusher(new FileFlusher);
66 flusher->set_on_flush_callback_for_test( 66 flusher->set_on_flush_callback_for_test(
67 base::Bind(&FileFlusherTest::OnFlush, base::Unretained(this))); 67 base::Bind(&FileFlusherTest::OnFlush, base::Unretained(this)));
68 return flusher; 68 return flusher;
69 } 69 }
70 70
71 base::FilePath GetTestFilePath(const std::string& path_string) const { 71 base::FilePath GetTestFilePath(const std::string& path_string) const {
72 const base::FilePath path = base::FilePath::FromUTF8Unsafe(path_string); 72 const base::FilePath path = base::FilePath::FromUTF8Unsafe(path_string);
73 if (path.IsAbsolute()) 73 if (path.IsAbsolute())
74 return path; 74 return path;
75 75
76 return temp_dir_.path().Append(path); 76 return temp_dir_.GetPath().Append(path);
77 } 77 }
78 78
79 void OnFlush(const base::FilePath& path) { ++flush_counts_[path]; } 79 void OnFlush(const base::FilePath& path) { ++flush_counts_[path]; }
80 80
81 int GetFlushCount(const std::string& path_string) const { 81 int GetFlushCount(const std::string& path_string) const {
82 const base::FilePath path(GetTestFilePath(path_string)); 82 const base::FilePath path(GetTestFilePath(path_string));
83 const auto& it = flush_counts_.find(path); 83 const auto& it = flush_counts_.find(path);
84 return it == flush_counts_.end() ? 0 : it->second; 84 return it == flush_counts_.end() ? 0 : it->second;
85 } 85 }
86 86
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 flusher->RequestFlush(GetTestFilePath("dir1"), std::vector<base::FilePath>(), 141 flusher->RequestFlush(GetTestFilePath("dir1"), std::vector<base::FilePath>(),
142 run_loop.QuitClosure()); 142 run_loop.QuitClosure());
143 run_loop.Run(); 143 run_loop.Run();
144 144
145 EXPECT_EQ(1, GetFlushCount("dir1/file1")); 145 EXPECT_EQ(1, GetFlushCount("dir1/file1"));
146 EXPECT_EQ(1, GetFlushCount("dir1/file2")); 146 EXPECT_EQ(1, GetFlushCount("dir1/file2"));
147 EXPECT_EQ(1, GetFlushCount("dir1/file3")); 147 EXPECT_EQ(1, GetFlushCount("dir1/file3"));
148 } 148 }
149 149
150 } // namespace chromeos 150 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service_unittest.cc ('k') | chrome/browser/chromeos/drive/download_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698