OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ash/desktop_background/wallpaper_resizer.h" | 5 #include "ash/desktop_background/wallpaper_resizer.h" |
6 | 6 |
7 #include "ash/desktop_background/wallpaper_resizer_observer.h" | 7 #include "ash/desktop_background/wallpaper_resizer_observer.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "content/public/test/test_browser_thread.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/image/image_skia_rep.h" | 11 #include "ui/gfx/image/image_skia_rep.h" |
10 | 12 |
11 using aura::RootWindow; | 13 using aura::RootWindow; |
12 using aura::Window; | 14 using aura::Window; |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 const int kTestImageWidth = 5; | 18 const int kTestImageWidth = 5; |
17 const int kTestImageHeight = 2; | 19 const int kTestImageHeight = 2; |
18 const int kTargetWidth = 1; | 20 const int kTargetWidth = 1; |
(...skipping 29 matching lines...) Expand all Loading... |
48 const SkBitmap* image_bitmap = image.bitmap(); | 50 const SkBitmap* image_bitmap = image.bitmap(); |
49 SkAutoLockPixels image_lock(*image_bitmap); | 51 SkAutoLockPixels image_lock(*image_bitmap); |
50 return *image_bitmap->getAddr32(0, 0) == expect; | 52 return *image_bitmap->getAddr32(0, 0) == expect; |
51 } | 53 } |
52 | 54 |
53 } // namespace | 55 } // namespace |
54 | 56 |
55 namespace ash { | 57 namespace ash { |
56 namespace internal { | 58 namespace internal { |
57 | 59 |
58 class WallpaperResizerTest : public test::AshTestBase, | 60 class WallpaperResizerTest : public testing::Test, |
59 public WallpaperResizerObserver { | 61 public WallpaperResizerObserver { |
60 public: | 62 public: |
61 WallpaperResizerTest() {} | 63 WallpaperResizerTest() |
| 64 : ui_thread_(content::BrowserThread::UI, &message_loop_) { |
| 65 } |
62 virtual ~WallpaperResizerTest() {} | 66 virtual ~WallpaperResizerTest() {} |
63 | 67 |
64 gfx::ImageSkia Resize(const WallpaperInfo& info, | 68 gfx::ImageSkia Resize(const gfx::ImageSkia& image, |
65 const gfx::Size& target_size, | 69 const gfx::Size& target_size, |
66 const gfx::ImageSkia& image) { | 70 WallpaperLayout layout) { |
67 scoped_ptr<WallpaperResizer> resizer; | 71 scoped_ptr<WallpaperResizer> resizer; |
68 resizer.reset(new WallpaperResizer(info, target_size, image)); | 72 resizer.reset(new WallpaperResizer(image, target_size, layout)); |
69 resizer->AddObserver(this); | 73 resizer->AddObserver(this); |
70 resizer->StartResize(); | 74 resizer->StartResize(); |
71 WaitForResize(); | 75 WaitForResize(); |
72 resizer->RemoveObserver(this); | 76 resizer->RemoveObserver(this); |
73 return resizer->wallpaper_image(); | 77 return resizer->wallpaper_image(); |
74 } | 78 } |
75 | 79 |
76 void WaitForResize() { | 80 void WaitForResize() { |
77 base::MessageLoop::current()->Run(); | 81 message_loop_.Run(); |
78 } | 82 } |
79 | 83 |
80 virtual void OnWallpaperResized() OVERRIDE { | 84 virtual void OnWallpaperResized() OVERRIDE { |
81 base::MessageLoop::current()->Quit(); | 85 message_loop_.Quit(); |
82 } | 86 } |
83 | 87 |
84 private: | 88 private: |
| 89 base::MessageLoop message_loop_; |
| 90 content::TestBrowserThread ui_thread_; |
| 91 |
85 DISALLOW_COPY_AND_ASSIGN(WallpaperResizerTest); | 92 DISALLOW_COPY_AND_ASSIGN(WallpaperResizerTest); |
86 }; | 93 }; |
87 | 94 |
88 TEST_F(WallpaperResizerTest, BasicResize) { | 95 TEST_F(WallpaperResizerTest, BasicResize) { |
89 // Keeps in sync with WallpaperLayout enum. | 96 // Keeps in sync with WallpaperLayout enum. |
90 WallpaperLayout layouts[4] = { | 97 WallpaperLayout layouts[4] = { |
91 WALLPAPER_LAYOUT_CENTER, | 98 WALLPAPER_LAYOUT_CENTER, |
92 WALLPAPER_LAYOUT_CENTER_CROPPED, | 99 WALLPAPER_LAYOUT_CENTER_CROPPED, |
93 WALLPAPER_LAYOUT_STRETCH, | 100 WALLPAPER_LAYOUT_STRETCH, |
94 WALLPAPER_LAYOUT_TILE, | 101 WALLPAPER_LAYOUT_TILE, |
95 }; | 102 }; |
96 const int length = arraysize(layouts); | 103 const int length = arraysize(layouts); |
97 | 104 |
98 for (int i = 0; i < length; i++) { | 105 for (int i = 0; i < length; i++) { |
99 WallpaperLayout layout = layouts[i]; | 106 WallpaperLayout layout = layouts[i]; |
100 WallpaperInfo info = { 0, layout }; | |
101 gfx::ImageSkia small_image(gfx::ImageSkiaRep(gfx::Size(10, 20), | 107 gfx::ImageSkia small_image(gfx::ImageSkiaRep(gfx::Size(10, 20), |
102 ui::SCALE_FACTOR_100P)); | 108 ui::SCALE_FACTOR_100P)); |
103 | 109 |
104 gfx::ImageSkia resized_small = Resize(info, gfx::Size(800, 600), | 110 gfx::ImageSkia resized_small = Resize(small_image, gfx::Size(800, 600), |
105 small_image); | 111 layout); |
106 EXPECT_EQ(10, resized_small.width()); | 112 EXPECT_EQ(10, resized_small.width()); |
107 EXPECT_EQ(20, resized_small.height()); | 113 EXPECT_EQ(20, resized_small.height()); |
108 | 114 |
109 gfx::ImageSkia large_image(gfx::ImageSkiaRep(gfx::Size(1000, 1000), | 115 gfx::ImageSkia large_image(gfx::ImageSkiaRep(gfx::Size(1000, 1000), |
110 ui::SCALE_FACTOR_100P)); | 116 ui::SCALE_FACTOR_100P)); |
111 gfx::ImageSkia resized_large = Resize(info, gfx::Size(800, 600), | 117 gfx::ImageSkia resized_large = Resize(large_image, gfx::Size(800, 600), |
112 large_image); | 118 layout); |
113 EXPECT_EQ(800, resized_large.width()); | 119 EXPECT_EQ(800, resized_large.width()); |
114 EXPECT_EQ(600, resized_large.height()); | 120 EXPECT_EQ(600, resized_large.height()); |
115 } | 121 } |
116 } | 122 } |
117 | 123 |
118 // Test for crbug.com/244629. "CENTER_CROPPED generates the same image as | 124 // Test for crbug.com/244629. "CENTER_CROPPED generates the same image as |
119 // STRETCH layout" | 125 // STRETCH layout" |
120 TEST_F(WallpaperResizerTest, AllLayoutDifferent) { | 126 TEST_F(WallpaperResizerTest, AllLayoutDifferent) { |
121 gfx::ImageSkia image = CreateTestImage( | 127 gfx::ImageSkia image = CreateTestImage( |
122 gfx::Size(kTestImageWidth, kTestImageHeight)); | 128 gfx::Size(kTestImageWidth, kTestImageHeight)); |
123 | 129 |
124 gfx::Size target_size = gfx::Size(kTargetWidth, kTargetHeight); | 130 gfx::Size target_size = gfx::Size(kTargetWidth, kTargetHeight); |
125 WallpaperInfo info_center = { 0, WALLPAPER_LAYOUT_CENTER }; | 131 gfx::ImageSkia center = Resize(image, target_size, WALLPAPER_LAYOUT_CENTER); |
126 gfx::ImageSkia center = Resize(info_center, target_size, image); | |
127 | 132 |
128 WallpaperInfo info_center_cropped = { 0, WALLPAPER_LAYOUT_CENTER_CROPPED }; | 133 gfx::ImageSkia center_cropped = Resize(image, target_size, |
129 gfx::ImageSkia center_cropped = Resize(info_center_cropped, target_size, | 134 WALLPAPER_LAYOUT_CENTER_CROPPED); |
130 image); | |
131 | 135 |
132 WallpaperInfo info_stretch = { 0, WALLPAPER_LAYOUT_STRETCH }; | 136 gfx::ImageSkia stretch = Resize(image, target_size, WALLPAPER_LAYOUT_STRETCH); |
133 gfx::ImageSkia stretch = Resize(info_stretch, target_size, image); | |
134 | 137 |
135 WallpaperInfo info_tile = { 0, WALLPAPER_LAYOUT_TILE }; | 138 gfx::ImageSkia tile = Resize(image, target_size, WALLPAPER_LAYOUT_TILE); |
136 gfx::ImageSkia tile = Resize(info_tile, target_size, image); | |
137 | 139 |
138 EXPECT_TRUE(IsColor(center, kExpectedCenter)); | 140 EXPECT_TRUE(IsColor(center, kExpectedCenter)); |
139 EXPECT_TRUE(IsColor(center_cropped, kExpectedCenterCropped)); | 141 EXPECT_TRUE(IsColor(center_cropped, kExpectedCenterCropped)); |
140 EXPECT_TRUE(IsColor(stretch, kExpectedStretch)); | 142 EXPECT_TRUE(IsColor(stretch, kExpectedStretch)); |
141 EXPECT_TRUE(IsColor(tile, kExpectedTile)); | 143 EXPECT_TRUE(IsColor(tile, kExpectedTile)); |
142 } | 144 } |
143 | 145 |
144 } // namespace internal | 146 } // namespace internal |
145 } // namespace ash | 147 } // namespace ash |
OLD | NEW |