| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include "ash/ash_resources/grit/ash_resources.h" | 7 #include "ash/ash_resources/grit/ash_resources.h" |
| 8 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
| 9 #include "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
| 10 #include "ash/desktop_background/desktop_background_controller_observer.h" | 10 #include "ash/desktop_background/desktop_background_controller_observer.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 wallpaper_path, | 157 wallpaper_path, |
| 158 reinterpret_cast<const char*>(image_data->front()), | 158 reinterpret_cast<const char*>(image_data->front()), |
| 159 image_data->size()); | 159 image_data->size()); |
| 160 EXPECT_EQ(static_cast<int>(image_data->size()), written); | 160 EXPECT_EQ(static_cast<int>(image_data->size()), written); |
| 161 } | 161 } |
| 162 | 162 |
| 163 int LoadedWallpapers() { | 163 int LoadedWallpapers() { |
| 164 return WallpaperManager::Get()->loaded_wallpapers(); | 164 return WallpaperManager::Get()->loaded_wallpapers(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ClearDisposableWallpaperCache() { |
| 168 WallpaperManager::Get()->ClearDisposableWallpaperCache(); |
| 169 } |
| 170 |
| 167 // Creates a test image of size 1x1. | 171 // Creates a test image of size 1x1. |
| 168 gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) { | 172 gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) { |
| 169 SkBitmap bitmap; | 173 SkBitmap bitmap; |
| 170 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 174 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 171 bitmap.allocPixels(); | 175 bitmap.allocPixels(); |
| 172 bitmap.eraseColor(color); | 176 bitmap.eraseColor(color); |
| 173 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 177 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 174 } | 178 } |
| 175 | 179 |
| 176 // Writes a JPEG image of the specified size and color to |path|. Returns | 180 // Writes a JPEG image of the specified size and color to |path|. Returns |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // Loads the same wallpaper before the initial one finished. It should be | 402 // Loads the same wallpaper before the initial one finished. It should be |
| 399 // prevented. | 403 // prevented. |
| 400 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | 404 wallpaper_manager->SetUserWallpaperNow(kTestUser1); |
| 401 WaitAsyncWallpaperLoadFinished(); | 405 WaitAsyncWallpaperLoadFinished(); |
| 402 EXPECT_EQ(1, LoadedWallpapers()); | 406 EXPECT_EQ(1, LoadedWallpapers()); |
| 403 // Loads the same wallpaper after the initial one finished. It should be | 407 // Loads the same wallpaper after the initial one finished. It should be |
| 404 // prevented. | 408 // prevented. |
| 405 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | 409 wallpaper_manager->SetUserWallpaperNow(kTestUser1); |
| 406 WaitAsyncWallpaperLoadFinished(); | 410 WaitAsyncWallpaperLoadFinished(); |
| 407 EXPECT_EQ(1, LoadedWallpapers()); | 411 EXPECT_EQ(1, LoadedWallpapers()); |
| 408 wallpaper_manager->ClearDisposableWallpaperCache(); | 412 ClearDisposableWallpaperCache(); |
| 409 | 413 |
| 410 // Change wallpaper to a custom wallpaper. | 414 // Change wallpaper to a custom wallpaper. |
| 411 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); | 415 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); |
| 412 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( | 416 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( |
| 413 kSmallWallpaperSubDir, | 417 kSmallWallpaperSubDir, |
| 414 kTestUser1Hash, | 418 kTestUser1Hash, |
| 415 id); | 419 id); |
| 416 SaveUserWallpaperData(small_wallpaper_path, | 420 SaveUserWallpaperData(small_wallpaper_path, |
| 417 kSmallWallpaperResourceId); | 421 kSmallWallpaperResourceId); |
| 418 | 422 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 red_wallpaper, | 692 red_wallpaper, |
| 689 WALLPAPER_LAYOUT_CENTER, | 693 WALLPAPER_LAYOUT_CENTER, |
| 690 true); | 694 true); |
| 691 WaitAsyncWallpaperLoadFinished(); | 695 WaitAsyncWallpaperLoadFinished(); |
| 692 // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile | 696 // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile |
| 693 // is turned on. | 697 // is turned on. |
| 694 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | 698 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); |
| 695 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper)); | 699 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper)); |
| 696 | 700 |
| 697 gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN); | 701 gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN); |
| 698 chromeos::UserImage image(green_wallpaper); | |
| 699 wallpaper_manager->SetCustomWallpaper(kTestUser1, | 702 wallpaper_manager->SetCustomWallpaper(kTestUser1, |
| 700 kTestUser1Hash, | 703 kTestUser1Hash, |
| 701 "dummy", // dummy file name | 704 "dummy", // dummy file name |
| 702 WALLPAPER_LAYOUT_CENTER, | 705 WALLPAPER_LAYOUT_CENTER, |
| 703 User::CUSTOMIZED, | 706 User::CUSTOMIZED, |
| 704 image, | 707 green_wallpaper, |
| 705 true); | 708 true); |
| 706 WaitAsyncWallpaperLoadFinished(); | 709 WaitAsyncWallpaperLoadFinished(); |
| 707 // SetCustomWallpaper should also update wallpaper cache when multi-profile is | 710 // SetCustomWallpaper should also update wallpaper cache when multi-profile is |
| 708 // turned on. | 711 // turned on. |
| 709 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | 712 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); |
| 710 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper)); | 713 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper)); |
| 711 | 714 |
| 712 wallpaper_manager->SetDefaultWallpaperNow(kTestUser1); | 715 wallpaper_manager->SetDefaultWallpaperNow(kTestUser1); |
| 713 WaitAsyncWallpaperLoadFinished(); | 716 WaitAsyncWallpaperLoadFinished(); |
| 714 // SetDefaultWallpaper should invalidate the user's wallpaper cache. | 717 // SetDefaultWallpaper should invalidate the user's wallpaper cache. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 // Start loading the default wallpaper. | 920 // Start loading the default wallpaper. |
| 918 UpdateDisplay("640x480"); | 921 UpdateDisplay("640x480"); |
| 919 WriteWallpapers(); | 922 WriteWallpapers(); |
| 920 UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false); | 923 UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false); |
| 921 | 924 |
| 922 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | 925 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); |
| 923 | 926 |
| 924 // Custom wallpaper should be applied immediately, canceling the default | 927 // Custom wallpaper should be applied immediately, canceling the default |
| 925 // wallpaper load task. | 928 // wallpaper load task. |
| 926 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor); | 929 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor); |
| 927 UserImage wallpaper(image); | |
| 928 WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser, | 930 WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser, |
| 929 "test_hash", | 931 "test_hash", |
| 930 "test-nofile.jpeg", | 932 "test-nofile.jpeg", |
| 931 WALLPAPER_LAYOUT_STRETCH, | 933 WALLPAPER_LAYOUT_STRETCH, |
| 932 User::CUSTOMIZED, | 934 User::CUSTOMIZED, |
| 933 wallpaper, | 935 image, |
| 934 true); | 936 true); |
| 935 WaitAsyncWallpaperLoadFinished(); | 937 WaitAsyncWallpaperLoadFinished(); |
| 936 | 938 |
| 937 EXPECT_TRUE( | 939 EXPECT_TRUE( |
| 938 ImageIsNearColor(controller_->GetWallpaper(), kCustomWallpaperColor)); | 940 ImageIsNearColor(controller_->GetWallpaper(), kCustomWallpaperColor)); |
| 939 | 941 |
| 940 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | 942 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); |
| 941 WaitAsyncWallpaperLoadFinished(); | 943 WaitAsyncWallpaperLoadFinished(); |
| 942 | 944 |
| 943 EXPECT_TRUE( | 945 EXPECT_TRUE( |
| 944 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor)); | 946 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor)); |
| 945 } | 947 } |
| 946 | 948 |
| 947 } // namespace chromeos | 949 } // namespace chromeos |
| OLD | NEW |