| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/json/json_file_value_serializer.h" | 5 #include "base/json/json_file_value_serializer.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/extension_icon_manager.h" | 9 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 waiting_(false), | 29 waiting_(false), |
| 30 ui_thread_(BrowserThread::UI, &ui_loop_), | 30 ui_thread_(BrowserThread::UI, &ui_loop_), |
| 31 file_thread_(BrowserThread::FILE), | 31 file_thread_(BrowserThread::FILE), |
| 32 io_thread_(BrowserThread::IO) {} | 32 io_thread_(BrowserThread::IO) {} |
| 33 | 33 |
| 34 virtual ~ExtensionIconManagerTest() {} | 34 virtual ~ExtensionIconManagerTest() {} |
| 35 | 35 |
| 36 void ImageLoadObserved() { | 36 void ImageLoadObserved() { |
| 37 unwaited_image_loads_++; | 37 unwaited_image_loads_++; |
| 38 if (waiting_) { | 38 if (waiting_) { |
| 39 MessageLoop::current()->Quit(); | 39 base::MessageLoop::current()->Quit(); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void WaitForImageLoad() { | 43 void WaitForImageLoad() { |
| 44 if (unwaited_image_loads_ == 0) { | 44 if (unwaited_image_loads_ == 0) { |
| 45 waiting_ = true; | 45 waiting_ = true; |
| 46 MessageLoop::current()->Run(); | 46 base::MessageLoop::current()->Run(); |
| 47 waiting_ = false; | 47 waiting_ = false; |
| 48 } | 48 } |
| 49 ASSERT_GT(unwaited_image_loads_, 0); | 49 ASSERT_GT(unwaited_image_loads_, 0); |
| 50 unwaited_image_loads_--; | 50 unwaited_image_loads_--; |
| 51 } | 51 } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 virtual void SetUp() { | 54 virtual void SetUp() { |
| 55 extensions::ExtensionTest::SetUp(); | 55 extensions::ExtensionTest::SetUp(); |
| 56 file_thread_.Start(); | 56 file_thread_.Start(); |
| 57 io_thread_.Start(); | 57 io_thread_.Start(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // The number of observed image loads that have not been waited for. | 60 // The number of observed image loads that have not been waited for. |
| 61 int unwaited_image_loads_; | 61 int unwaited_image_loads_; |
| 62 | 62 |
| 63 // Whether we are currently waiting for an image load. | 63 // Whether we are currently waiting for an image load. |
| 64 bool waiting_; | 64 bool waiting_; |
| 65 | 65 |
| 66 MessageLoop ui_loop_; | 66 base::MessageLoop ui_loop_; |
| 67 content::TestBrowserThread ui_thread_; | 67 content::TestBrowserThread ui_thread_; |
| 68 content::TestBrowserThread file_thread_; | 68 content::TestBrowserThread file_thread_; |
| 69 content::TestBrowserThread io_thread_; | 69 content::TestBrowserThread io_thread_; |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(ExtensionIconManagerTest); | 71 DISALLOW_COPY_AND_ASSIGN(ExtensionIconManagerTest); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // This is a specialization of ExtensionIconManager, with a special override to | 74 // This is a specialization of ExtensionIconManager, with a special override to |
| 75 // call back to the test when an icon has completed loading. | 75 // call back to the test when an icon has completed loading. |
| 76 class TestIconManager : public ExtensionIconManager { | 76 class TestIconManager : public ExtensionIconManager { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // Now re-load the icon - we should get the same result bitmap (and not the | 176 // Now re-load the icon - we should get the same result bitmap (and not the |
| 177 // default icon). | 177 // default icon). |
| 178 icon_manager.LoadIcon(profile.get(), extension.get()); | 178 icon_manager.LoadIcon(profile.get(), extension.get()); |
| 179 WaitForImageLoad(); | 179 WaitForImageLoad(); |
| 180 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); | 180 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); |
| 181 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); | 181 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); |
| 182 | 182 |
| 183 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); | 183 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); |
| 184 } | 184 } |
| 185 #endif | 185 #endif |
| OLD | NEW |