| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <set> | 5 #include <set> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" |
| 8 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 9 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/test/test_suite.h" | 17 #include "base/test/test_suite.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 testing::Test::SetUp(); | 203 testing::Test::SetUp(); |
| 203 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 204 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| 204 } | 205 } |
| 205 | 206 |
| 206 const base::FilePath& temp_path() const { return scoped_temp_dir_.GetPath(); } | 207 const base::FilePath& temp_path() const { return scoped_temp_dir_.GetPath(); } |
| 207 | 208 |
| 208 using VisitedDBSet = std::set<DBTracker::TrackedDB*>; | 209 using VisitedDBSet = std::set<DBTracker::TrackedDB*>; |
| 209 | 210 |
| 210 static VisitedDBSet VisitDatabases() { | 211 static VisitedDBSet VisitDatabases() { |
| 211 VisitedDBSet visited; | 212 VisitedDBSet visited; |
| 212 auto db_visitor = [&](DBTracker::TrackedDB* db) { | 213 auto db_visitor = [](VisitedDBSet* visited, DBTracker::TrackedDB* db) { |
| 213 ASSERT_TRUE(visited.insert(db).second) | 214 ASSERT_TRUE(visited->insert(db).second) |
| 214 << "Database " << std::hex << db << " visited for the second time"; | 215 << "Database " << std::hex << db << " visited for the second time"; |
| 215 }; | 216 }; |
| 216 DBTracker::GetInstance()->VisitDatabases(db_visitor); | 217 DBTracker::GetInstance()->VisitDatabases( |
| 218 base::BindRepeating(db_visitor, base::Unretained(&visited))); |
| 217 return visited; | 219 return visited; |
| 218 } | 220 } |
| 219 | 221 |
| 220 using LiveDBSet = std::vector<std::unique_ptr<DBTracker::TrackedDB>>; | 222 using LiveDBSet = std::vector<std::unique_ptr<DBTracker::TrackedDB>>; |
| 221 | 223 |
| 222 void AssertEqualSets(const LiveDBSet& live_dbs, | 224 void AssertEqualSets(const LiveDBSet& live_dbs, |
| 223 const VisitedDBSet& visited_dbs) { | 225 const VisitedDBSet& visited_dbs) { |
| 224 for (const auto& live_db : live_dbs) { | 226 for (const auto& live_db : live_dbs) { |
| 225 ASSERT_EQ(1u, visited_dbs.count(live_db.get())) | 227 ASSERT_EQ(1u, visited_dbs.count(live_db.get())) |
| 226 << "Database " << std::hex << live_db.get() << " was not visited"; | 228 << "Database " << std::hex << live_db.get() << " was not visited"; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 ASSERT_TRUE(status.ok()) << status.ToString(); | 321 ASSERT_TRUE(status.ok()) << status.ToString(); |
| 320 | 322 |
| 321 auto visited_dbs = VisitDatabases(); | 323 auto visited_dbs = VisitDatabases(); |
| 322 | 324 |
| 323 // Databases returned by OpenDB() should be tracked. | 325 // Databases returned by OpenDB() should be tracked. |
| 324 ASSERT_EQ(1u, visited_dbs.size()); | 326 ASSERT_EQ(1u, visited_dbs.size()); |
| 325 ASSERT_EQ(db.get(), *visited_dbs.begin()); | 327 ASSERT_EQ(db.get(), *visited_dbs.begin()); |
| 326 } | 328 } |
| 327 | 329 |
| 328 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } | 330 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } |
| OLD | NEW |