| 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" |
| 11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/extensions/extension_unittest.h" | |
| 13 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
| 15 #include "extensions/common/id_util.h" | 14 #include "extensions/common/id_util.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 18 | 17 |
| 19 using content::BrowserThread; | 18 using content::BrowserThread; |
| 20 using extensions::Extension; | 19 using extensions::Extension; |
| 21 using extensions::Manifest; | 20 using extensions::Manifest; |
| 22 | 21 |
| 23 // Our test class that takes care of managing the necessary threads for loading | 22 // Our test class that takes care of managing the necessary threads for loading |
| 24 // extension icons, and waiting for those loads to happen. | 23 // extension icons, and waiting for those loads to happen. |
| 25 class ExtensionIconManagerTest : public extensions::ExtensionTest { | 24 class ExtensionIconManagerTest : public testing::Test { |
| 26 public: | 25 public: |
| 27 ExtensionIconManagerTest() : | 26 ExtensionIconManagerTest() : |
| 28 unwaited_image_loads_(0), | 27 unwaited_image_loads_(0), |
| 29 waiting_(false), | 28 waiting_(false), |
| 30 ui_thread_(BrowserThread::UI, &ui_loop_), | 29 ui_thread_(BrowserThread::UI, &ui_loop_), |
| 31 file_thread_(BrowserThread::FILE), | 30 file_thread_(BrowserThread::FILE), |
| 32 io_thread_(BrowserThread::IO) {} | 31 io_thread_(BrowserThread::IO) {} |
| 33 | 32 |
| 34 virtual ~ExtensionIconManagerTest() {} | 33 virtual ~ExtensionIconManagerTest() {} |
| 35 | 34 |
| 36 void ImageLoadObserved() { | 35 void ImageLoadObserved() { |
| 37 unwaited_image_loads_++; | 36 unwaited_image_loads_++; |
| 38 if (waiting_) { | 37 if (waiting_) { |
| 39 MessageLoop::current()->Quit(); | 38 MessageLoop::current()->Quit(); |
| 40 } | 39 } |
| 41 } | 40 } |
| 42 | 41 |
| 43 void WaitForImageLoad() { | 42 void WaitForImageLoad() { |
| 44 if (unwaited_image_loads_ == 0) { | 43 if (unwaited_image_loads_ == 0) { |
| 45 waiting_ = true; | 44 waiting_ = true; |
| 46 MessageLoop::current()->Run(); | 45 MessageLoop::current()->Run(); |
| 47 waiting_ = false; | 46 waiting_ = false; |
| 48 } | 47 } |
| 49 ASSERT_GT(unwaited_image_loads_, 0); | 48 ASSERT_GT(unwaited_image_loads_, 0); |
| 50 unwaited_image_loads_--; | 49 unwaited_image_loads_--; |
| 51 } | 50 } |
| 52 | 51 |
| 53 private: | 52 private: |
| 54 virtual void SetUp() { | 53 virtual void SetUp() { |
| 55 extensions::ExtensionTest::SetUp(); | |
| 56 file_thread_.Start(); | 54 file_thread_.Start(); |
| 57 io_thread_.Start(); | 55 io_thread_.Start(); |
| 58 } | 56 } |
| 59 | 57 |
| 60 // The number of observed image loads that have not been waited for. | 58 // The number of observed image loads that have not been waited for. |
| 61 int unwaited_image_loads_; | 59 int unwaited_image_loads_; |
| 62 | 60 |
| 63 // Whether we are currently waiting for an image load. | 61 // Whether we are currently waiting for an image load. |
| 64 bool waiting_; | 62 bool waiting_; |
| 65 | 63 |
| (...skipping 110 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 | 174 // Now re-load the icon - we should get the same result bitmap (and not the |
| 177 // default icon). | 175 // default icon). |
| 178 icon_manager.LoadIcon(profile.get(), extension.get()); | 176 icon_manager.LoadIcon(profile.get(), extension.get()); |
| 179 WaitForImageLoad(); | 177 WaitForImageLoad(); |
| 180 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); | 178 SkBitmap second_icon = icon_manager.GetIcon(extension->id()); |
| 181 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); | 179 EXPECT_FALSE(gfx::BitmapsAreEqual(second_icon, default_icon)); |
| 182 | 180 |
| 183 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); | 181 EXPECT_TRUE(gfx::BitmapsAreEqual(first_icon, second_icon)); |
| 184 } | 182 } |
| 185 #endif | 183 #endif |
| OLD | NEW |