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

Side by Side Diff: components/leveldb_proto/proto_database_impl_unittest.cc

Issue 1144153004: components: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/leveldb_proto/proto_database_impl.h" 5 #include "components/leveldb_proto/proto_database_impl.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/location.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
14 #include "components/leveldb_proto/leveldb_database.h" 15 #include "components/leveldb_proto/leveldb_database.h"
15 #include "components/leveldb_proto/testing/proto/test.pb.h" 16 #include "components/leveldb_proto/testing/proto/test.pb.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/leveldatabase/src/include/leveldb/options.h" 19 #include "third_party/leveldatabase/src/include/leveldb/options.h"
19 20
20 using base::MessageLoop; 21 using base::MessageLoop;
21 using base::ScopedTempDir; 22 using base::ScopedTempDir;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 std::string serialized_actual = actual[i].SerializeAsString(); 80 std::string serialized_actual = actual[i].SerializeAsString();
80 EXPECT_EQ(serialized_expected, serialized_actual); 81 EXPECT_EQ(serialized_expected, serialized_actual);
81 expected.erase(expected_it); 82 expected.erase(expected_it);
82 } 83 }
83 } 84 }
84 85
85 class ProtoDatabaseImplTest : public testing::Test { 86 class ProtoDatabaseImplTest : public testing::Test {
86 public: 87 public:
87 void SetUp() override { 88 void SetUp() override {
88 main_loop_.reset(new MessageLoop()); 89 main_loop_.reset(new MessageLoop());
89 db_.reset( 90 db_.reset(new ProtoDatabaseImpl<TestProto>(main_loop_->task_runner()));
90 new ProtoDatabaseImpl<TestProto>(main_loop_->message_loop_proxy()));
91 } 91 }
92 92
93 void TearDown() override { 93 void TearDown() override {
94 db_.reset(); 94 db_.reset();
95 base::RunLoop().RunUntilIdle(); 95 base::RunLoop().RunUntilIdle();
96 main_loop_.reset(); 96 main_loop_.reset();
97 } 97 }
98 98
99 scoped_ptr<ProtoDatabaseImpl<TestProto> > db_; 99 scoped_ptr<ProtoDatabaseImpl<TestProto> > db_;
100 scoped_ptr<MessageLoop> main_loop_; 100 scoped_ptr<MessageLoop> main_loop_;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // threading violations. 325 // threading violations.
326 TEST(ProtoDatabaseImplThreadingTest, TestDBDestruction) { 326 TEST(ProtoDatabaseImplThreadingTest, TestDBDestruction) {
327 base::MessageLoop main_loop; 327 base::MessageLoop main_loop;
328 328
329 ScopedTempDir temp_dir; 329 ScopedTempDir temp_dir;
330 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 330 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
331 331
332 base::Thread db_thread("dbthread"); 332 base::Thread db_thread("dbthread");
333 ASSERT_TRUE(db_thread.Start()); 333 ASSERT_TRUE(db_thread.Start());
334 334
335 scoped_ptr<ProtoDatabaseImpl<TestProto> > db( 335 scoped_ptr<ProtoDatabaseImpl<TestProto>> db(
336 new ProtoDatabaseImpl<TestProto>(db_thread.message_loop_proxy())); 336 new ProtoDatabaseImpl<TestProto>(db_thread.task_runner()));
337 337
338 MockDatabaseCaller caller; 338 MockDatabaseCaller caller;
339 EXPECT_CALL(caller, InitCallback(_)); 339 EXPECT_CALL(caller, InitCallback(_));
340 db->Init(temp_dir.path(), base::Bind(&MockDatabaseCaller::InitCallback, 340 db->Init(temp_dir.path(), base::Bind(&MockDatabaseCaller::InitCallback,
341 base::Unretained(&caller))); 341 base::Unretained(&caller)));
342 342
343 db.reset(); 343 db.reset();
344 344
345 base::RunLoop run_loop; 345 base::RunLoop run_loop;
346 db_thread.message_loop_proxy()->PostTaskAndReply( 346 db_thread.task_runner()->PostTaskAndReply(
347 FROM_HERE, base::Bind(base::DoNothing), run_loop.QuitClosure()); 347 FROM_HERE, base::Bind(base::DoNothing), run_loop.QuitClosure());
348 run_loop.Run(); 348 run_loop.Run();
349 } 349 }
350 350
351 // Test that the LevelDB properly saves entries and that load returns the saved 351 // Test that the LevelDB properly saves entries and that load returns the saved
352 // entries. If |close_after_save| is true, the database will be closed after 352 // entries. If |close_after_save| is true, the database will be closed after
353 // saving and then re-opened to ensure that the data is properly persisted. 353 // saving and then re-opened to ensure that the data is properly persisted.
354 void TestLevelDBSaveAndLoad(bool close_after_save) { 354 void TestLevelDBSaveAndLoad(bool close_after_save) {
355 ScopedTempDir temp_dir; 355 ScopedTempDir temp_dir;
356 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 356 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 KeyValueVector save_entries; 406 KeyValueVector save_entries;
407 std::vector<std::string> load_entries; 407 std::vector<std::string> load_entries;
408 KeyVector remove_keys; 408 KeyVector remove_keys;
409 409
410 EXPECT_FALSE(db->InitWithOptions(temp_dir.path(), options)); 410 EXPECT_FALSE(db->InitWithOptions(temp_dir.path(), options));
411 EXPECT_FALSE(db->Load(&load_entries)); 411 EXPECT_FALSE(db->Load(&load_entries));
412 EXPECT_FALSE(db->Save(save_entries, remove_keys)); 412 EXPECT_FALSE(db->Save(save_entries, remove_keys));
413 } 413 }
414 414
415 } // namespace leveldb_proto 415 } // namespace leveldb_proto
OLDNEW
« no previous file with comments | « components/invalidation/sync_system_resources.cc ('k') | components/metrics/call_stack_profile_metrics_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698