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

Side by Side Diff: ui/app_list/search/history_data_store_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698