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

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

Issue 2290473004: Rename ash desktop_background to wallpaper. (Closed)
Patch Set: Address comments. Created 4 years, 3 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
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/desktop_background/desktop_background_controller.h"
12 #include "ash/desktop_background/desktop_background_controller_observer.h"
13 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wallpaper/wallpaper_controller.h"
13 #include "ash/wallpaper/wallpaper_controller_observer.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/path_service.h" 20 #include "base/path_service.h"
21 #include "base/run_loop.h" 21 #include "base/run_loop.h"
22 #include "chrome/browser/chromeos/login/login_manager_test.h" 22 #include "chrome/browser/chromeos/login/login_manager_test.h"
23 #include "chrome/browser/chromeos/login/startup_utils.h" 23 #include "chrome/browser/chromeos/login/startup_utils.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 } 106 }
107 bitmap.unlockPixels(); 107 bitmap.unlockPixels();
108 uint64_t pixel_number = bitmap.width() * bitmap.height(); 108 uint64_t pixel_number = bitmap.width() * bitmap.height();
109 return SkColorSetARGB((a + pixel_number / 2) / pixel_number, 109 return SkColorSetARGB((a + pixel_number / 2) / pixel_number,
110 (r + pixel_number / 2) / pixel_number, 110 (r + pixel_number / 2) / pixel_number,
111 (g + pixel_number / 2) / pixel_number, 111 (g + pixel_number / 2) / pixel_number,
112 (b + pixel_number / 2) / pixel_number); 112 (b + pixel_number / 2) / pixel_number);
113 } 113 }
114 114
115 // Obtain background image and return its average ARGB color. 115 // Obtain wallpaper image and return its average ARGB color.
116 SkColor GetAverageBackgroundColor() { 116 SkColor GetAverageWallpaperColor() {
117 const gfx::ImageSkia image = 117 const gfx::ImageSkia image =
118 ash::Shell::GetInstance()->desktop_background_controller()-> 118 ash::Shell::GetInstance()->wallpaper_controller()->GetWallpaper();
119 GetWallpaper();
120 119
121 const gfx::ImageSkiaRep& representation = image.GetRepresentation(1.); 120 const gfx::ImageSkiaRep& representation = image.GetRepresentation(1.);
122 if (representation.is_null()) { 121 if (representation.is_null()) {
123 ADD_FAILURE() << "No image representation."; 122 ADD_FAILURE() << "No image representation.";
124 return SkColorSetARGB(0, 0, 0, 0); 123 return SkColorSetARGB(0, 0, 0, 0);
125 } 124 }
126 125
127 const SkBitmap& bitmap = representation.sk_bitmap(); 126 const SkBitmap& bitmap = representation.sk_bitmap();
128 return ComputeAverageColor(bitmap); 127 return ComputeAverageColor(bitmap);
129 } 128 }
130 129
131 // Initialize system salt to calculate wallpaper file names. 130 // Initialize system salt to calculate wallpaper file names.
132 void SetSystemSalt() { 131 void SetSystemSalt() {
133 chromeos::SystemSaltGetter::Get()->SetRawSaltForTesting( 132 chromeos::SystemSaltGetter::Get()->SetRawSaltForTesting(
134 chromeos::SystemSaltGetter::RawSalt({1, 2, 3, 4, 5, 6, 7, 8})); 133 chromeos::SystemSaltGetter::RawSalt({1, 2, 3, 4, 5, 6, 7, 8}));
135 } 134 }
136 135
137 } // namespace 136 } // namespace
138 137
139 class WallpaperManagerPolicyTest 138 class WallpaperManagerPolicyTest : public LoginManagerTest,
140 : public LoginManagerTest, 139 public ash::WallpaperControllerObserver {
141 public ash::DesktopBackgroundControllerObserver {
142 protected: 140 protected:
143 WallpaperManagerPolicyTest() 141 WallpaperManagerPolicyTest()
144 : LoginManagerTest(true), 142 : LoginManagerTest(true),
145 wallpaper_change_count_(0), 143 wallpaper_change_count_(0),
146 fake_session_manager_client_(new FakeSessionManagerClient) { 144 fake_session_manager_client_(new FakeSessionManagerClient) {
147 testUsers_.push_back( 145 testUsers_.push_back(
148 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser1)); 146 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser1));
149 testUsers_.push_back( 147 testUsers_.push_back(
150 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser2)); 148 AccountId::FromUserEmail(LoginManagerTest::kEnterpriseUser2));
151 } 149 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 192
195 // Allow policy fetches to fail - these tests instead invoke InjectPolicy() 193 // Allow policy fetches to fail - these tests instead invoke InjectPolicy()
196 // to directly inject and modify policy dynamically. 194 // to directly inject and modify policy dynamically.
197 command_line->AppendSwitch(switches::kAllowFailedPolicyFetchForTest); 195 command_line->AppendSwitch(switches::kAllowFailedPolicyFetchForTest);
198 196
199 LoginManagerTest::SetUpCommandLine(command_line); 197 LoginManagerTest::SetUpCommandLine(command_line);
200 } 198 }
201 199
202 void SetUpOnMainThread() override { 200 void SetUpOnMainThread() override {
203 LoginManagerTest::SetUpOnMainThread(); 201 LoginManagerTest::SetUpOnMainThread();
204 ash::Shell::GetInstance()-> 202 ash::Shell::GetInstance()->wallpaper_controller()->AddObserver(this);
205 desktop_background_controller()->AddObserver(this);
206 203
207 // Set up policy signing. 204 // Set up policy signing.
208 user_policy_builders_[0] = GetUserPolicyBuilder(testUsers_[0]); 205 user_policy_builders_[0] = GetUserPolicyBuilder(testUsers_[0]);
209 user_policy_builders_[1] = GetUserPolicyBuilder(testUsers_[1]); 206 user_policy_builders_[1] = GetUserPolicyBuilder(testUsers_[1]);
210 } 207 }
211 208
212 void TearDownOnMainThread() override { 209 void TearDownOnMainThread() override {
213 ash::Shell::GetInstance()-> 210 ash::Shell::GetInstance()->wallpaper_controller()->RemoveObserver(this);
214 desktop_background_controller()->RemoveObserver(this);
215 LoginManagerTest::TearDownOnMainThread(); 211 LoginManagerTest::TearDownOnMainThread();
216 } 212 }
217 213
218 // ash::DesktopBackgroundControllerObserver: 214 // ash::WallpaperControllerObserver:
219 void OnWallpaperDataChanged() override { 215 void OnWallpaperDataChanged() override {
220 ++wallpaper_change_count_; 216 ++wallpaper_change_count_;
221 if (run_loop_) 217 if (run_loop_)
222 run_loop_->Quit(); 218 run_loop_->Quit();
223 } 219 }
224 220
225 // Runs the loop until wallpaper has changed at least |count| times in total. 221 // Runs the loop until wallpaper has changed at least |count| times in total.
226 void RunUntilWallpaperChangeCount(int count) { 222 void RunUntilWallpaperChangeCount(int count) {
227 while (wallpaper_change_count_ < count) { 223 while (wallpaper_change_count_ < count) {
228 run_loop_.reset(new base::RunLoop); 224 run_loop_.reset(new base::RunLoop);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // reverts to default. 299 // reverts to default.
304 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, SetResetClear) { 300 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, SetResetClear) {
305 SetSystemSalt(); 301 SetSystemSalt();
306 wallpaper::WallpaperInfo info; 302 wallpaper::WallpaperInfo info;
307 LoginUser(testUsers_[0].GetUserEmail()); 303 LoginUser(testUsers_[0].GetUserEmail());
308 base::RunLoop().RunUntilIdle(); 304 base::RunLoop().RunUntilIdle();
309 305
310 // First user: Wait until default wallpaper has been loaded (happens 306 // First user: Wait until default wallpaper has been loaded (happens
311 // automatically) and store color to recognize it later. 307 // automatically) and store color to recognize it later.
312 RunUntilWallpaperChangeCount(1); 308 RunUntilWallpaperChangeCount(1);
313 const SkColor original_background_color = GetAverageBackgroundColor(); 309 const SkColor original_wallpaper_color = GetAverageWallpaperColor();
314 310
315 // Second user: Set wallpaper policy to blue image. This should not result in 311 // Second user: Set wallpaper policy to blue image. This should not result in
316 // a wallpaper change, which is checked at the very end of this test. 312 // a wallpaper change, which is checked at the very end of this test.
317 InjectPolicy(1, kBlueImageFileName); 313 InjectPolicy(1, kBlueImageFileName);
318 314
319 // First user: Set wallpaper policy to red image and verify average color. 315 // First user: Set wallpaper policy to red image and verify average color.
320 InjectPolicy(0, kRedImageFileName); 316 InjectPolicy(0, kRedImageFileName);
321 RunUntilWallpaperChangeCount(2); 317 RunUntilWallpaperChangeCount(2);
322 GetUserWallpaperInfo(0, &info); 318 GetUserWallpaperInfo(0, &info);
323 ASSERT_EQ(user_manager::User::POLICY, info.type); 319 ASSERT_EQ(user_manager::User::POLICY, info.type);
324 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); 320 ASSERT_EQ(kRedImageColor, GetAverageWallpaperColor());
325 321
326 // First user: Set wallpaper policy to green image and verify average color. 322 // First user: Set wallpaper policy to green image and verify average color.
327 InjectPolicy(0, kGreenImageFileName); 323 InjectPolicy(0, kGreenImageFileName);
328 RunUntilWallpaperChangeCount(3); 324 RunUntilWallpaperChangeCount(3);
329 GetUserWallpaperInfo(0, &info); 325 GetUserWallpaperInfo(0, &info);
330 ASSERT_EQ(user_manager::User::POLICY, info.type); 326 ASSERT_EQ(user_manager::User::POLICY, info.type);
331 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); 327 ASSERT_EQ(kGreenImageColor, GetAverageWallpaperColor());
332 328
333 // First user: Clear wallpaper policy and verify that the default wallpaper is 329 // First user: Clear wallpaper policy and verify that the default wallpaper is
334 // set again. 330 // set again.
335 InjectPolicy(0, ""); 331 InjectPolicy(0, "");
336 RunUntilWallpaperChangeCount(4); 332 RunUntilWallpaperChangeCount(4);
337 GetUserWallpaperInfo(0, &info); 333 GetUserWallpaperInfo(0, &info);
338 ASSERT_EQ(user_manager::User::DEFAULT, info.type); 334 ASSERT_EQ(user_manager::User::DEFAULT, info.type);
339 ASSERT_EQ(original_background_color, GetAverageBackgroundColor()); 335 ASSERT_EQ(original_wallpaper_color, GetAverageWallpaperColor());
340 336
341 // Check wallpaper change count to ensure that setting the second user's 337 // Check wallpaper change count to ensure that setting the second user's
342 // wallpaper didn't have any effect. 338 // wallpaper didn't have any effect.
343 ASSERT_EQ(4, wallpaper_change_count_); 339 ASSERT_EQ(4, wallpaper_change_count_);
344 } 340 }
345 341
346 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, 342 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest,
347 DISABLED_PRE_PRE_PRE_WallpaperOnLoginScreen) { 343 DISABLED_PRE_PRE_PRE_WallpaperOnLoginScreen) {
348 RegisterUser(testUsers_[0].GetUserEmail()); 344 RegisterUser(testUsers_[0].GetUserEmail());
349 RegisterUser(testUsers_[1].GetUserEmail()); 345 RegisterUser(testUsers_[1].GetUserEmail());
350 StartupUtils::MarkOobeCompleted(); 346 StartupUtils::MarkOobeCompleted();
351 } 347 }
352 348
353 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, 349 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest,
354 DISABLED_PRE_PRE_WallpaperOnLoginScreen) { 350 DISABLED_PRE_PRE_WallpaperOnLoginScreen) {
355 LoginUser(testUsers_[0].GetUserEmail()); 351 LoginUser(testUsers_[0].GetUserEmail());
356 352
357 // Wait until default wallpaper has been loaded. 353 // Wait until default wallpaper has been loaded.
358 RunUntilWallpaperChangeCount(1); 354 RunUntilWallpaperChangeCount(1);
359 355
360 // Set wallpaper policy to red image. 356 // Set wallpaper policy to red image.
361 InjectPolicy(0, kRedImageFileName); 357 InjectPolicy(0, kRedImageFileName);
362 358
363 // Run until wallpaper has changed. 359 // Run until wallpaper has changed.
364 RunUntilWallpaperChangeCount(2); 360 RunUntilWallpaperChangeCount(2);
365 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); 361 ASSERT_EQ(kRedImageColor, GetAverageWallpaperColor());
366 } 362 }
367 363
368 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, 364 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest,
369 DISABLED_PRE_WallpaperOnLoginScreen) { 365 DISABLED_PRE_WallpaperOnLoginScreen) {
370 LoginUser(testUsers_[1].GetUserEmail()); 366 LoginUser(testUsers_[1].GetUserEmail());
371 367
372 // Wait until default wallpaper has been loaded. 368 // Wait until default wallpaper has been loaded.
373 RunUntilWallpaperChangeCount(1); 369 RunUntilWallpaperChangeCount(1);
374 370
375 // Set wallpaper policy to green image. 371 // Set wallpaper policy to green image.
376 InjectPolicy(1, kGreenImageFileName); 372 InjectPolicy(1, kGreenImageFileName);
377 373
378 // Run until wallpaper has changed. 374 // Run until wallpaper has changed.
379 RunUntilWallpaperChangeCount(2); 375 RunUntilWallpaperChangeCount(2);
380 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); 376 ASSERT_EQ(kGreenImageColor, GetAverageWallpaperColor());
381 } 377 }
382 378
383 // Disabled due to flakiness: http://crbug.com/385648. 379 // Disabled due to flakiness: http://crbug.com/385648.
384 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, 380 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest,
385 DISABLED_WallpaperOnLoginScreen) { 381 DISABLED_WallpaperOnLoginScreen) {
386 // Wait for active pod's wallpaper to be loaded. 382 // Wait for active pod's wallpaper to be loaded.
387 RunUntilWallpaperChangeCount(1); 383 RunUntilWallpaperChangeCount(1);
388 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); 384 ASSERT_EQ(kGreenImageColor, GetAverageWallpaperColor());
389 385
390 // Select the second pod (belonging to user 1). 386 // Select the second pod (belonging to user 1).
391 ASSERT_TRUE(content::ExecuteScript( 387 ASSERT_TRUE(content::ExecuteScript(
392 LoginDisplayHost::default_host()->GetOobeUI()->web_ui()->GetWebContents(), 388 LoginDisplayHost::default_host()->GetOobeUI()->web_ui()->GetWebContents(),
393 "document.getElementsByClassName('pod')[1].focus();")); 389 "document.getElementsByClassName('pod')[1].focus();"));
394 RunUntilWallpaperChangeCount(2); 390 RunUntilWallpaperChangeCount(2);
395 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); 391 ASSERT_EQ(kRedImageColor, GetAverageWallpaperColor());
396 } 392 }
397 393
398 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PRE_PersistOverLogout) { 394 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PRE_PersistOverLogout) {
399 SetSystemSalt(); 395 SetSystemSalt();
400 RegisterUser(testUsers_[0].GetUserEmail()); 396 RegisterUser(testUsers_[0].GetUserEmail());
401 StartupUtils::MarkOobeCompleted(); 397 StartupUtils::MarkOobeCompleted();
402 } 398 }
403 399
404 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PersistOverLogout) { 400 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PRE_PersistOverLogout) {
405 SetSystemSalt(); 401 SetSystemSalt();
406 LoginUser(testUsers_[0].GetUserEmail()); 402 LoginUser(testUsers_[0].GetUserEmail());
407 403
408 // Wait until default wallpaper has been loaded. 404 // Wait until default wallpaper has been loaded.
409 RunUntilWallpaperChangeCount(1); 405 RunUntilWallpaperChangeCount(1);
410 406
411 // Set wallpaper policy to red image. 407 // Set wallpaper policy to red image.
412 InjectPolicy(0, kRedImageFileName); 408 InjectPolicy(0, kRedImageFileName);
413 409
414 // Run until wallpaper has changed. 410 // Run until wallpaper has changed.
415 RunUntilWallpaperChangeCount(2); 411 RunUntilWallpaperChangeCount(2);
416 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); 412 ASSERT_EQ(kRedImageColor, GetAverageWallpaperColor());
417 } 413 }
418 414
419 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) { 415 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) {
420 LoginUser(testUsers_[0].GetUserEmail()); 416 LoginUser(testUsers_[0].GetUserEmail());
421 417
422 // Wait until wallpaper has been loaded. 418 // Wait until wallpaper has been loaded.
423 RunUntilWallpaperChangeCount(1); 419 RunUntilWallpaperChangeCount(1);
424 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); 420 ASSERT_EQ(kRedImageColor, GetAverageWallpaperColor());
425 } 421 }
426 422
427 } // namespace chromeos 423 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698