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

Side by Side Diff: remoting/host/it2me/it2me_confirmation_dialog_proxy_unittest.cc

Issue 816903002: It2Me Confirmation Dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback, clean up implementation, add tests. Created 6 years 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 2014 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 "remoting/host/it2me/it2me_confirmation_dialog_proxy.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gmock_mutant.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using ::testing::InvokeWithoutArgs;
18 using ::testing::CreateFunctor;
19
20 namespace remoting {
21
22 class StubIt2MeConfirmationDialog : public It2MeConfirmationDialog {
23 public:
24 explicit StubIt2MeConfirmationDialog(
25 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
26 : task_runner_(task_runner) {
27 }
28 ~StubIt2MeConfirmationDialog() override {
29 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
30 }
31
32 void ReportResult(Result result) {
33 ASSERT_TRUE(task_runner_->BelongsToCurrentThread());
34 callback_.Run(result);
35 }
36
37 MOCK_METHOD0(OnShow, void());
38
39 // It2MeConfirmationDialog implementation.
40 void Show(const ResultCallback& callback) override {
41 EXPECT_TRUE(callback_.is_null());
42 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
43 callback_ = callback;
44 OnShow();
45 }
46
47 private:
48 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
49 ResultCallback callback_;
50 };
51
52 // Encapsulates a target for It2MeConfirmationDialog::ResultCallback.
53 class ResultCallbackTarget {
54 public:
55 explicit ResultCallbackTarget(
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
57 : task_runner_(task_runner) {
58 }
59
60 MOCK_METHOD1(OnDialogResult, void(It2MeConfirmationDialog::Result));
61
62 It2MeConfirmationDialog::ResultCallback MakeCallback() {
63 return base::Bind(&ResultCallbackTarget::HandleDialogResult,
64 base::Unretained(this));
65 }
66
67 private:
68 void HandleDialogResult(It2MeConfirmationDialog::Result result) {
69 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
70 OnDialogResult(result);
71 }
72
73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
74 };
75
76 class It2MeConfirmationDialogProxyTest : public testing::Test {
77 public:
78 It2MeConfirmationDialogProxyTest();
79 ~It2MeConfirmationDialogProxyTest() override;
80
81 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner() {
82 return message_loop_.task_runner();
83 }
84
85 scoped_refptr<base::SingleThreadTaskRunner> dialog_task_runner() {
86 return dialog_thread_.task_runner();
87 }
88
89 void Run() {
90 run_loop_.Run();
91 }
92
93 void Quit() {
94 run_loop_.Quit();
95 }
96
97 It2MeConfirmationDialogProxy* dialog_proxy() {
98 return dialog_proxy_.get();
99 }
100
101 StubIt2MeConfirmationDialog* dialog() {
102 return dialog_;
103 }
104
105 private:
106 base::MessageLoop message_loop_;
107 base::RunLoop run_loop_;
108 base::Thread dialog_thread_;
109
110 // |dialog_| is owned by |dialog_proxy_| but we keep an alias for test
111 // purposes.
112 StubIt2MeConfirmationDialog* dialog_;
113 scoped_ptr<It2MeConfirmationDialogProxy> dialog_proxy_;
114 };
115
116 It2MeConfirmationDialogProxyTest::It2MeConfirmationDialogProxyTest()
117 : dialog_thread_("test dialog thread") {
118 dialog_thread_.Start();
119
120 dialog_ = new StubIt2MeConfirmationDialog(dialog_task_runner());
121 dialog_proxy_.reset(new It2MeConfirmationDialogProxy(
122 dialog_task_runner(),
123 main_task_runner(),
124 scoped_ptr<It2MeConfirmationDialog>(dialog_)));
125 }
126
127 It2MeConfirmationDialogProxyTest::~It2MeConfirmationDialogProxyTest() {}
128
129 TEST_F(It2MeConfirmationDialogProxyTest, Show) {
130 ResultCallbackTarget callback_target(main_task_runner());
131
132 EXPECT_CALL(*dialog(), OnShow())
133 .WillOnce(
134 InvokeWithoutArgs(
135 CreateFunctor(
136 dialog(), &StubIt2MeConfirmationDialog::ReportResult,
137 It2MeConfirmationDialog::Result::CANCEL)));
138
139 EXPECT_CALL(callback_target,
140 OnDialogResult(It2MeConfirmationDialog::Result::CANCEL))
141 .WillOnce(
142 InvokeWithoutArgs(this, &It2MeConfirmationDialogProxyTest::Quit));
143
144 dialog_proxy()->Show(callback_target.MakeCallback());
145
146 Run();
147 }
148
149 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698