OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ui/app_list/search/history_data_store.h" |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop/message_loop.h" | |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_task_environment.h" |
12 #include "base/test/sequenced_worker_pool_owner.h" | 14 #include "base/test/sequenced_worker_pool_owner.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "ui/app_list/search/dictionary_data_store.h" | 16 #include "ui/app_list/search/dictionary_data_store.h" |
15 #include "ui/app_list/search/history_data.h" | 17 #include "ui/app_list/search/history_data.h" |
16 #include "ui/app_list/search/history_data_store.h" | |
17 | 18 |
18 namespace app_list { | 19 namespace app_list { |
19 namespace test { | 20 namespace test { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 std::string GetDataContent(const HistoryData::Data& data) { | 24 std::string GetDataContent(const HistoryData::Data& data) { |
24 std::string str = std::string("p:") + data.primary + ";s:"; | 25 std::string str = std::string("p:") + data.primary + ";s:"; |
25 bool first = true; | 26 bool first = true; |
26 for (HistoryData::SecondaryDeque::const_iterator it = data.secondary.begin(); | 27 for (HistoryData::SecondaryDeque::const_iterator it = data.secondary.begin(); |
27 it != data.secondary.end(); | 28 it != data.secondary.end(); |
28 ++it) { | 29 ++it) { |
29 if (first) | 30 if (first) |
30 first = false; | 31 first = false; |
31 else | 32 else |
32 str += ','; | 33 str += ','; |
33 | 34 |
34 str += *it; | 35 str += *it; |
35 } | 36 } |
36 | 37 |
37 return str; | 38 return str; |
38 } | 39 } |
39 | 40 |
40 } // namespace | 41 } // namespace |
41 | 42 |
42 class HistoryDataStoreTest : public testing::Test { | 43 class HistoryDataStoreTest : public testing::Test { |
43 public: | 44 public: |
44 HistoryDataStoreTest() : worker_pool_owner_(2, "AppLanucherTest") {} | 45 HistoryDataStoreTest() |
| 46 : scoped_task_environment_( |
| 47 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 48 worker_pool_owner_(2, "AppLanucherTest") {} |
45 | 49 |
46 // testing::Test overrides: | 50 // testing::Test overrides: |
47 void SetUp() override { | 51 void SetUp() override { |
48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 52 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
49 } | 53 } |
50 void TearDown() override { | 54 void TearDown() override { |
51 // Release |store_| while ui loop is still running. | 55 // Release |store_| while ui loop is still running. |
52 store_ = NULL; | 56 store_ = NULL; |
53 } | 57 } |
54 | 58 |
(...skipping 27 matching lines...) Expand all Loading... |
82 private: | 86 private: |
83 void OnRead(std::unique_ptr<HistoryData::Associations> associations) { | 87 void OnRead(std::unique_ptr<HistoryData::Associations> associations) { |
84 associations_.clear(); | 88 associations_.clear(); |
85 if (associations) | 89 if (associations) |
86 associations->swap(associations_); | 90 associations->swap(associations_); |
87 | 91 |
88 if (run_loop_) | 92 if (run_loop_) |
89 run_loop_->Quit(); | 93 run_loop_->Quit(); |
90 } | 94 } |
91 | 95 |
92 base::MessageLoopForUI message_loop_; | 96 base::test::ScopedTaskEnvironment scoped_task_environment_; |
93 base::ScopedTempDir temp_dir_; | 97 base::ScopedTempDir temp_dir_; |
94 base::FilePath data_file_; | 98 base::FilePath data_file_; |
95 std::unique_ptr<base::RunLoop> run_loop_; | 99 std::unique_ptr<base::RunLoop> run_loop_; |
96 base::SequencedWorkerPoolOwner worker_pool_owner_; | 100 base::SequencedWorkerPoolOwner worker_pool_owner_; |
97 | 101 |
98 scoped_refptr<HistoryDataStore> store_; | 102 scoped_refptr<HistoryDataStore> store_; |
99 HistoryData::Associations associations_; | 103 HistoryData::Associations associations_; |
100 | 104 |
101 DISALLOW_COPY_AND_ASSIGN(HistoryDataStoreTest); | 105 DISALLOW_COPY_AND_ASSIGN(HistoryDataStoreTest); |
102 }; | 106 }; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 EXPECT_EQ(now, it->second.update_time); | 174 EXPECT_EQ(now, it->second.update_time); |
171 | 175 |
172 store()->Delete(kQuery); | 176 store()->Delete(kQuery); |
173 Flush(); | 177 Flush(); |
174 Load(); | 178 Load(); |
175 EXPECT_TRUE(associations().empty()); | 179 EXPECT_TRUE(associations().empty()); |
176 } | 180 } |
177 | 181 |
178 } // namespace test | 182 } // namespace test |
179 } // namespace app_list | 183 } // namespace app_list |
OLD | NEW |