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" | |
12 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 13 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
13 #include "chrome/browser/chromeos/arc/extensions/fake_arc_support.h" | 14 #include "chrome/browser/chromeos/arc/extensions/fake_arc_support.h" |
14 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia tor.h" | 15 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia tor.h" |
15 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
20 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
22 #include "components/sync_preferences/testing_pref_service_syncable.h" | |
21 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
23 | 25 |
24 namespace arc { | 26 namespace arc { |
25 | 27 |
26 class ArcTermsOfServiceDefaultNegotiatorTest : public testing::Test { | 28 class ArcTermsOfServiceDefaultNegotiatorTest : public testing::Test { |
27 public: | 29 protected: |
hidehiko
2017/02/14 11:51:36
nit: could you keep public?
emaxx
2017/02/15 03:40:59
Done. (Although I thought it's more common in the
| |
28 ArcTermsOfServiceDefaultNegotiatorTest() = default; | 30 ArcTermsOfServiceDefaultNegotiatorTest() = default; |
29 ~ArcTermsOfServiceDefaultNegotiatorTest() override = default; | 31 ~ArcTermsOfServiceDefaultNegotiatorTest() override = default; |
30 | 32 |
31 void SetUp() override { | 33 void SetUp() override { |
32 user_manager_enabler_ = | 34 user_manager_enabler_ = |
33 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( | 35 base::MakeUnique<chromeos::ScopedUserManagerEnabler>( |
34 new chromeos::FakeChromeUserManager()); | 36 new chromeos::FakeChromeUserManager()); |
35 | 37 |
36 profile_ = base::MakeUnique<TestingProfile>(); | 38 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 Profile* profile() { return profile_.get(); } | 54 TestingProfile* 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 // Check the preference related checkbox. | 115 // By default, the preference related checkboxes are checked, despite that |
116 fake_arc_support()->set_metrics_mode(true); | 116 // the preferences default to false. |
117 fake_arc_support()->set_backup_and_restore_mode(true); | 117 EXPECT_FALSE( |
118 fake_arc_support()->set_location_service_mode(true); | 118 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
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, | |
128 base::MakeUnique<base::Value>(false).release()); | |
hidehiko
2017/02/14 11:51:36
nit: new base::Value(false)
BTW, according to the
emaxx
2017/02/15 03:40:59
Done.
Created crbug.com/692121 to track that refac
| |
129 EXPECT_FALSE(fake_arc_support()->backup_and_restore_mode()); | |
130 profile()->GetTestingPrefService()->SetManagedPref( | |
131 prefs::kArcLocationServiceEnabled, | |
132 base::MakeUnique<base::Value>(false).release()); | |
133 EXPECT_FALSE(fake_arc_support()->location_service_mode()); | |
134 | |
135 // The managed preference values are removed, and the corresponding checkboxes | |
136 // are checked again. | |
137 profile()->GetTestingPrefService()->RemoveManagedPref( | |
138 prefs::kArcBackupRestoreEnabled); | |
139 EXPECT_TRUE(fake_arc_support()->backup_and_restore_mode()); | |
140 profile()->GetTestingPrefService()->RemoveManagedPref( | |
141 prefs::kArcLocationServiceEnabled); | |
142 EXPECT_TRUE(fake_arc_support()->location_service_mode()); | |
119 | 143 |
120 // Make sure preference values are not yet updated. | 144 // Make sure preference values are not yet updated. |
121 EXPECT_FALSE( | 145 EXPECT_FALSE( |
122 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | 146 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
123 EXPECT_FALSE( | 147 EXPECT_FALSE( |
124 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | 148 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); |
125 | 149 |
126 // Click the "AGREE" button so that the callback should be invoked | 150 // Click the "AGREE" button so that the callback should be invoked |
127 // with |agreed| = true. | 151 // with |agreed| = true. |
128 fake_arc_support()->ClickAgreeButton(); | 152 fake_arc_support()->ClickAgreeButton(); |
129 EXPECT_EQ(status, Status::ACCEPTED); | 153 EXPECT_EQ(status, Status::ACCEPTED); |
130 | 154 |
131 // Make sure preference values are now updated. | 155 // Make sure preference values are now updated. |
132 EXPECT_TRUE( | 156 EXPECT_TRUE( |
133 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | 157 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); |
134 EXPECT_TRUE( | 158 EXPECT_TRUE( |
135 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | 159 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); |
136 } | 160 } |
137 | 161 |
162 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, AcceptWithUnchecked) { | |
163 // Show Terms of service page. | |
164 Status status = Status::PENDING; | |
165 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); | |
166 | |
167 // TERMS page should be shown. | |
168 EXPECT_EQ(status, Status::PENDING); | |
169 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); | |
170 | |
171 // Override the preferences from the default values to true. | |
172 profile()->GetPrefs()->SetBoolean(prefs::kArcBackupRestoreEnabled, true); | |
173 profile()->GetPrefs()->SetBoolean(prefs::kArcLocationServiceEnabled, true); | |
174 | |
175 // Uncheck the preference related checkboxes. | |
176 fake_arc_support()->set_backup_and_restore_mode(false); | |
177 fake_arc_support()->set_location_service_mode(false); | |
178 | |
179 // Make sure preference values are not yet updated. | |
180 EXPECT_TRUE( | |
181 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | |
182 EXPECT_TRUE( | |
183 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | |
184 | |
185 // Click the "AGREE" button so that the callback should be invoked | |
186 // with |agreed| = true. | |
187 fake_arc_support()->ClickAgreeButton(); | |
188 EXPECT_EQ(status, Status::ACCEPTED); | |
189 | |
190 // Make sure preference values are now updated. | |
191 EXPECT_FALSE( | |
192 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); | |
193 EXPECT_FALSE( | |
194 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); | |
195 } | |
196 | |
138 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Cancel) { | 197 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Cancel) { |
139 // Show Terms of service page. | 198 // Show Terms of service page. |
140 Status status = Status::PENDING; | 199 Status status = Status::PENDING; |
141 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); | 200 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); |
142 | 201 |
143 // TERMS page should be shown. | 202 // TERMS page should be shown. |
144 EXPECT_EQ(status, Status::PENDING); | 203 EXPECT_EQ(status, Status::PENDING); |
145 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); | 204 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); |
146 | 205 |
147 // Check the preference related checkbox. | 206 // Check the preference related checkbox. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::ERROR); | 243 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::ERROR); |
185 | 244 |
186 // Click RETRY button on the page, then Terms of service page should be | 245 // Click RETRY button on the page, then Terms of service page should be |
187 // re-shown. | 246 // re-shown. |
188 fake_arc_support()->ClickRetryButton(); | 247 fake_arc_support()->ClickRetryButton(); |
189 EXPECT_EQ(status, Status::PENDING); | 248 EXPECT_EQ(status, Status::PENDING); |
190 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); | 249 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); |
191 } | 250 } |
192 | 251 |
193 } // namespace arc | 252 } // namespace arc |
OLD | NEW |