ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / wallpaper / wallpaper_manager_unittest.cc
blobb6543f5923de4e6df897bb71d6bf27f34dc35767
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
3 // found in the LICENSE file.
5 #include <cstdlib>
6 #include <cstring>
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/files/file_path.h"
16 #include "base/files/file_util.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/startup_utils.h"
22 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
23 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
24 #include "chrome/browser/chromeos/login/users/wallpaper/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/test/base/testing_browser_process.h"
29 #include "chromeos/chromeos_switches.h"
30 #include "chromeos/settings/cros_settings_names.h"
31 #include "chromeos/settings/cros_settings_provider.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "ui/gfx/image/image.h"
35 using namespace ash;
37 namespace chromeos {
39 class WallpaperManagerCacheTest : public test::AshTestBase {
40 public:
41 WallpaperManagerCacheTest()
42 : fake_user_manager_(new FakeChromeUserManager()),
43 scoped_user_manager_(fake_user_manager_) {}
45 protected:
46 ~WallpaperManagerCacheTest() override {}
48 FakeChromeUserManager* fake_user_manager() { return fake_user_manager_; }
50 void SetUp() override { test::AshTestBase::SetUp(); }
52 // Creates a test image of size 1x1.
53 gfx::ImageSkia CreateTestImage(SkColor color) {
54 SkBitmap bitmap;
55 bitmap.allocN32Pixels(1, 1);
56 bitmap.eraseColor(color);
57 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
60 private:
61 FakeChromeUserManager* fake_user_manager_;
62 ScopedUserManagerEnabler scoped_user_manager_;
65 TEST_F(WallpaperManagerCacheTest, VerifyWallpaperCache) {
66 // Add three users to known users.
67 std::string test_user_1 = "test1@example.com";
68 std::string test_user_2 = "test2@example.com";
69 std::string test_user_3 = "test3@example.com";
70 base::FilePath path1("path1");
71 base::FilePath path2("path2");
72 base::FilePath path3("path3");
73 fake_user_manager()->AddUser(test_user_1);
74 fake_user_manager()->AddUser(test_user_2);
75 fake_user_manager()->AddUser(test_user_3);
77 // Login two users.
78 fake_user_manager()->LoginUser(test_user_1);
79 fake_user_manager()->LoginUser(test_user_2);
81 scoped_ptr<WallpaperManager::TestApi> test_api;
82 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get()));
84 gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED);
85 gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN);
86 gfx::ImageSkia test_user_3_wallpaper = CreateTestImage(SK_ColorWHITE);
87 test_api->SetWallpaperCache(test_user_1, path1, test_user_1_wallpaper);
88 test_api->SetWallpaperCache(test_user_2, path2, test_user_2_wallpaper);
89 test_api->SetWallpaperCache(test_user_3, path3, test_user_3_wallpaper);
91 test_api->ClearDisposableWallpaperCache();
93 gfx::ImageSkia cached_wallpaper;
94 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_1, &cached_wallpaper));
95 base::FilePath path;
96 EXPECT_TRUE(test_api->GetPathFromCache(test_user_1, &path));
97 // Logged in users' wallpaper cache should be kept.
98 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper));
99 EXPECT_EQ(path, path1);
100 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_2, &cached_wallpaper));
101 EXPECT_TRUE(test_api->GetPathFromCache(test_user_2, &path));
102 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper));
103 EXPECT_EQ(path, path2);
105 // Not logged in user's wallpaper cache should be cleared.
106 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_user_3, &cached_wallpaper));
107 EXPECT_FALSE(test_api->GetPathFromCache(test_user_3, &path));
110 } // namespace chromeos