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 "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/public/test/test_browser_thread.h" | 9 #include "content/public/test/test_browser_thread.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // Fill bitmap with data. | 34 // Fill bitmap with data. |
35 for (int y = 0; y < h; ++y) { | 35 for (int y = 0; y < h; ++y) { |
36 for (int x = 0; x < w; ++x) { | 36 for (int x = 0; x < w; ++x) { |
37 const uint8_t component = static_cast<uint8_t>(y * w + x); | 37 const uint8_t component = static_cast<uint8_t>(y * w + x); |
38 const SkColor pixel = SkColorSetARGB(component, component, | 38 const SkColor pixel = SkColorSetARGB(component, component, |
39 component, component); | 39 component, component); |
40 *(src.getAddr32(x, y)) = pixel; | 40 *(src.getAddr32(x, y)) = pixel; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 return gfx::ImageSkia::CreateFrom1xBitmap(src); | 44 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(src); |
| 45 return image; |
45 } | 46 } |
46 | 47 |
47 bool IsColor(const gfx::ImageSkia& image, const uint32_t expect) { | 48 bool IsColor(const gfx::ImageSkia& image, const uint32_t expect) { |
48 EXPECT_EQ(image.width(), kTargetWidth); | 49 EXPECT_EQ(image.width(), kTargetWidth); |
49 EXPECT_EQ(image.height(), kTargetHeight); | 50 EXPECT_EQ(image.height(), kTargetHeight); |
50 const SkBitmap* image_bitmap = image.bitmap(); | 51 const SkBitmap* image_bitmap = image.bitmap(); |
51 SkAutoLockPixels image_lock(*image_bitmap); | 52 SkAutoLockPixels image_lock(*image_bitmap); |
52 return *image_bitmap->getAddr32(0, 0) == expect; | 53 return *image_bitmap->getAddr32(0, 0) == expect; |
53 } | 54 } |
54 | 55 |
(...skipping 12 matching lines...) Expand all Loading... |
67 | 68 |
68 gfx::ImageSkia Resize(const gfx::ImageSkia& image, | 69 gfx::ImageSkia Resize(const gfx::ImageSkia& image, |
69 const gfx::Size& target_size, | 70 const gfx::Size& target_size, |
70 WallpaperLayout layout) { | 71 WallpaperLayout layout) { |
71 scoped_ptr<WallpaperResizer> resizer; | 72 scoped_ptr<WallpaperResizer> resizer; |
72 resizer.reset(new WallpaperResizer(image, target_size, layout)); | 73 resizer.reset(new WallpaperResizer(image, target_size, layout)); |
73 resizer->AddObserver(this); | 74 resizer->AddObserver(this); |
74 resizer->StartResize(); | 75 resizer->StartResize(); |
75 WaitForResize(); | 76 WaitForResize(); |
76 resizer->RemoveObserver(this); | 77 resizer->RemoveObserver(this); |
77 return resizer->wallpaper_image(); | 78 return resizer->image(); |
78 } | 79 } |
79 | 80 |
80 void WaitForResize() { | 81 void WaitForResize() { |
81 message_loop_.Run(); | 82 message_loop_.Run(); |
82 } | 83 } |
83 | 84 |
84 virtual void OnWallpaperResized() OVERRIDE { | 85 virtual void OnWallpaperResized() OVERRIDE { |
85 message_loop_.Quit(); | 86 message_loop_.Quit(); |
86 } | 87 } |
87 | 88 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 gfx::ImageSkia stretch = Resize(image, target_size, WALLPAPER_LAYOUT_STRETCH); | 135 gfx::ImageSkia stretch = Resize(image, target_size, WALLPAPER_LAYOUT_STRETCH); |
135 | 136 |
136 gfx::ImageSkia tile = Resize(image, target_size, WALLPAPER_LAYOUT_TILE); | 137 gfx::ImageSkia tile = Resize(image, target_size, WALLPAPER_LAYOUT_TILE); |
137 | 138 |
138 EXPECT_TRUE(IsColor(center, kExpectedCenter)); | 139 EXPECT_TRUE(IsColor(center, kExpectedCenter)); |
139 EXPECT_TRUE(IsColor(center_cropped, kExpectedCenterCropped)); | 140 EXPECT_TRUE(IsColor(center_cropped, kExpectedCenterCropped)); |
140 EXPECT_TRUE(IsColor(stretch, kExpectedStretch)); | 141 EXPECT_TRUE(IsColor(stretch, kExpectedStretch)); |
141 EXPECT_TRUE(IsColor(tile, kExpectedTile)); | 142 EXPECT_TRUE(IsColor(tile, kExpectedTile)); |
142 } | 143 } |
143 | 144 |
| 145 TEST_F(WallpaperResizerTest, ImageId) { |
| 146 gfx::ImageSkia image = CreateTestImage( |
| 147 gfx::Size(kTestImageWidth, kTestImageHeight)); |
| 148 |
| 149 // Create a WallpaperResizer and check that it reports an original image ID |
| 150 // both pre- and post-resize that matches the ID returned by GetImageId(). |
| 151 WallpaperResizer resizer(image, gfx::Size(10, 20), WALLPAPER_LAYOUT_STRETCH); |
| 152 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id()); |
| 153 resizer.AddObserver(this); |
| 154 resizer.StartResize(); |
| 155 WaitForResize(); |
| 156 resizer.RemoveObserver(this); |
| 157 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id()); |
| 158 } |
| 159 |
144 } // namespace internal | 160 } // namespace internal |
145 } // namespace ash | 161 } // namespace ash |
OLD | NEW |