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

Side by Side Diff: chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotiator_unittest.cc

Issue 2682833003: Skip ARC initial screen when everything is set up by policy (Closed)
Patch Set: Rebase Created 3 years, 10 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
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 public:
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
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, 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());
119 141
120 // Make sure preference values are not yet updated. 142 // Make sure preference values are not yet updated.
121 EXPECT_FALSE( 143 EXPECT_FALSE(
122 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); 144 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled));
123 EXPECT_FALSE( 145 EXPECT_FALSE(
124 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); 146 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled));
125 147
126 // Click the "AGREE" button so that the callback should be invoked 148 // Click the "AGREE" button so that the callback should be invoked
127 // with |agreed| = true. 149 // with |agreed| = true.
128 fake_arc_support()->ClickAgreeButton(); 150 fake_arc_support()->ClickAgreeButton();
129 EXPECT_EQ(status, Status::ACCEPTED); 151 EXPECT_EQ(status, Status::ACCEPTED);
130 152
131 // Make sure preference values are now updated. 153 // Make sure preference values are now updated.
132 EXPECT_TRUE( 154 EXPECT_TRUE(
133 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled)); 155 profile()->GetPrefs()->GetBoolean(prefs::kArcBackupRestoreEnabled));
134 EXPECT_TRUE( 156 EXPECT_TRUE(
135 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled)); 157 profile()->GetPrefs()->GetBoolean(prefs::kArcLocationServiceEnabled));
136 } 158 }
137 159
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
138 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Cancel) { 195 TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Cancel) {
139 // Show Terms of service page. 196 // Show Terms of service page.
140 Status status = Status::PENDING; 197 Status status = Status::PENDING;
141 negotiator()->StartNegotiation(UpdateStatusCallback(&status)); 198 negotiator()->StartNegotiation(UpdateStatusCallback(&status));
142 199
143 // TERMS page should be shown. 200 // TERMS page should be shown.
144 EXPECT_EQ(status, Status::PENDING); 201 EXPECT_EQ(status, Status::PENDING);
145 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); 202 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS);
146 203
147 // Check the preference related checkbox. 204 // Check the preference related checkbox.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::ERROR); 241 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::ERROR);
185 242
186 // Click RETRY button on the page, then Terms of service page should be 243 // Click RETRY button on the page, then Terms of service page should be
187 // re-shown. 244 // re-shown.
188 fake_arc_support()->ClickRetryButton(); 245 fake_arc_support()->ClickRetryButton();
189 EXPECT_EQ(status, Status::PENDING); 246 EXPECT_EQ(status, Status::PENDING);
190 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS); 247 EXPECT_EQ(fake_arc_support()->ui_page(), ArcSupportHost::UIPage::TERMS);
191 } 248 }
192 249
193 } // namespace arc 250 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/optin/arc_optin_preference_handler_observer.h ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698