OLD | NEW |
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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" | 10 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" |
11 #include "chrome/browser/predictors/predictor_database.h" | 11 #include "chrome/browser/predictors/predictor_database.h" |
12 #include "chrome/browser/predictors/predictor_database_factory.h" | 12 #include "chrome/browser/predictors/predictor_database_factory.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "sql/statement.h" | 16 #include "sql/statement.h" |
16 | 17 |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 using base::Time; | 20 using base::Time; |
20 using base::TimeDelta; | 21 using base::TimeDelta; |
21 using content::BrowserThread; | 22 using content::BrowserThread; |
22 using predictors::AutocompleteActionPredictorTable; | 23 using predictors::AutocompleteActionPredictorTable; |
23 | 24 |
24 namespace predictors { | 25 namespace predictors { |
25 | 26 |
26 class AutocompleteActionPredictorTableTest : public testing::Test { | 27 class AutocompleteActionPredictorTableTest : public testing::Test { |
27 public: | 28 protected: |
28 AutocompleteActionPredictorTableTest(); | |
29 virtual ~AutocompleteActionPredictorTableTest(); | |
30 | |
31 virtual void SetUp(); | 29 virtual void SetUp(); |
32 virtual void TearDown(); | 30 virtual void TearDown(); |
33 | 31 |
34 size_t CountRecords() const; | 32 size_t CountRecords() const; |
35 | 33 |
36 void AddAll(); | 34 void AddAll(); |
37 | 35 |
38 bool RowsAreEqual(const AutocompleteActionPredictorTable::Row& lhs, | 36 bool RowsAreEqual(const AutocompleteActionPredictorTable::Row& lhs, |
39 const AutocompleteActionPredictorTable::Row& rhs) const; | 37 const AutocompleteActionPredictorTable::Row& rhs) const; |
40 | 38 |
41 TestingProfile* profile() { return &profile_; } | 39 TestingProfile* profile() { return &profile_; } |
42 | 40 |
43 protected: | |
44 | |
45 // Test functions that can be run against this text fixture or | 41 // Test functions that can be run against this text fixture or |
46 // AutocompleteActionPredictorTableReopenTest that inherits from this. | 42 // AutocompleteActionPredictorTableReopenTest that inherits from this. |
47 void TestGetRow(); | 43 void TestGetRow(); |
48 void TestAddAndUpdateRows(); | 44 void TestAddAndUpdateRows(); |
49 void TestDeleteRows(); | 45 void TestDeleteRows(); |
50 void TestDeleteAllRows(); | 46 void TestDeleteAllRows(); |
51 | 47 |
52 AutocompleteActionPredictorTable::Rows test_db_; | 48 AutocompleteActionPredictorTable::Rows test_db_; |
53 | 49 |
54 private: | 50 private: |
| 51 content::TestBrowserThreadBundle thread_bundle_; |
55 TestingProfile profile_; | 52 TestingProfile profile_; |
56 scoped_ptr<PredictorDatabase> db_; | 53 scoped_ptr<PredictorDatabase> db_; |
57 base::MessageLoop loop_; | |
58 content::TestBrowserThread db_thread_; | |
59 }; | 54 }; |
60 | 55 |
61 class AutocompleteActionPredictorTableReopenTest | 56 class AutocompleteActionPredictorTableReopenTest |
62 : public AutocompleteActionPredictorTableTest { | 57 : public AutocompleteActionPredictorTableTest { |
63 public: | 58 protected: |
64 virtual void SetUp() { | 59 virtual void SetUp() { |
65 // By calling SetUp twice, we make sure that the table already exists for | 60 // By calling SetUp twice, we make sure that the table already exists for |
66 // this fixture. | 61 // this fixture. |
67 AutocompleteActionPredictorTableTest::SetUp(); | 62 AutocompleteActionPredictorTableTest::SetUp(); |
68 AutocompleteActionPredictorTableTest::TearDown(); | 63 AutocompleteActionPredictorTableTest::TearDown(); |
69 AutocompleteActionPredictorTableTest::SetUp(); | 64 AutocompleteActionPredictorTableTest::SetUp(); |
70 } | 65 } |
71 }; | 66 }; |
72 | 67 |
73 AutocompleteActionPredictorTableTest::AutocompleteActionPredictorTableTest() | |
74 : loop_(base::MessageLoop::TYPE_DEFAULT), | |
75 db_thread_(BrowserThread::DB, &loop_) { | |
76 } | |
77 | |
78 AutocompleteActionPredictorTableTest::~AutocompleteActionPredictorTableTest() { | |
79 } | |
80 | |
81 void AutocompleteActionPredictorTableTest::SetUp() { | 68 void AutocompleteActionPredictorTableTest::SetUp() { |
82 db_.reset(new PredictorDatabase(&profile_)); | 69 db_.reset(new PredictorDatabase(&profile_)); |
83 loop_.RunUntilIdle(); | 70 base::RunLoop().RunUntilIdle(); |
84 | 71 |
85 test_db_.push_back(AutocompleteActionPredictorTable::Row( | 72 test_db_.push_back(AutocompleteActionPredictorTable::Row( |
86 "BD85DBA2-8C29-49F9-84AE-48E1E90880DF", | 73 "BD85DBA2-8C29-49F9-84AE-48E1E90880DF", |
87 ASCIIToUTF16("goog"), GURL("http://www.google.com/"), | 74 ASCIIToUTF16("goog"), GURL("http://www.google.com/"), |
88 1, 0)); | 75 1, 0)); |
89 test_db_.push_back(AutocompleteActionPredictorTable::Row( | 76 test_db_.push_back(AutocompleteActionPredictorTable::Row( |
90 "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", | 77 "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", |
91 ASCIIToUTF16("slash"), GURL("http://slashdot.org/"), | 78 ASCIIToUTF16("slash"), GURL("http://slashdot.org/"), |
92 3, 2)); | 79 3, 2)); |
93 test_db_.push_back(AutocompleteActionPredictorTable::Row( | 80 test_db_.push_back(AutocompleteActionPredictorTable::Row( |
94 "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", | 81 "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", |
95 ASCIIToUTF16("news"), GURL("http://slashdot.org/"), | 82 ASCIIToUTF16("news"), GURL("http://slashdot.org/"), |
96 0, 1)); | 83 0, 1)); |
97 } | 84 } |
98 | 85 |
99 void AutocompleteActionPredictorTableTest::TearDown() { | 86 void AutocompleteActionPredictorTableTest::TearDown() { |
100 db_.reset(NULL); | 87 db_.reset(NULL); |
101 loop_.RunUntilIdle(); | 88 base::RunLoop().RunUntilIdle(); |
102 test_db_.clear(); | 89 test_db_.clear(); |
103 } | 90 } |
104 | 91 |
105 size_t AutocompleteActionPredictorTableTest::CountRecords() const { | 92 size_t AutocompleteActionPredictorTableTest::CountRecords() const { |
106 sql::Statement s(db_->GetDatabase()->GetUniqueStatement( | 93 sql::Statement s(db_->GetDatabase()->GetUniqueStatement( |
107 "SELECT count(*) FROM network_action_predictor")); | 94 "SELECT count(*) FROM network_action_predictor")); |
108 EXPECT_TRUE(s.Step()); | 95 EXPECT_TRUE(s.Step()); |
109 return static_cast<size_t>(s.ColumnInt(0)); | 96 return static_cast<size_t>(s.ColumnInt(0)); |
110 } | 97 } |
111 | 98 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 218 |
232 TEST_F(AutocompleteActionPredictorTableReopenTest, DeleteRows) { | 219 TEST_F(AutocompleteActionPredictorTableReopenTest, DeleteRows) { |
233 TestDeleteRows(); | 220 TestDeleteRows(); |
234 } | 221 } |
235 | 222 |
236 TEST_F(AutocompleteActionPredictorTableReopenTest, DeleteAllRows) { | 223 TEST_F(AutocompleteActionPredictorTableReopenTest, DeleteAllRows) { |
237 TestDeleteAllRows(); | 224 TestDeleteAllRows(); |
238 } | 225 } |
239 | 226 |
240 } // namespace predictors | 227 } // namespace predictors |
OLD | NEW |