OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/host/it2me/it2me_confirmation_dialog_proxy.h" | 5 #include "remoting/host/it2me/it2me_confirmation_dialog_proxy.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return dialog_; | 109 return dialog_; |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
113 base::MessageLoop message_loop_; | 113 base::MessageLoop message_loop_; |
114 base::RunLoop run_loop_; | 114 base::RunLoop run_loop_; |
115 base::Thread dialog_thread_; | 115 base::Thread dialog_thread_; |
116 | 116 |
117 // |dialog_| is owned by |dialog_proxy_| but we keep an alias for test | 117 // |dialog_| is owned by |dialog_proxy_| but we keep an alias for test |
118 // purposes. | 118 // purposes. |
119 StubIt2MeConfirmationDialog* dialog_; | 119 StubIt2MeConfirmationDialog* dialog_ = nullptr; |
120 std::unique_ptr<It2MeConfirmationDialogProxy> dialog_proxy_; | 120 std::unique_ptr<It2MeConfirmationDialogProxy> dialog_proxy_; |
121 }; | 121 }; |
122 | 122 |
123 It2MeConfirmationDialogProxyTest::It2MeConfirmationDialogProxyTest() | 123 It2MeConfirmationDialogProxyTest::It2MeConfirmationDialogProxyTest() |
124 : dialog_thread_("test dialog thread") { | 124 : dialog_thread_("test dialog thread") { |
125 dialog_thread_.Start(); | 125 dialog_thread_.Start(); |
126 | 126 |
127 dialog_ = new StubIt2MeConfirmationDialog(dialog_task_runner()); | 127 dialog_ = new StubIt2MeConfirmationDialog(dialog_task_runner()); |
128 dialog_proxy_.reset(new It2MeConfirmationDialogProxy( | 128 dialog_proxy_.reset(new It2MeConfirmationDialogProxy( |
129 dialog_task_runner(), std::unique_ptr<It2MeConfirmationDialog>(dialog_))); | 129 dialog_task_runner(), std::unique_ptr<It2MeConfirmationDialog>(dialog_))); |
130 } | 130 } |
131 | 131 |
132 It2MeConfirmationDialogProxyTest::~It2MeConfirmationDialogProxyTest() {} | 132 It2MeConfirmationDialogProxyTest::~It2MeConfirmationDialogProxyTest() {} |
133 | 133 |
134 TEST_F(It2MeConfirmationDialogProxyTest, Show) { | 134 TEST_F(It2MeConfirmationDialogProxyTest, ShowAction_OkButtonClicked) { |
135 ResultCallbackTarget callback_target(main_task_runner()); | 135 ResultCallbackTarget callback_target(main_task_runner()); |
136 | 136 |
137 EXPECT_CALL(*dialog(), OnShow()) | 137 EXPECT_CALL(*dialog(), OnShow()) |
| 138 .WillOnce(InvokeWithoutArgs(CreateFunctor( |
| 139 &StubIt2MeConfirmationDialog::ReportResult, |
| 140 base::Unretained(dialog()), It2MeConfirmationDialog::Result::OK))); |
| 141 |
| 142 EXPECT_CALL(callback_target, |
| 143 OnDialogResult(It2MeConfirmationDialog::Result::OK)) |
| 144 .WillOnce( |
| 145 InvokeWithoutArgs(this, &It2MeConfirmationDialogProxyTest::Quit)); |
| 146 |
| 147 dialog_proxy()->Show(kTestEmailAddress, callback_target.MakeCallback()); |
| 148 |
| 149 Run(); |
| 150 } |
| 151 |
| 152 TEST_F(It2MeConfirmationDialogProxyTest, ShowAction_CancelButtonClicked) { |
| 153 ResultCallbackTarget callback_target(main_task_runner()); |
| 154 |
| 155 EXPECT_CALL(*dialog(), OnShow()) |
138 .WillOnce( | 156 .WillOnce( |
139 InvokeWithoutArgs( | 157 InvokeWithoutArgs( |
140 CreateFunctor( | 158 CreateFunctor( |
141 &StubIt2MeConfirmationDialog::ReportResult, | 159 &StubIt2MeConfirmationDialog::ReportResult, |
142 base::Unretained(dialog()), | 160 base::Unretained(dialog()), |
143 It2MeConfirmationDialog::Result::CANCEL))); | 161 It2MeConfirmationDialog::Result::CANCEL))); |
144 | 162 |
145 EXPECT_CALL(callback_target, | 163 EXPECT_CALL(callback_target, |
146 OnDialogResult(It2MeConfirmationDialog::Result::CANCEL)) | 164 OnDialogResult(It2MeConfirmationDialog::Result::CANCEL)) |
147 .WillOnce( | 165 .WillOnce( |
148 InvokeWithoutArgs(this, &It2MeConfirmationDialogProxyTest::Quit)); | 166 InvokeWithoutArgs(this, &It2MeConfirmationDialogProxyTest::Quit)); |
149 | 167 |
150 dialog_proxy()->Show(kTestEmailAddress, callback_target.MakeCallback()); | 168 dialog_proxy()->Show(kTestEmailAddress, callback_target.MakeCallback()); |
151 | 169 |
152 Run(); | 170 Run(); |
153 } | 171 } |
154 | 172 |
| 173 TEST_F(It2MeConfirmationDialogProxyTest, ShowActionCancelled_OkButtonClicked) { |
| 174 ResultCallbackTarget callback_target(main_task_runner()); |
| 175 |
| 176 EXPECT_CALL(*dialog(), OnShow()) |
| 177 .WillOnce(InvokeWithoutArgs(CreateFunctor( |
| 178 &StubIt2MeConfirmationDialog::ReportResult, |
| 179 base::Unretained(dialog()), It2MeConfirmationDialog::Result::OK))); |
| 180 |
| 181 EXPECT_CALL(callback_target, |
| 182 OnDialogResult(It2MeConfirmationDialog::Result::CANCEL)) |
| 183 .WillOnce( |
| 184 InvokeWithoutArgs(this, &It2MeConfirmationDialogProxyTest::Quit)); |
| 185 |
| 186 dialog_proxy()->Show(kTestEmailAddress, callback_target.MakeCallback()); |
| 187 |
| 188 dialog_proxy()->Cancel(); |
| 189 |
| 190 Run(); |
| 191 } |
| 192 |
155 } // namespace remoting | 193 } // namespace remoting |
OLD | NEW |