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

Side by Side Diff: ash/desktop_background/wallpaper_resizer_unittest.cc

Issue 81393004: ash: Avoid reloading already-resized custom wallpaper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add another MakeThreadSafe() call to WallpaperResizer Created 7 years 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 | Annotate | Revision Log
OLDNEW
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
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 image.MakeThreadSafe();
46 return image;
45 } 47 }
46 48
47 bool IsColor(const gfx::ImageSkia& image, const uint32_t expect) { 49 bool IsColor(const gfx::ImageSkia& image, const uint32_t expect) {
48 EXPECT_EQ(image.width(), kTargetWidth); 50 EXPECT_EQ(image.width(), kTargetWidth);
49 EXPECT_EQ(image.height(), kTargetHeight); 51 EXPECT_EQ(image.height(), kTargetHeight);
50 const SkBitmap* image_bitmap = image.bitmap(); 52 const SkBitmap* image_bitmap = image.bitmap();
51 SkAutoLockPixels image_lock(*image_bitmap); 53 SkAutoLockPixels image_lock(*image_bitmap);
52 return *image_bitmap->getAddr32(0, 0) == expect; 54 return *image_bitmap->getAddr32(0, 0) == expect;
53 } 55 }
54 56
(...skipping 12 matching lines...) Expand all
67 69
68 gfx::ImageSkia Resize(const gfx::ImageSkia& image, 70 gfx::ImageSkia Resize(const gfx::ImageSkia& image,
69 const gfx::Size& target_size, 71 const gfx::Size& target_size,
70 WallpaperLayout layout) { 72 WallpaperLayout layout) {
71 scoped_ptr<WallpaperResizer> resizer; 73 scoped_ptr<WallpaperResizer> resizer;
72 resizer.reset(new WallpaperResizer(image, target_size, layout)); 74 resizer.reset(new WallpaperResizer(image, target_size, layout));
73 resizer->AddObserver(this); 75 resizer->AddObserver(this);
74 resizer->StartResize(); 76 resizer->StartResize();
75 WaitForResize(); 77 WaitForResize();
76 resizer->RemoveObserver(this); 78 resizer->RemoveObserver(this);
77 return resizer->wallpaper_image(); 79 return resizer->image();
78 } 80 }
79 81
80 void WaitForResize() { 82 void WaitForResize() {
81 message_loop_.Run(); 83 message_loop_.Run();
82 } 84 }
83 85
84 virtual void OnWallpaperResized() OVERRIDE { 86 virtual void OnWallpaperResized() OVERRIDE {
85 message_loop_.Quit(); 87 message_loop_.Quit();
86 } 88 }
87 89
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 gfx::ImageSkia stretch = Resize(image, target_size, WALLPAPER_LAYOUT_STRETCH); 136 gfx::ImageSkia stretch = Resize(image, target_size, WALLPAPER_LAYOUT_STRETCH);
135 137
136 gfx::ImageSkia tile = Resize(image, target_size, WALLPAPER_LAYOUT_TILE); 138 gfx::ImageSkia tile = Resize(image, target_size, WALLPAPER_LAYOUT_TILE);
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
146 TEST_F(WallpaperResizerTest, ImageId) {
147 gfx::ImageSkia image = CreateTestImage(
148 gfx::Size(kTestImageWidth, kTestImageHeight));
149
150 // Create a WallpaperResizer and check that it reports an original image ID
151 // both pre- and post-resize that matches the ID returned by GetImageId().
152 WallpaperResizer resizer(image, gfx::Size(10, 20), WALLPAPER_LAYOUT_STRETCH);
153 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id());
154 resizer.AddObserver(this);
155 resizer.StartResize();
156 WaitForResize();
157 resizer.RemoveObserver(this);
158 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id());
159 }
160
144 } // namespace internal 161 } // namespace internal
145 } // namespace ash 162 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698