OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 <memory> | 5 #include <memory> |
6 #include <ostream> | 6 #include <ostream> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/values.h" | |
13 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 12 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
14 #include "chrome/browser/chromeos/arc/extensions/fake_arc_support.h" | 13 #include "chrome/browser/chromeos/arc/extensions/fake_arc_support.h" |
15 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" | 14 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" |
16 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
18 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
19 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
20 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
21 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
22 #include "components/sync_preferences/testing_pref_service_syncable.h" | |
23 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
25 | 23 |
26 namespace arc { | 24 namespace arc { |
27 | 25 |
28 class ArcTermsOfServiceDefaultNegotiatorTest : public testing::Test { | 26 class ArcTermsOfServiceDefaultNegotiatorTest : public testing::Test { |
29 public: | 27 public: |
30 ArcTermsOfServiceDefaultNegotiatorTest() = default; | 28 ArcTermsOfServiceDefaultNegotiatorTest() = default; |
31 ~ArcTermsOfServiceDefaultNegotiatorTest() override = default; | 29 ~ArcTermsOfServiceDefaultNegotiatorTest() override = default; |
32 | 30 |
33 void SetUp() override { | 31 void SetUp() override { |
34 user_manager_enabler_ = | 32 user_manager_enabler_ = |
35 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( | 33 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( |
36 new chromeos::FakeChromeUserManager()); | 34 new chromeos::FakeChromeUserManager()); |
37 | 35 |
38 profile_ = base::MakeUnique<TestingProfile>(); | 36 profile_ = base::MakeUnique<TestingProfile>(); |
| 37 profile_->GetPrefs()->SetBoolean(prefs::kArcBackupRestoreEnabled, false); |
| 38 profile_->GetPrefs()->SetBoolean(prefs::kArcLocationServiceEnabled, false); |
39 | 39 |
40 support_host_ = base::MakeUnique<ArcSupportHost>(profile_.get()); | 40 support_host_ = base::MakeUnique<ArcSupportHost>(profile_.get()); |
41 fake_arc_support_ = base::MakeUnique<FakeArcSupport>(support_host_.get()); | 41 fake_arc_support_ = base::MakeUnique<FakeArcSupport>(support_host_.get()); |
42 negotiator_ = base::MakeUnique<ArcTermsOfServiceDefaultNegotiator>( | 42 negotiator_ = base::MakeUnique<ArcTermsOfServiceDefaultNegotiator>( |
43 profile_->GetPrefs(), support_host()); | 43 profile_->GetPrefs(), support_host()); |
44 } | 44 } |
45 | 45 |
46 void TearDown() override { | 46 void TearDown() override { |
47 negotiator_.reset(); | 47 negotiator_.reset(); |
48 fake_arc_support_.reset(); | 48 fake_arc_support_.reset(); |
49 support_host_.reset(); | 49 support_host_.reset(); |
50 profile_.reset(); | 50 profile_.reset(); |
51 user_manager_enabler_.reset(); | 51 user_manager_enabler_.reset(); |
52 } | 52 } |
53 | 53 |
54 TestingProfile* profile() { return profile_.get(); } | 54 Profile* profile() { return profile_.get(); } |
55 ArcSupportHost* support_host() { return support_host_.get(); } | 55 ArcSupportHost* support_host() { return support_host_.get(); } |
56 FakeArcSupport* fake_arc_support() { return fake_arc_support_.get(); } | 56 FakeArcSupport* fake_arc_support() { return fake_arc_support_.get(); } |
57 ArcTermsOfServiceNegotiator* negotiator() { return negotiator_.get(); } | 57 ArcTermsOfServiceNegotiator* negotiator() { return negotiator_.get(); } |
58 | 58 |
59 private: | 59 private: |
60 // Fake as if the current testing thread is UI thread. | 60 // Fake as if the current testing thread is UI thread. |
61 content::TestBrowserThreadBundle bundle_; | 61 content::TestBrowserThreadBundle bundle_; |
62 | 62 |
63 std::unique_ptr<TestingProfile> profile_; | 63 std::unique_ptr<TestingProfile> profile_; |
64 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 64 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Accept) { | 106 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Accept) { |
107 // Show Terms of service page. | 107 // Show Terms of service page. |
108 Status status = Status::PENDING; | 108 Status status = Status::PENDING; |
109 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); | 109 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); |
110 | 110 |
111 // TERMS page should be shown. | 111 // TERMS page should be shown. |
112 EXPECT_EQ(status, Status::PENDING); | 112 EXPECT_EQ(status, Status::PENDING); |
113 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); | 113 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); |
114 | 114 |
115 // By default, the preference related checkboxes are checked, despite that | 115 // Check the preference related checkbox. |
116 // the preferences default to false. | 116 fake_arc_support()->set_metrics_mode(true); |
117 EXPECT_FALSE( | 117 fake_arc_support()->set_backup_and_restore_mode(true); |
118 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | 118 fake_arc_support()->set_location_service_mode(true); |
119 EXPECT_FALSE( | |
120 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | |
121 EXPECT_TRUE(fake_arc_support()->backup_and_restore_mode()); | |
122 EXPECT_TRUE(fake_arc_support()->location_service_mode()); | |
123 | |
124 // The preferences are assigned to the managed false value, and the | |
125 // corresponding checkboxes are unchecked. | |
126 profile()->GetTestingPrefService()->SetManagedPref( | |
127 prefs::kArcBackupRestoreEnabled, new base::Value(false)); | |
128 EXPECT_FALSE(fake_arc_support()->backup_and_restore_mode()); | |
129 profile()->GetTestingPrefService()->SetManagedPref( | |
130 prefs::kArcLocationServiceEnabled, new base::Value(false)); | |
131 EXPECT_FALSE(fake_arc_support()->location_service_mode()); | |
132 | |
133 // The managed preference values are removed, and the corresponding checkboxes | |
134 // are checked again. | |
135 profile()->GetTestingPrefService()->RemoveManagedPref( | |
136 prefs::kArcBackupRestoreEnabled); | |
137 EXPECT_TRUE(fake_arc_support()->backup_and_restore_mode()); | |
138 profile()->GetTestingPrefService()->RemoveManagedPref( | |
139 prefs::kArcLocationServiceEnabled); | |
140 EXPECT_TRUE(fake_arc_support()->location_service_mode()); | |
141 | 119 |
142 // Make sure preference values are not yet updated. | 120 // Make sure preference values are not yet updated. |
143 EXPECT_FALSE( | 121 EXPECT_FALSE( |
144 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | 122 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
145 EXPECT_FALSE( | 123 EXPECT_FALSE( |
146 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | 124 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); |
147 | 125 |
148 // Click the "AGREE" button so that the callback should be invoked | 126 // Click the "AGREE" button so that the callback should be invoked |
149 // with |agreed| = true. | 127 // with |agreed| = true. |
150 fake_arc_support()->ClickAgreeButton(); | 128 fake_arc_support()->ClickAgreeButton(); |
151 EXPECT_EQ(status, Status::ACCEPTED); | 129 EXPECT_EQ(status, Status::ACCEPTED); |
152 | 130 |
153 // Make sure preference values are now updated. | 131 // Make sure preference values are now updated. |
154 EXPECT_TRUE( | 132 EXPECT_TRUE( |
155 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | 133 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
156 EXPECT_TRUE( | 134 EXPECT_TRUE( |
157 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | 135 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); |
158 } | 136 } |
159 | 137 |
160 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, AcceptWithUnchecked) { | |
161 // Show Terms of service page. | |
162 Status status = Status::PENDING; | |
163 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); | |
164 | |
165 // TERMS page should be shown. | |
166 EXPECT_EQ(status, Status::PENDING); | |
167 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); | |
168 | |
169 // Override the preferences from the default values to true. | |
170 profile()->GetPrefs()->SetBoolean(prefs::kArcBackupRestoreEnabled, true); | |
171 profile()->GetPrefs()->SetBoolean(prefs::kArcLocationServiceEnabled, true); | |
172 | |
173 // Uncheck the preference related checkboxes. | |
174 fake_arc_support()->set_backup_and_restore_mode(false); | |
175 fake_arc_support()->set_location_service_mode(false); | |
176 | |
177 // Make sure preference values are not yet updated. | |
178 EXPECT_TRUE( | |
179 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | |
180 EXPECT_TRUE( | |
181 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | |
182 | |
183 // Click the "AGREE" button so that the callback should be invoked | |
184 // with |agreed| = true. | |
185 fake_arc_support()->ClickAgreeButton(); | |
186 EXPECT_EQ(status, Status::ACCEPTED); | |
187 | |
188 // Make sure preference values are now updated. | |
189 EXPECT_FALSE( | |
190 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | |
191 EXPECT_FALSE( | |
192 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | |
193 } | |
194 | |
195 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Cancel) { | 138 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Cancel) { |
196 // Show Terms of service page. | 139 // Show Terms of service page. |
197 Status status = Status::PENDING; | 140 Status status = Status::PENDING; |
198 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); | 141 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); |
199 | 142 |
200 // TERMS page should be shown. | 143 // TERMS page should be shown. |
201 EXPECT_EQ(status, Status::PENDING); | 144 EXPECT_EQ(status, Status::PENDING); |
202 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); | 145 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); |
203 | 146 |
204 // Check the preference related checkbox. | 147 // Check the preference related checkbox. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::ERROR); | 184 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::ERROR); |
242 | 185 |
243 // Click RETRY button on the page, then Terms of service page should be | 186 // Click RETRY button on the page, then Terms of service page should be |
244 // re-shown. | 187 // re-shown. |
245 fake_arc_support()->ClickRetryButton(); | 188 fake_arc_support()->ClickRetryButton(); |
246 EXPECT_EQ(status, Status::PENDING); | 189 EXPECT_EQ(status, Status::PENDING); |
247 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); | 190 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); |
248 } | 191 } |
249 | 192 |
250 } // namespace arc | 193 } // namespace arc |
OLD | NEW |