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

Side by Side Diff: components/previews/previews_ui_service_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_ui_service.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_io_data.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace previews {
17
18 namespace {
19
20 class TestPreviewsUIService : public PreviewsUIService {
21 public:
22 TestPreviewsUIService(
23 PreviewsIOData* previews_io_data,
24 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
25 : PreviewsUIService(previews_io_data, io_task_runner),
26 io_data_set_(false) {}
27 ~TestPreviewsUIService() override {}
28
29 // Set |io_data_set_| to true and use base class functionality.
30 void SetIOData(base::WeakPtr<PreviewsIOData> previews_io_data) override {
31 io_data_set_ = true;
32 PreviewsUIService::SetIOData(previews_io_data);
33 }
34
35 // Whether SetIOData was called.
36 bool io_data_set() { return io_data_set_; }
37
38 private:
39 // Whether SetIOData was called.
40 bool io_data_set_;
41 };
42
43 class PreviewsUIServiceTest : public testing::Test {
44 public:
45 PreviewsUIServiceTest() {}
46
47 ~PreviewsUIServiceTest() override {}
48
49 void set_io_data(std::unique_ptr<PreviewsIOData> io_data) {
50 io_data_ = std::move(io_data);
51 }
52
53 PreviewsIOData* io_data() { return io_data_.get(); }
54
55 void set_ui_service(std::unique_ptr<TestPreviewsUIService> ui_service) {
56 ui_service_ = std::move(ui_service);
57 }
58
59 TestPreviewsUIService* ui_service() { return ui_service_.get(); }
60
61 protected:
62 // Run this test on a single thread.
63 base::MessageLoopForIO loop_;
64
65 private:
66 std::unique_ptr<PreviewsIOData> io_data_;
67 std::unique_ptr<TestPreviewsUIService> ui_service_;
68 };
69
70 } // namespace
71
72 TEST_F(PreviewsUIServiceTest, TestInitialization) {
73 set_io_data(base::WrapUnique(
74 new PreviewsIOData(loop_.task_runner(), loop_.task_runner())));
75 set_ui_service(base::WrapUnique(
76 new TestPreviewsUIService(io_data(), loop_.task_runner())));
77 loop_.RunUntilIdle();
78 // After the outstanding posted tasks have run, SetIOData should have been
79 // called for |ui_service_|.
80 EXPECT_TRUE(ui_service()->io_data_set());
81 }
82
83 } // namespace previews
OLDNEW
« components/previews/previews_io_data.h ('K') | « components/previews/previews_ui_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698