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

Side by Side Diff: chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc

Issue 221873005: Some cleanup of WallpaperManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Compilation fix. Created 6 years, 8 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/wallpaper_manager.cc ('k') | chromeos/chromeos_switches.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 wallpaper_path, 156 wallpaper_path,
157 reinterpret_cast<const char*>(image_data->front()), 157 reinterpret_cast<const char*>(image_data->front()),
158 image_data->size()); 158 image_data->size());
159 EXPECT_EQ(static_cast<int>(image_data->size()), written); 159 EXPECT_EQ(static_cast<int>(image_data->size()), written);
160 } 160 }
161 161
162 int LoadedWallpapers() { 162 int LoadedWallpapers() {
163 return WallpaperManager::Get()->loaded_wallpapers(); 163 return WallpaperManager::Get()->loaded_wallpapers();
164 } 164 }
165 165
166 void ClearDisposableWallpaperCache() {
167 WallpaperManager::Get()->ClearDisposableWallpaperCache();
168 }
169
166 // Creates a test image of size 1x1. 170 // Creates a test image of size 1x1.
167 gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) { 171 gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) {
168 SkBitmap bitmap; 172 SkBitmap bitmap;
169 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 173 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
170 bitmap.allocPixels(); 174 bitmap.allocPixels();
171 bitmap.eraseColor(color); 175 bitmap.eraseColor(color);
172 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 176 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
173 } 177 }
174 178
175 // Writes a JPEG image of the specified size and color to |path|. Returns 179 // 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
397 // Loads the same wallpaper before the initial one finished. It should be 401 // Loads the same wallpaper before the initial one finished. It should be
398 // prevented. 402 // prevented.
399 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 403 wallpaper_manager->SetUserWallpaperNow(kTestUser1);
400 WaitAsyncWallpaperLoadFinished(); 404 WaitAsyncWallpaperLoadFinished();
401 EXPECT_EQ(1, LoadedWallpapers()); 405 EXPECT_EQ(1, LoadedWallpapers());
402 // Loads the same wallpaper after the initial one finished. It should be 406 // Loads the same wallpaper after the initial one finished. It should be
403 // prevented. 407 // prevented.
404 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 408 wallpaper_manager->SetUserWallpaperNow(kTestUser1);
405 WaitAsyncWallpaperLoadFinished(); 409 WaitAsyncWallpaperLoadFinished();
406 EXPECT_EQ(1, LoadedWallpapers()); 410 EXPECT_EQ(1, LoadedWallpapers());
407 wallpaper_manager->ClearDisposableWallpaperCache(); 411 ClearDisposableWallpaperCache();
408 412
409 // Change wallpaper to a custom wallpaper. 413 // Change wallpaper to a custom wallpaper.
410 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); 414 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
411 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( 415 base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
412 kSmallWallpaperSubDir, 416 kSmallWallpaperSubDir,
413 kTestUser1Hash, 417 kTestUser1Hash,
414 id); 418 id);
415 SaveUserWallpaperData(small_wallpaper_path, 419 SaveUserWallpaperData(small_wallpaper_path,
416 kSmallWallpaperResourceId); 420 kSmallWallpaperResourceId);
417 421
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 red_wallpaper, 689 red_wallpaper,
686 WALLPAPER_LAYOUT_CENTER, 690 WALLPAPER_LAYOUT_CENTER,
687 true); 691 true);
688 WaitAsyncWallpaperLoadFinished(); 692 WaitAsyncWallpaperLoadFinished();
689 // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile 693 // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile
690 // is turned on. 694 // is turned on.
691 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 695 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
692 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper)); 696 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper));
693 697
694 gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN); 698 gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN);
695 chromeos::UserImage image(green_wallpaper);
696 wallpaper_manager->SetCustomWallpaper(kTestUser1, 699 wallpaper_manager->SetCustomWallpaper(kTestUser1,
697 kTestUser1Hash, 700 kTestUser1Hash,
698 "dummy", // dummy file name 701 "dummy", // dummy file name
699 WALLPAPER_LAYOUT_CENTER, 702 WALLPAPER_LAYOUT_CENTER,
700 User::CUSTOMIZED, 703 User::CUSTOMIZED,
701 image, 704 green_wallpaper,
702 true); 705 true);
703 WaitAsyncWallpaperLoadFinished(); 706 WaitAsyncWallpaperLoadFinished();
704 // SetCustomWallpaper should also update wallpaper cache when multi-profile is 707 // SetCustomWallpaper should also update wallpaper cache when multi-profile is
705 // turned on. 708 // turned on.
706 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 709 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
707 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper)); 710 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper));
708 711
709 wallpaper_manager->SetDefaultWallpaperNow(kTestUser1); 712 wallpaper_manager->SetDefaultWallpaperNow(kTestUser1);
710 WaitAsyncWallpaperLoadFinished(); 713 WaitAsyncWallpaperLoadFinished();
711 // SetDefaultWallpaper should invalidate the user's wallpaper cache. 714 // SetDefaultWallpaper should invalidate the user's wallpaper cache.
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 // Start loading the default wallpaper. 918 // Start loading the default wallpaper.
916 UpdateDisplay("640x480"); 919 UpdateDisplay("640x480");
917 WriteWallpapers(); 920 WriteWallpapers();
918 UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false); 921 UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false);
919 922
920 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 923 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
921 924
922 // Custom wallpaper should be applied immediately, canceling the default 925 // Custom wallpaper should be applied immediately, canceling the default
923 // wallpaper load task. 926 // wallpaper load task.
924 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor); 927 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor);
925 UserImage wallpaper(image);
926 WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser, 928 WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser,
927 "test_hash", 929 "test_hash",
928 "test-nofile.jpeg", 930 "test-nofile.jpeg",
929 WALLPAPER_LAYOUT_STRETCH, 931 WALLPAPER_LAYOUT_STRETCH,
930 User::CUSTOMIZED, 932 User::CUSTOMIZED,
931 wallpaper, 933 image,
932 true); 934 true);
933 WaitAsyncWallpaperLoadFinished(); 935 WaitAsyncWallpaperLoadFinished();
934 936
935 EXPECT_TRUE( 937 EXPECT_TRUE(
936 ImageIsNearColor(controller_->GetWallpaper(), kCustomWallpaperColor)); 938 ImageIsNearColor(controller_->GetWallpaper(), kCustomWallpaperColor));
937 939
938 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 940 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
939 WaitAsyncWallpaperLoadFinished(); 941 WaitAsyncWallpaperLoadFinished();
940 942
941 EXPECT_TRUE( 943 EXPECT_TRUE(
942 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor)); 944 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor));
943 } 945 }
944 946
945 } // namespace chromeos 947 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.cc ('k') | chromeos/chromeos_switches.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698