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

Side by Side Diff: chrome/browser/value_store/value_store_frontend_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "chrome/browser/value_store/value_store_frontend.h" 10 #include "chrome/browser/value_store/value_store_frontend.h"
11 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using content::BrowserThread; 15 using content::BrowserThread;
16 16
17 // Test suite for CachingValueStore, using a test database with a few simple 17 // Test suite for CachingValueStore, using a test database with a few simple
18 // entries. 18 // entries.
19 class ValueStoreFrontendTest : public testing::Test { 19 class ValueStoreFrontendTest : public testing::Test {
20 public: 20 public:
21 ValueStoreFrontendTest() 21 ValueStoreFrontendTest()
22 : ui_thread_(BrowserThread::UI, MessageLoop::current()), 22 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
23 file_thread_(BrowserThread::FILE, MessageLoop::current()) { 23 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
24 }
25 24
26 virtual void SetUp() { 25 virtual void SetUp() {
27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
28 27
29 base::FilePath test_data_dir; 28 base::FilePath test_data_dir;
30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 29 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
31 base::FilePath src_db(test_data_dir.AppendASCII("value_store_db")); 30 base::FilePath src_db(test_data_dir.AppendASCII("value_store_db"));
32 db_path_ = temp_dir_.path().AppendASCII("temp_db"); 31 db_path_ = temp_dir_.path().AppendASCII("temp_db");
33 file_util::CopyDirectory(src_db, db_path_, true); 32 file_util::CopyDirectory(src_db, db_path_, true);
34 33
35 ResetStorage(); 34 ResetStorage();
36 } 35 }
37 36
38 virtual void TearDown() { 37 virtual void TearDown() {
39 MessageLoop::current()->RunUntilIdle(); // wait for storage to delete 38 base::MessageLoop::current()->RunUntilIdle(); // wait for storage to delete
40 storage_.reset(); 39 storage_.reset();
41 } 40 }
42 41
43 // Reset the value store, reloading the DB from disk. 42 // Reset the value store, reloading the DB from disk.
44 void ResetStorage() { 43 void ResetStorage() {
45 storage_.reset(new ValueStoreFrontend(db_path_)); 44 storage_.reset(new ValueStoreFrontend(db_path_));
46 } 45 }
47 46
48 bool Get(const std::string& key, scoped_ptr<base::Value>* output) { 47 bool Get(const std::string& key, scoped_ptr<base::Value>* output) {
49 storage_->Get(key, base::Bind(&ValueStoreFrontendTest::GetAndWait, 48 storage_->Get(key, base::Bind(&ValueStoreFrontendTest::GetAndWait,
50 base::Unretained(this), output)); 49 base::Unretained(this), output));
51 MessageLoop::current()->Run(); // wait for GetAndWait 50 base::MessageLoop::current()->Run(); // wait for GetAndWait
52 return !!output->get(); 51 return !!output->get();
53 } 52 }
54 53
55 protected: 54 protected:
56 void GetAndWait(scoped_ptr<base::Value>* output, 55 void GetAndWait(scoped_ptr<base::Value>* output,
57 scoped_ptr<base::Value> result) { 56 scoped_ptr<base::Value> result) {
58 *output = result.Pass(); 57 *output = result.Pass();
59 MessageLoop::current()->Quit(); 58 base::MessageLoop::current()->Quit();
60 } 59 }
61 60
62 scoped_ptr<ValueStoreFrontend> storage_; 61 scoped_ptr<ValueStoreFrontend> storage_;
63 base::ScopedTempDir temp_dir_; 62 base::ScopedTempDir temp_dir_;
64 base::FilePath db_path_; 63 base::FilePath db_path_;
65 MessageLoop message_loop_; 64 base::MessageLoop message_loop_;
66 content::TestBrowserThread ui_thread_; 65 content::TestBrowserThread ui_thread_;
67 content::TestBrowserThread file_thread_; 66 content::TestBrowserThread file_thread_;
68 }; 67 };
69 68
70 TEST_F(ValueStoreFrontendTest, GetExistingData) { 69 TEST_F(ValueStoreFrontendTest, GetExistingData) {
71 scoped_ptr<base::Value> value(NULL); 70 scoped_ptr<base::Value> value(NULL);
72 ASSERT_FALSE(Get("key0", &value)); 71 ASSERT_FALSE(Get("key0", &value));
73 72
74 // Test existing keys in the DB. 73 // Test existing keys in the DB.
75 { 74 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 106
108 { 107 {
109 ASSERT_TRUE(Get("key1", &value)); 108 ASSERT_TRUE(Get("key1", &value));
110 std::string result; 109 std::string result;
111 ASSERT_TRUE(value->GetAsString(&result)); 110 ASSERT_TRUE(value->GetAsString(&result));
112 EXPECT_EQ("new1", result); 111 EXPECT_EQ("new1", result);
113 } 112 }
114 113
115 ASSERT_FALSE(Get("key2", &value)); 114 ASSERT_FALSE(Get("key2", &value));
116 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698