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

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

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace chromeos { 20 namespace chromeos {
21 21
22 namespace { 22 namespace {
23 23
(...skipping 30 matching lines...) Expand all
54 WriteStringToFile(temp_dir_.path().AppendASCII(path), content); 54 WriteStringToFile(temp_dir_.path().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 scoped_ptr<FileFlusher> CreateFileFlusher() { 64 std::unique_ptr<FileFlusher> CreateFileFlusher() {
65 scoped_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
(...skipping 10 matching lines...) Expand all
86 86
87 private: 87 private:
88 content::TestBrowserThreadBundle thread_bundle_; 88 content::TestBrowserThreadBundle thread_bundle_;
89 base::ScopedTempDir temp_dir_; 89 base::ScopedTempDir temp_dir_;
90 std::map<base::FilePath, int> flush_counts_; 90 std::map<base::FilePath, int> flush_counts_;
91 91
92 DISALLOW_COPY_AND_ASSIGN(FileFlusherTest); 92 DISALLOW_COPY_AND_ASSIGN(FileFlusherTest);
93 }; 93 };
94 94
95 TEST_F(FileFlusherTest, Flush) { 95 TEST_F(FileFlusherTest, Flush) {
96 scoped_ptr<FileFlusher> flusher(CreateFileFlusher()); 96 std::unique_ptr<FileFlusher> flusher(CreateFileFlusher());
97 base::RunLoop run_loop; 97 base::RunLoop run_loop;
98 flusher->RequestFlush(GetTestFilePath("dir1"), std::vector<base::FilePath>(), 98 flusher->RequestFlush(GetTestFilePath("dir1"), std::vector<base::FilePath>(),
99 base::Closure()); 99 base::Closure());
100 flusher->RequestFlush(GetTestFilePath("dir2"), std::vector<base::FilePath>(), 100 flusher->RequestFlush(GetTestFilePath("dir2"), std::vector<base::FilePath>(),
101 run_loop.QuitClosure()); 101 run_loop.QuitClosure());
102 run_loop.Run(); 102 run_loop.Run();
103 103
104 EXPECT_EQ(1, GetFlushCount("dir1/file1")); 104 EXPECT_EQ(1, GetFlushCount("dir1/file1"));
105 EXPECT_EQ(1, GetFlushCount("dir1/file2")); 105 EXPECT_EQ(1, GetFlushCount("dir1/file2"));
106 EXPECT_EQ(1, GetFlushCount("dir1/file3")); 106 EXPECT_EQ(1, GetFlushCount("dir1/file3"));
107 107
108 EXPECT_EQ(1, GetFlushCount("dir2/file1")); 108 EXPECT_EQ(1, GetFlushCount("dir2/file1"));
109 EXPECT_EQ(1, GetFlushCount("dir2/file2")); 109 EXPECT_EQ(1, GetFlushCount("dir2/file2"));
110 EXPECT_EQ(1, GetFlushCount("dir2/file3")); 110 EXPECT_EQ(1, GetFlushCount("dir2/file3"));
111 } 111 }
112 112
113 TEST_F(FileFlusherTest, Exclude) { 113 TEST_F(FileFlusherTest, Exclude) {
114 scoped_ptr<FileFlusher> flusher(CreateFileFlusher()); 114 std::unique_ptr<FileFlusher> flusher(CreateFileFlusher());
115 115
116 std::vector<base::FilePath> excludes; 116 std::vector<base::FilePath> excludes;
117 // Relative exclude 117 // Relative exclude
118 excludes.push_back(base::FilePath::FromUTF8Unsafe("file1")); 118 excludes.push_back(base::FilePath::FromUTF8Unsafe("file1"));
119 // Absolute exclude 119 // Absolute exclude
120 excludes.push_back(GetTestFilePath("dir1/file2")); 120 excludes.push_back(GetTestFilePath("dir1/file2"));
121 // Invalid exclude will be ignored. 121 // Invalid exclude will be ignored.
122 excludes.push_back(base::FilePath::FromUTF8Unsafe("Bad file")); 122 excludes.push_back(base::FilePath::FromUTF8Unsafe("Bad file"));
123 123
124 base::RunLoop run_loop; 124 base::RunLoop run_loop;
125 flusher->RequestFlush(GetTestFilePath("dir1"), excludes, 125 flusher->RequestFlush(GetTestFilePath("dir1"), excludes,
126 run_loop.QuitClosure()); 126 run_loop.QuitClosure());
127 run_loop.Run(); 127 run_loop.Run();
128 128
129 EXPECT_EQ(0, GetFlushCount("dir1/file1")); 129 EXPECT_EQ(0, GetFlushCount("dir1/file1"));
130 EXPECT_EQ(0, GetFlushCount("dir1/file2")); 130 EXPECT_EQ(0, GetFlushCount("dir1/file2"));
131 EXPECT_EQ(1, GetFlushCount("dir1/file3")); 131 EXPECT_EQ(1, GetFlushCount("dir1/file3"));
132 132
133 EXPECT_EQ(0, GetFlushCount("dir1/Bad file")); 133 EXPECT_EQ(0, GetFlushCount("dir1/Bad file"));
134 } 134 }
135 135
136 TEST_F(FileFlusherTest, DuplicateRequests) { 136 TEST_F(FileFlusherTest, DuplicateRequests) {
137 scoped_ptr<FileFlusher> flusher(CreateFileFlusher()); 137 std::unique_ptr<FileFlusher> flusher(CreateFileFlusher());
138 base::RunLoop run_loop; 138 base::RunLoop run_loop;
139 flusher->RequestFlush(GetTestFilePath("dir1"), std::vector<base::FilePath>(), 139 flusher->RequestFlush(GetTestFilePath("dir1"), std::vector<base::FilePath>(),
140 base::Closure()); 140 base::Closure());
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/attestation/platform_verification_flow.cc ('k') | chrome/browser/chromeos/base/locale_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698