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

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_policy_browsertest.cc

Issue 2714493002: Load DeviceLocalAccount policy and DeviceSettings immediately on restore after Chrome crash. (Closed)
Patch Set: wrap Validator in unique_ptr Created 3 years, 9 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/wallpaper/wallpaper_controller.h" 11 #include "ash/common/wallpaper/wallpaper_controller.h"
12 #include "ash/common/wallpaper/wallpaper_controller_observer.h" 12 #include "ash/common/wallpaper/wallpaper_controller_observer.h"
13 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/json/json_writer.h" 18 #include "base/json/json_writer.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/numerics/safe_conversions.h" 21 #include "base/numerics/safe_conversions.h"
22 #include "base/path_service.h" 22 #include "base/path_service.h"
23 #include "base/run_loop.h" 23 #include "base/run_loop.h"
24 #include "chrome/browser/chromeos/login/login_manager_test.h" 24 #include "chrome/browser/chromeos/login/login_manager_test.h"
25 #include "chrome/browser/chromeos/login/startup_utils.h" 25 #include "chrome/browser/chromeos/login/startup_utils.h"
26 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 26 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
27 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 27 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
28 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 29 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
29 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h" 30 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u til.h"
31 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
30 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" 32 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
31 #include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h" 33 #include "chrome/browser/chromeos/policy/user_policy_manager_factory_chromeos.h"
32 #include "chrome/browser/chromeos/profiles/profile_helper.h" 34 #include "chrome/browser/chromeos/profiles/profile_helper.h"
33 #include "chrome/browser/chromeos/settings/stub_install_attributes.h" 35 #include "chrome/browser/chromeos/settings/stub_install_attributes.h"
34 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 37 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
36 #include "chrome/common/chrome_paths.h" 38 #include "chrome/common/chrome_paths.h"
37 #include "chromeos/chromeos_paths.h" 39 #include "chromeos/chromeos_paths.h"
38 #include "chromeos/chromeos_switches.h" 40 #include "chromeos/chromeos_switches.h"
39 #include "chromeos/cryptohome/system_salt_getter.h" 41 #include "chromeos/cryptohome/system_salt_getter.h"
40 #include "chromeos/dbus/cryptohome_client.h" 42 #include "chromeos/dbus/cryptohome_client.h"
41 #include "chromeos/dbus/dbus_thread_manager.h" 43 #include "chromeos/dbus/dbus_thread_manager.h"
42 #include "chromeos/dbus/fake_session_manager_client.h" 44 #include "chromeos/dbus/fake_session_manager_client.h"
43 #include "chromeos/dbus/session_manager_client.h" 45 #include "chromeos/dbus/session_manager_client.h"
46 #include "components/ownership/mock_owner_key_util.h"
44 #include "components/policy/core/common/cloud/cloud_policy_core.h" 47 #include "components/policy/core/common/cloud/cloud_policy_core.h"
45 #include "components/policy/core/common/cloud/cloud_policy_store.h" 48 #include "components/policy/core/common/cloud/cloud_policy_store.h"
46 #include "components/policy/core/common/cloud/cloud_policy_validator.h" 49 #include "components/policy/core/common/cloud/cloud_policy_validator.h"
47 #include "components/policy/core/common/cloud/policy_builder.h" 50 #include "components/policy/core/common/cloud/policy_builder.h"
48 #include "components/policy/proto/cloud_policy.pb.h" 51 #include "components/policy/proto/cloud_policy.pb.h"
49 #include "components/user_manager/user.h" 52 #include "components/user_manager/user.h"
50 #include "components/user_manager/user_manager.h" 53 #include "components/user_manager/user_manager.h"
51 #include "content/public/test/browser_test_utils.h" 54 #include "content/public/test/browser_test_utils.h"
52 #include "crypto/rsa_private_key.h" 55 #include "crypto/rsa_private_key.h"
53 #include "net/test/embedded_test_server/embedded_test_server.h" 56 #include "net/test/embedded_test_server/embedded_test_server.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 142 }
140 143
141 } // namespace 144 } // namespace
142 145
143 class WallpaperManagerPolicyTest : public LoginManagerTest, 146 class WallpaperManagerPolicyTest : public LoginManagerTest,
144 public ash::WallpaperControllerObserver { 147 public ash::WallpaperControllerObserver {
145 protected: 148 protected:
146 WallpaperManagerPolicyTest() 149 WallpaperManagerPolicyTest()
147 : LoginManagerTest(true), 150 : LoginManagerTest(true),
148 wallpaper_change_count_(0), 151 wallpaper_change_count_(0),
152 owner_key_util_(new ownership::MockOwnerKeyUtil()),
149 fake_session_manager_client_(new FakeSessionManagerClient) { 153 fake_session_manager_client_(new FakeSessionManagerClient) {
150 testUsers_.push_back( 154 testUsers_.push_back(
151 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser1)); 155 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser1));
152 testUsers_.push_back( 156 testUsers_.push_back(
153 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser2)); 157 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser2));
154 } 158 }
155 159
156 std::unique_ptr<policy::UserPolicyBuilder> GetUserPolicyBuilder( 160 std::unique_ptr<policy::UserPolicyBuilder> GetUserPolicyBuilder(
157 const AccountId& account_id) { 161 const AccountId& account_id) {
158 std::unique_ptr<policy::UserPolicyBuilder> user_policy_builder( 162 std::unique_ptr<policy::UserPolicyBuilder> user_policy_builder(
(...skipping 12 matching lines...) Expand all
171 EXPECT_TRUE(base::CreateDirectory(user_key_file.DirName())); 175 EXPECT_TRUE(base::CreateDirectory(user_key_file.DirName()));
172 EXPECT_EQ(base::WriteFile(user_key_file, user_key_bits.data(), 176 EXPECT_EQ(base::WriteFile(user_key_file, user_key_bits.data(),
173 user_key_bits.length()), 177 user_key_bits.length()),
174 base::checked_cast<int>(user_key_bits.length())); 178 base::checked_cast<int>(user_key_bits.length()));
175 user_policy_builder->policy_data().set_username(account_id.GetUserEmail()); 179 user_policy_builder->policy_data().set_username(account_id.GetUserEmail());
176 return user_policy_builder; 180 return user_policy_builder;
177 } 181 }
178 182
179 // LoginManagerTest: 183 // LoginManagerTest:
180 void SetUpInProcessBrowserTestFixture() override { 184 void SetUpInProcessBrowserTestFixture() override {
185 device_policy_.Build();
186 OwnerSettingsServiceChromeOSFactory::GetInstance()
187 ->SetOwnerKeyUtilForTesting(owner_key_util_);
188 owner_key_util_->SetPublicKeyFromPrivateKey(
189 *device_policy_.GetSigningKey());
190 fake_session_manager_client_->set_device_policy(device_policy_.GetBlob());
191 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
192 std::unique_ptr<SessionManagerClient>(fake_session_manager_client_));
193
181 // Set up fake install attributes. 194 // Set up fake install attributes.
182 std::unique_ptr<chromeos::StubInstallAttributes> attributes = 195 std::unique_ptr<chromeos::StubInstallAttributes> attributes =
183 base::MakeUnique<chromeos::StubInstallAttributes>(); 196 base::MakeUnique<chromeos::StubInstallAttributes>();
184 attributes->SetEnterprise("fake-domain", "fake-id"); 197 attributes->SetEnterprise("fake-domain", "fake-id");
185 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( 198 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
186 attributes.release()); 199 attributes.release());
187 200
188 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
189 std::unique_ptr<SessionManagerClient>(fake_session_manager_client_));
190
191 LoginManagerTest::SetUpInProcessBrowserTestFixture(); 201 LoginManagerTest::SetUpInProcessBrowserTestFixture();
192 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); 202 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_));
193 } 203 }
194 204
195 void SetUpCommandLine(base::CommandLine* command_line) override { 205 void SetUpCommandLine(base::CommandLine* command_line) override {
196 // Set the same switches as LoginManagerTest, except that kMultiProfiles is 206 // Set the same switches as LoginManagerTest, except that kMultiProfiles is
197 // only set when GetParam() is true and except that kLoginProfile is set 207 // only set when GetParam() is true and except that kLoginProfile is set
198 // when GetParam() is false. The latter seems to be required for the sane 208 // when GetParam() is false. The latter seems to be required for the sane
199 // start-up of user profiles. 209 // start-up of user profiles.
200 command_line->AppendSwitch(switches::kLoginManager); 210 command_line->AppendSwitch(switches::kLoginManager);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 void GetUserWallpaperInfo(int user_number, 293 void GetUserWallpaperInfo(int user_number,
284 wallpaper::WallpaperInfo* wallpaper_info) { 294 wallpaper::WallpaperInfo* wallpaper_info) {
285 WallpaperManager::Get()->GetUserWallpaperInfo(testUsers_[user_number], 295 WallpaperManager::Get()->GetUserWallpaperInfo(testUsers_[user_number],
286 wallpaper_info); 296 wallpaper_info);
287 } 297 }
288 298
289 base::FilePath test_data_dir_; 299 base::FilePath test_data_dir_;
290 std::unique_ptr<base::RunLoop> run_loop_; 300 std::unique_ptr<base::RunLoop> run_loop_;
291 int wallpaper_change_count_; 301 int wallpaper_change_count_;
292 std::unique_ptr<policy::UserPolicyBuilder> user_policy_builders_[2]; 302 std::unique_ptr<policy::UserPolicyBuilder> user_policy_builders_[2];
303 policy::DevicePolicyBuilder device_policy_;
304 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_;
293 FakeSessionManagerClient* fake_session_manager_client_; 305 FakeSessionManagerClient* fake_session_manager_client_;
294 std::vector<AccountId> testUsers_; 306 std::vector<AccountId> testUsers_;
295 307
296 private: 308 private:
297 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerPolicyTest); 309 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerPolicyTest);
298 }; 310 };
299 311
300 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_SetResetClear) { 312 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_SetResetClear) {
301 RegisterUser(testUsers_[0].GetUserEmail()); 313 RegisterUser(testUsers_[0].GetUserEmail());
302 RegisterUser(testUsers_[1].GetUserEmail()); 314 RegisterUser(testUsers_[1].GetUserEmail());
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 437
426 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) { 438 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) {
427 LoginUser(testUsers_[0].GetUserEmail()); 439 LoginUser(testUsers_[0].GetUserEmail());
428 440
429 // Wait until wallpaper has been loaded. 441 // Wait until wallpaper has been loaded.
430 RunUntilWallpaperChangeCount(1); 442 RunUntilWallpaperChangeCount(1);
431 ASSERT_EQ(kRedImageColor, GetAverageWallpaperColor()); 443 ASSERT_EQ(kRedImageColor, GetAverageWallpaperColor());
432 } 444 }
433 445
434 } // namespace chromeos 446 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698