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

Side by Side Diff: chrome/browser/ui/app_list/search/history_unittest.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/test/sequenced_worker_pool_owner.h" 15 #include "base/test/sequenced_worker_pool_owner.h"
15 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
16 #include "chrome/browser/ui/app_list/search/history_factory.h" 17 #include "chrome/browser/ui/app_list/search/history_factory.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/app_list/search/dictionary_data_store.h" 19 #include "ui/app_list/search/dictionary_data_store.h"
19 #include "ui/app_list/search/history.h" 20 #include "ui/app_list/search/history.h"
20 #include "ui/app_list/search/history_data.h" 21 #include "ui/app_list/search/history_data.h"
(...skipping 24 matching lines...) Expand all
45 run_loop_->Run(); 46 run_loop_->Run();
46 47
47 data_->RemoveObserver(this); 48 data_->RemoveObserver(this);
48 } 49 }
49 50
50 private: 51 private:
51 // HistoryDataObserver overrides: 52 // HistoryDataObserver overrides:
52 void OnHistoryDataLoadedFromStore() override { run_loop_->Quit(); } 53 void OnHistoryDataLoadedFromStore() override { run_loop_->Quit(); }
53 54
54 HistoryData* data_; // Not owned. 55 HistoryData* data_; // Not owned.
55 scoped_ptr<base::RunLoop> run_loop_; 56 std::unique_ptr<base::RunLoop> run_loop_;
56 57
57 DISALLOW_COPY_AND_ASSIGN(HistoryDataLoadWaiter); 58 DISALLOW_COPY_AND_ASSIGN(HistoryDataLoadWaiter);
58 }; 59 };
59 60
60 // StoreFlushWaiter waits for the given |store| to flush its data to disk. 61 // StoreFlushWaiter waits for the given |store| to flush its data to disk.
61 // The flush and disk write happens on the blocking pool. The waiter waits 62 // The flush and disk write happens on the blocking pool. The waiter waits
62 // on the main message loop until the OnFlushed() is invoked or the maximum 63 // on the main message loop until the OnFlushed() is invoked or the maximum
63 // allowed wait time has passed. 64 // allowed wait time has passed.
64 class StoreFlushWaiter { 65 class StoreFlushWaiter {
65 public: 66 public:
66 explicit StoreFlushWaiter(HistoryDataStore* store) : store_(store) {} 67 explicit StoreFlushWaiter(HistoryDataStore* store) : store_(store) {}
67 ~StoreFlushWaiter() {} 68 ~StoreFlushWaiter() {}
68 69
69 void Wait() { 70 void Wait() {
70 store_->Flush( 71 store_->Flush(
71 base::Bind(&StoreFlushWaiter::OnFlushed, base::Unretained(this))); 72 base::Bind(&StoreFlushWaiter::OnFlushed, base::Unretained(this)));
72 73
73 run_loop_.reset(new base::RunLoop); 74 run_loop_.reset(new base::RunLoop);
74 run_loop_->Run(); 75 run_loop_->Run();
75 } 76 }
76 77
77 private: 78 private:
78 void OnFlushed() { 79 void OnFlushed() {
79 run_loop_->Quit(); 80 run_loop_->Quit();
80 } 81 }
81 82
82 HistoryDataStore* store_; // Not owned. 83 HistoryDataStore* store_; // Not owned.
83 scoped_ptr<base::RunLoop> run_loop_; 84 std::unique_ptr<base::RunLoop> run_loop_;
84 85
85 DISALLOW_COPY_AND_ASSIGN(StoreFlushWaiter); 86 DISALLOW_COPY_AND_ASSIGN(StoreFlushWaiter);
86 }; 87 };
87 88
88 } // namespace 89 } // namespace
89 90
90 class SearchHistoryTest : public testing::Test { 91 class SearchHistoryTest : public testing::Test {
91 public: 92 public:
92 SearchHistoryTest() {} 93 SearchHistoryTest() {}
93 ~SearchHistoryTest() override {} 94 ~SearchHistoryTest() override {}
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 139 }
139 140
140 History* history() { return history_.get(); } 141 History* history() { return history_.get(); }
141 const HistoryData::Associations& associations() const { 142 const HistoryData::Associations& associations() const {
142 return history_->data_->associations(); 143 return history_->data_->associations();
143 } 144 }
144 145
145 private: 146 private:
146 base::MessageLoopForUI message_loop_; 147 base::MessageLoopForUI message_loop_;
147 base::ScopedTempDir temp_dir_; 148 base::ScopedTempDir temp_dir_;
148 scoped_ptr<base::SequencedWorkerPoolOwner> worker_pool_owner_; 149 std::unique_ptr<base::SequencedWorkerPoolOwner> worker_pool_owner_;
149 150
150 scoped_ptr<History> history_; 151 std::unique_ptr<History> history_;
151 scoped_ptr<KnownResults> known_results_; 152 std::unique_ptr<KnownResults> known_results_;
152 153
153 DISALLOW_COPY_AND_ASSIGN(SearchHistoryTest); 154 DISALLOW_COPY_AND_ASSIGN(SearchHistoryTest);
154 }; 155 };
155 156
156 TEST_F(SearchHistoryTest, Persistence) { 157 TEST_F(SearchHistoryTest, Persistence) {
157 // Ensure it's empty. 158 // Ensure it's empty.
158 EXPECT_EQ(0u, GetKnownResults("cal")); 159 EXPECT_EQ(0u, GetKnownResults("cal"));
159 160
160 // Add one launch event. 161 // Add one launch event.
161 history()->AddLaunchEvent("cal", "calendar"); 162 history()->AddLaunchEvent("cal", "calendar");
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 296
296 // The oldest secondary is gone. 297 // The oldest secondary is gone.
297 EXPECT_EQ(UNKNOWN_RESULT, GetResultType("1")); 298 EXPECT_EQ(UNKNOWN_RESULT, GetResultType("1"));
298 299
299 // Touched oldest survived. 300 // Touched oldest survived.
300 EXPECT_EQ(PERFECT_SECONDARY, GetResultType("0")); 301 EXPECT_EQ(PERFECT_SECONDARY, GetResultType("0"));
301 } 302 }
302 303
303 } // namespace test 304 } // namespace test
304 } // namespace app_list 305 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698