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

Side by Side Diff: components/previews/previews_io_data_unittest.cc

Issue 2300213002: Adding an IO Data and keyed service to previews/ (Closed)
Patch Set: thestig comments Created 4 years, 3 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/previews/previews_io_data.h"
6
7 #include <memory>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/single_thread_task_runner.h"
13 #include "components/previews/previews_ui_service.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace previews {
17
18 namespace {
19
20 class TestPreviewsIOData : public PreviewsIOData {
21 public:
22 TestPreviewsIOData(
23 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
24 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
25 : PreviewsIOData(io_task_runner, ui_task_runner), initialized_(false) {}
26 ~TestPreviewsIOData() override {}
27
28 // Whether Initialize was called.
29 bool initialized() { return initialized_; }
30
31 private:
32 // Set |initialized_| to true and use base class functionality.
33 void InitializeOnIOThread() override {
34 initialized_ = true;
35 PreviewsIOData::InitializeOnIOThread();
36 }
37
38 // Whether Initialize was called.
39 bool initialized_;
40 };
41
42 class PreviewsIODataTest : public testing::Test {
43 public:
44 PreviewsIODataTest() {}
45
46 ~PreviewsIODataTest() override {}
47
48 void set_io_data(std::unique_ptr<TestPreviewsIOData> io_data) {
49 io_data_ = std::move(io_data);
50 }
51
52 TestPreviewsIOData* io_data() { return io_data_.get(); }
53
54 void set_ui_service(std::unique_ptr<PreviewsUIService> ui_service) {
55 ui_service_ = std::move(ui_service);
56 }
57
58 protected:
59 // Run this test on a single thread.
60 base::MessageLoopForIO loop_;
61
62 private:
63 std::unique_ptr<TestPreviewsIOData> io_data_;
64 std::unique_ptr<PreviewsUIService> ui_service_;
65 };
66
67 } // namespace
68
69 TEST_F(PreviewsIODataTest, TestInitialization) {
70 set_io_data(base::WrapUnique(
71 new TestPreviewsIOData(loop_.task_runner(), loop_.task_runner())));
72 set_ui_service(
73 base::WrapUnique(new PreviewsUIService(io_data(), loop_.task_runner())));
74 loop_.RunUntilIdle();
75 // After the outstanding posted tasks have run, |io_data_| should be fully
76 // initialized.
77 EXPECT_TRUE(io_data()->initialized());
78 }
79
80 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698