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

Side by Side Diff: chrome/browser/chromeos/arc/arc_support_host_unittest.cc

Issue 2844383006: Turn ArcSupportHost from Observer model to Delegate (Closed)
Patch Set: Turn ArcSupportHost from Observer model to Delegate Created 3 years, 7 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 2017 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 "chrome/browser/chromeos/arc/arc_support_host.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/chromeos/arc/extensions/fake_arc_support.h"
9 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
10 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using testing::_;
17 using testing::Eq;
18
19 namespace arc {
20
21 class ArcSupportHostTest : public testing::Test {
Luis Héctor Chávez 2017/05/12 15:41:31 Can this class (and the rest of the tests) be in t
victorhsieh0 2017/05/12 18:31:55 Done.
22 public:
23 ArcSupportHostTest() = default;
24 ~ArcSupportHostTest() override = default;
25
26 void SetUp() override {
27 user_manager_enabler_ =
28 base::MakeUnique<chromeos::ScopedUserManagerEnabler>(
29 new chromeos::FakeChromeUserManager());
30
31 profile_ = base::MakeUnique<TestingProfile>();
32 support_host_ = base::MakeUnique<ArcSupportHost>(profile_.get());
33 fake_arc_support_ = base::MakeUnique<FakeArcSupport>(support_host_.get());
34 }
35
36 void TearDown() override {
37 fake_arc_support_.reset();
38 support_host_.reset();
39 profile_.reset();
40 user_manager_enabler_.reset();
41 }
42
43 ArcSupportHost* support_host() { return support_host_.get(); }
44 FakeArcSupport* fake_arc_support() { return fake_arc_support_.get(); }
45
46 protected:
47 class MockAuthDelegate : public ArcSupportHost::AuthDelegate {
Luis Héctor Chávez 2017/05/12 15:41:31 Can these three classes be in the anonymous namesp
victorhsieh0 2017/05/12 18:31:55 Done.
48 public:
49 MOCK_METHOD1(OnAuthSucceeded, void(const std::string& auth_code));
50 MOCK_METHOD0(OnAuthFailed, void());
51 MOCK_METHOD0(OnAuthRetry, void());
52 };
53
54 class MockTermsOfServiceDelegate
55 : public ArcSupportHost::TermsOfServiceDelegate {
56 public:
57 MOCK_METHOD3(OnTermsAgreed,
58 void(bool is_metrics_enabled,
59 bool is_backup_and_restore_enabled,
60 bool is_location_service_enabled));
61 MOCK_METHOD0(OnTermsRejected, void());
62 MOCK_METHOD0(OnTermsRetry, void());
63 };
64
65 class MockErrorDelegate : public ArcSupportHost::ErrorDelegate {
66 public:
67 MOCK_METHOD0(OnOptInAborted, void());
68 MOCK_METHOD0(OnRetryClicked, void());
69 MOCK_METHOD0(OnSendFeedbackClicked, void());
70 };
71
72 private:
73 // Fake as if the current testing thread is UI thread.
74 content::TestBrowserThreadBundle bundle_;
75
76 std::unique_ptr<TestingProfile> profile_;
77 std::unique_ptr<ArcSupportHost> support_host_;
78 std::unique_ptr<FakeArcSupport> fake_arc_support_;
79 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
80
81 DISALLOW_COPY_AND_ASSIGN(ArcSupportHostTest);
82 };
83
84 TEST_F(ArcSupportHostTest, AuthSucceeded) {
85 MockAuthDelegate auth_delegate;
86 support_host()->SetAuthDelegate(&auth_delegate);
87 support_host()->ShowLso();
88
89 EXPECT_CALL(auth_delegate, OnAuthSucceeded(Eq("fake_code")));
90 fake_arc_support()->EmulateAuthCodeResponse("fake_code");
91
92 support_host()->SetAuthDelegate(nullptr);
Luis Héctor Chávez 2017/05/12 15:41:31 (optional) Maybe add an RAII ScopedAuthDelegate? N
victorhsieh0 2017/05/12 18:31:55 Done.
93 }
94
95 TEST_F(ArcSupportHostTest, AuthFailed) {
96 MockAuthDelegate auth_delegate;
97 support_host()->SetAuthDelegate(&auth_delegate);
98 support_host()->ShowLso();
99
100 EXPECT_CALL(auth_delegate, OnAuthFailed());
101 fake_arc_support()->EmulateAuthFailure();
102
103 support_host()->SetAuthDelegate(nullptr);
104 }
105
106 TEST_F(ArcSupportHostTest, AuthRetryOnError) {
107 // Auth error can only happen after terms accepted.
108 MockAuthDelegate auth_delegate;
109 support_host()->SetAuthDelegate(&auth_delegate);
110 support_host()->ShowError(ArcSupportHost::Error::NETWORK_UNAVAILABLE_ERROR,
111 false /* should_show_send_feedback */);
112
113 EXPECT_CALL(auth_delegate, OnAuthRetry());
114 fake_arc_support()->ClickRetryButton();
115
116 support_host()->SetAuthDelegate(nullptr);
117 }
118
119 TEST_F(ArcSupportHostTest, TermsOfServiceAccept) {
120 MockTermsOfServiceDelegate tos_delegate;
121 support_host()->SetTermsOfServiceDelegate(&tos_delegate);
122 support_host()->ShowTermsOfService();
123
124 EXPECT_CALL(tos_delegate, OnTermsAgreed(_, _, _));
125 fake_arc_support()->ClickAgreeButton();
126
127 support_host()->SetTermsOfServiceDelegate(nullptr);
128 }
129
130 TEST_F(ArcSupportHostTest, TermsOfServiceRejectOrCloseWindow) {
131 MockTermsOfServiceDelegate tos_delegate;
132 support_host()->SetTermsOfServiceDelegate(&tos_delegate);
133 support_host()->ShowTermsOfService();
134
135 EXPECT_CALL(tos_delegate, OnTermsRejected());
136 // Rejecting ToS and closing the window when ToS is showing is the same thing.
137 fake_arc_support()->Close();
138
139 support_host()->SetTermsOfServiceDelegate(nullptr);
140 }
141
142 TEST_F(ArcSupportHostTest, TermsOfServiceRetryOnError) {
143 MockTermsOfServiceDelegate tos_delegate;
144 support_host()->SetTermsOfServiceDelegate(&tos_delegate);
145 support_host()->ShowError(ArcSupportHost::Error::NETWORK_UNAVAILABLE_ERROR,
146 false /* should_show_send_feedback */);
147
148 EXPECT_CALL(tos_delegate, OnTermsRetry());
149 fake_arc_support()->ClickRetryButton();
150
151 support_host()->SetTermsOfServiceDelegate(nullptr);
152 }
153
154 TEST_F(ArcSupportHostTest, CloseWindowDuringManualAuth) {
155 // No TermsOfServiceDelegate since it is not ongoing.
156 MockErrorDelegate error_delegate;
157 support_host()->SetErrorDelegate(&error_delegate);
158 MockAuthDelegate auth_delegate;
159 support_host()->SetAuthDelegate(&auth_delegate);
160 support_host()->ShowArcLoading();
161
162 EXPECT_CALL(error_delegate, OnOptInAborted());
Luis Héctor Chávez 2017/05/12 15:41:31 Is there an easy way to express that you expect so
victorhsieh0 2017/05/12 18:31:55 .Times(0). But AuthDelegate does not have the rel
163 fake_arc_support()->Close();
164
165 support_host()->SetAuthDelegate(nullptr);
166 support_host()->SetErrorDelegate(nullptr);
167 }
168
169 TEST_F(ArcSupportHostTest, CloseWindowWithoutTermsOfServiceOrAuthOnging) {
170 // No TermsOfServiceDelegate since it is not ongoing.
171 MockErrorDelegate error_delegate;
172 support_host()->SetErrorDelegate(&error_delegate);
173 support_host()->ShowArcLoading();
174
175 EXPECT_CALL(error_delegate, OnOptInAborted());
176 fake_arc_support()->Close();
177
178 support_host()->SetErrorDelegate(nullptr);
179 }
180
181 TEST_F(ArcSupportHostTest, RetryOnGeneralError) {
182 // No TermsOfServiceDelegate and AuthDelegate since it is not ongoing.
183 MockErrorDelegate error_delegate;
184 support_host()->SetErrorDelegate(&error_delegate);
185 support_host()->ShowError(ArcSupportHost::Error::NETWORK_UNAVAILABLE_ERROR,
186 false /* should_show_send_feedback */);
187
188 EXPECT_CALL(error_delegate, OnRetryClicked());
189 fake_arc_support()->ClickRetryButton();
190
191 support_host()->SetErrorDelegate(nullptr);
192 }
193
194 TEST_F(ArcSupportHostTest, SendFeedbackOnError) {
195 MockErrorDelegate error_delegate;
196 support_host()->SetErrorDelegate(&error_delegate);
197 support_host()->ShowError(ArcSupportHost::Error::NETWORK_UNAVAILABLE_ERROR,
198 true /* should_show_send_feedback */);
199
200 EXPECT_CALL(error_delegate, OnSendFeedbackClicked());
201 fake_arc_support()->ClickSendFeedbackButton();
202
203 support_host()->SetErrorDelegate(nullptr);
204 }
205
206 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698