| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 namespace ash { | 56 namespace ash { |
| 57 | 57 |
| 58 class WallpaperResizerTest : public testing::Test, | 58 class WallpaperResizerTest : public testing::Test, |
| 59 public WallpaperResizerObserver { | 59 public WallpaperResizerObserver { |
| 60 public: | 60 public: |
| 61 WallpaperResizerTest() | 61 WallpaperResizerTest() |
| 62 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | 62 : ui_thread_(content::BrowserThread::UI, &message_loop_) { |
| 63 } | 63 } |
| 64 virtual ~WallpaperResizerTest() {} | 64 ~WallpaperResizerTest() override {} |
| 65 | 65 |
| 66 gfx::ImageSkia Resize(const gfx::ImageSkia& image, | 66 gfx::ImageSkia Resize(const gfx::ImageSkia& image, |
| 67 const gfx::Size& target_size, | 67 const gfx::Size& target_size, |
| 68 WallpaperLayout layout) { | 68 WallpaperLayout layout) { |
| 69 scoped_ptr<WallpaperResizer> resizer; | 69 scoped_ptr<WallpaperResizer> resizer; |
| 70 resizer.reset(new WallpaperResizer(image, target_size, layout)); | 70 resizer.reset(new WallpaperResizer(image, target_size, layout)); |
| 71 resizer->AddObserver(this); | 71 resizer->AddObserver(this); |
| 72 resizer->StartResize(); | 72 resizer->StartResize(); |
| 73 WaitForResize(); | 73 WaitForResize(); |
| 74 resizer->RemoveObserver(this); | 74 resizer->RemoveObserver(this); |
| 75 return resizer->image(); | 75 return resizer->image(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void WaitForResize() { | 78 void WaitForResize() { |
| 79 message_loop_.Run(); | 79 message_loop_.Run(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 virtual void OnWallpaperResized() override { | 82 void OnWallpaperResized() override { message_loop_.Quit(); } |
| 83 message_loop_.Quit(); | |
| 84 } | |
| 85 | 83 |
| 86 private: | 84 private: |
| 87 base::MessageLoop message_loop_; | 85 base::MessageLoop message_loop_; |
| 88 content::TestBrowserThread ui_thread_; | 86 content::TestBrowserThread ui_thread_; |
| 89 | 87 |
| 90 DISALLOW_COPY_AND_ASSIGN(WallpaperResizerTest); | 88 DISALLOW_COPY_AND_ASSIGN(WallpaperResizerTest); |
| 91 }; | 89 }; |
| 92 | 90 |
| 93 TEST_F(WallpaperResizerTest, BasicResize) { | 91 TEST_F(WallpaperResizerTest, BasicResize) { |
| 94 // Keeps in sync with WallpaperLayout enum. | 92 // Keeps in sync with WallpaperLayout enum. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 WallpaperResizer resizer(image, gfx::Size(10, 20), WALLPAPER_LAYOUT_STRETCH); | 146 WallpaperResizer resizer(image, gfx::Size(10, 20), WALLPAPER_LAYOUT_STRETCH); |
| 149 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id()); | 147 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id()); |
| 150 resizer.AddObserver(this); | 148 resizer.AddObserver(this); |
| 151 resizer.StartResize(); | 149 resizer.StartResize(); |
| 152 WaitForResize(); | 150 WaitForResize(); |
| 153 resizer.RemoveObserver(this); | 151 resizer.RemoveObserver(this); |
| 154 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id()); | 152 EXPECT_EQ(WallpaperResizer::GetImageId(image), resizer.original_image_id()); |
| 155 } | 153 } |
| 156 | 154 |
| 157 } // namespace ash | 155 } // namespace ash |
| OLD | NEW |