| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <cstdlib> | |
| 6 #include <cstring> | |
| 7 | |
| 8 #include "ash/desktop_background/desktop_background_controller.h" | |
| 9 #include "ash/desktop_background/desktop_background_controller_observer.h" | |
| 10 #include "ash/shell.h" | |
| 11 #include "ash/test/ash_test_base.h" | |
| 12 #include "ash/test/display_manager_test_api.h" | |
| 13 #include "ash/test/test_user_wallpaper_delegate.h" | |
| 14 #include "base/command_line.h" | |
| 15 #include "base/file_util.h" | |
| 16 #include "base/files/file_path.h" | |
| 17 #include "base/files/scoped_temp_dir.h" | |
| 18 #include "base/memory/scoped_ptr.h" | |
| 19 #include "base/prefs/pref_service.h" | |
| 20 #include "base/prefs/testing_pref_service.h" | |
| 21 #include "chrome/browser/chromeos/login/fake_user_manager.h" | |
| 22 #include "chrome/browser/chromeos/login/startup_utils.h" | |
| 23 #include "chrome/browser/chromeos/login/user_manager_impl.h" | |
| 24 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | |
| 25 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 26 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 27 #include "chrome/browser/prefs/browser_prefs.h" | |
| 28 #include "chrome/common/chrome_switches.h" | |
| 29 #include "chrome/test/base/testing_browser_process.h" | |
| 30 #include "chromeos/chromeos_switches.h" | |
| 31 #include "chromeos/settings/cros_settings_names.h" | |
| 32 #include "chromeos/settings/cros_settings_provider.h" | |
| 33 #include "grit/ash_resources.h" | |
| 34 #include "testing/gtest/include/gtest/gtest.h" | |
| 35 #include "ui/base/resource/resource_bundle.h" | |
| 36 #include "ui/gfx/image/image.h" | |
| 37 | |
| 38 using namespace ash; | |
| 39 | |
| 40 namespace chromeos { | |
| 41 | |
| 42 class WallpaperManagerCacheTest : public test::AshTestBase { | |
| 43 public: | |
| 44 WallpaperManagerCacheTest() | |
| 45 : fake_user_manager_(new FakeUserManager()), | |
| 46 scoped_user_manager_(fake_user_manager_) { | |
| 47 } | |
| 48 | |
| 49 protected: | |
| 50 virtual ~WallpaperManagerCacheTest() {} | |
| 51 | |
| 52 FakeUserManager* fake_user_manager() { return fake_user_manager_; } | |
| 53 | |
| 54 virtual void SetUp() OVERRIDE { | |
| 55 CommandLine::ForCurrentProcess()->AppendSwitch(::switches::kMultiProfiles); | |
| 56 test::AshTestBase::SetUp(); | |
| 57 } | |
| 58 | |
| 59 // Creates a test image of size 1x1. | |
| 60 gfx::ImageSkia CreateTestImage(SkColor color) { | |
| 61 SkBitmap bitmap; | |
| 62 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | |
| 63 bitmap.allocPixels(); | |
| 64 bitmap.eraseColor(color); | |
| 65 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 FakeUserManager* fake_user_manager_; | |
| 70 ScopedUserManagerEnabler scoped_user_manager_; | |
| 71 }; | |
| 72 | |
| 73 TEST_F(WallpaperManagerCacheTest, VerifyWallpaperCache) { | |
| 74 // Add three users to known users. | |
| 75 std::string test_user_1 = "test1@example.com"; | |
| 76 std::string test_user_2 = "test2@example.com"; | |
| 77 std::string test_user_3 = "test3@example.com"; | |
| 78 fake_user_manager()->AddUser(test_user_1); | |
| 79 fake_user_manager()->AddUser(test_user_2); | |
| 80 fake_user_manager()->AddUser(test_user_3); | |
| 81 | |
| 82 // Login two users. | |
| 83 fake_user_manager()->LoginUser(test_user_1); | |
| 84 fake_user_manager()->LoginUser(test_user_2); | |
| 85 | |
| 86 scoped_ptr<WallpaperManager::TestApi> test_api; | |
| 87 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get())); | |
| 88 | |
| 89 gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED); | |
| 90 gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN); | |
| 91 gfx::ImageSkia test_user_3_wallpaper = CreateTestImage(SK_ColorWHITE); | |
| 92 test_api->SetWallpaperCache(test_user_1, test_user_1_wallpaper); | |
| 93 test_api->SetWallpaperCache(test_user_2, test_user_2_wallpaper); | |
| 94 test_api->SetWallpaperCache(test_user_3, test_user_3_wallpaper); | |
| 95 | |
| 96 test_api->ClearDisposableWallpaperCache(); | |
| 97 | |
| 98 gfx::ImageSkia cached_wallpaper; | |
| 99 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_1, &cached_wallpaper)); | |
| 100 // Logged in users' wallpaper cache should be kept. | |
| 101 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper)); | |
| 102 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_2, &cached_wallpaper)); | |
| 103 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper)); | |
| 104 | |
| 105 // Not logged in user's wallpaper cache should be cleared. | |
| 106 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_user_3, &cached_wallpaper)); | |
| 107 } | |
| 108 | |
| 109 } // namespace chromeos | |
| OLD | NEW |