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

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

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

Powered by Google App Engine
This is Rietveld 408576698