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

Unified Diff: chrome/browser/extensions/image_loading_tracker_unittest.cc

Issue 12213093: Remove ImageLoadingTracker class (Closed) Base URL: https://git.chromium.org/chromium/src.git@Issue_163929
Patch Set: Fix merge conflict Created 7 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/image_loading_tracker.cc ('k') | chrome/browser/extensions/tab_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/image_loading_tracker_unittest.cc
diff --git a/chrome/browser/extensions/image_loading_tracker_unittest.cc b/chrome/browser/extensions/image_loading_tracker_unittest.cc
deleted file mode 100644
index f722304ee15a0a1af1f2d642928bcbe192418bbd..0000000000000000000000000000000000000000
--- a/chrome/browser/extensions/image_loading_tracker_unittest.cc
+++ /dev/null
@@ -1,248 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/extensions/image_loading_tracker.h"
-
-#include "base/json/json_file_value_serializer.h"
-#include "base/message_loop.h"
-#include "base/path_service.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/extensions/extension.h"
-#include "chrome/common/extensions/extension_constants.h"
-#include "chrome/common/extensions/extension_icon_set.h"
-#include "chrome/common/extensions/extension_resource.h"
-#include "chrome/common/extensions/manifest.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/test/test_browser_thread.h"
-#include "grit/component_extension_resources.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/gfx/image/image.h"
-#include "ui/gfx/image/image_skia.h"
-#include "ui/gfx/size.h"
-
-using content::BrowserThread;
-using extensions::Extension;
-using extensions::Manifest;
-
-class ImageLoadingTrackerTest : public testing::Test,
- public ImageLoadingTracker::Observer {
- public:
- ImageLoadingTrackerTest()
- : image_loaded_count_(0),
- quit_in_image_loaded_(false),
- ui_thread_(BrowserThread::UI, &ui_loop_),
- file_thread_(BrowserThread::FILE),
- io_thread_(BrowserThread::IO) {
- }
-
- virtual void OnImageLoaded(const gfx::Image& image,
- const std::string& extension_id,
- int index) OVERRIDE {
- image_loaded_count_++;
- if (quit_in_image_loaded_)
- MessageLoop::current()->Quit();
- image_ = image;
- }
-
- void WaitForImageLoad() {
- quit_in_image_loaded_ = true;
- MessageLoop::current()->Run();
- quit_in_image_loaded_ = false;
- }
-
- int image_loaded_count() {
- int result = image_loaded_count_;
- image_loaded_count_ = 0;
- return result;
- }
-
- scoped_refptr<Extension> CreateExtension(const char* name,
- Manifest::Location location) {
- // Create and load an extension.
- base::FilePath test_file;
- if (!PathService::Get(chrome::DIR_TEST_DATA, &test_file)) {
- EXPECT_FALSE(true);
- return NULL;
- }
- test_file = test_file.AppendASCII("extensions")
- .AppendASCII(name);
- int error_code = 0;
- std::string error;
- JSONFileValueSerializer serializer(test_file.AppendASCII("app.json"));
- scoped_ptr<DictionaryValue> valid_value(
- static_cast<DictionaryValue*>(serializer.Deserialize(&error_code,
- &error)));
- EXPECT_EQ(0, error_code) << error;
- if (error_code != 0)
- return NULL;
-
- EXPECT_TRUE(valid_value.get());
- if (!valid_value.get())
- return NULL;
-
- if (location == Manifest::COMPONENT) {
- if (!PathService::Get(chrome::DIR_RESOURCES, &test_file)) {
- EXPECT_FALSE(true);
- return NULL;
- }
- test_file = test_file.AppendASCII(name);
- }
- return Extension::Create(test_file, location, *valid_value,
- Extension::NO_FLAGS, &error);
- }
-
- gfx::Image image_;
-
- private:
- virtual void SetUp() {
- file_thread_.Start();
- io_thread_.Start();
- }
-
- int image_loaded_count_;
- bool quit_in_image_loaded_;
- MessageLoop ui_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
- content::TestBrowserThread io_thread_;
-};
-
-// Tests asking ImageLoadingTracker to cache pushes the result to the Extension.
-TEST_F(ImageLoadingTrackerTest, Cache) {
- scoped_refptr<Extension> extension(CreateExtension(
- "image_loading_tracker", Manifest::INVALID_LOCATION));
- ASSERT_TRUE(extension.get() != NULL);
-
- ExtensionResource image_resource =
- extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH,
- ExtensionIconSet::MATCH_EXACTLY);
- gfx::Size max_size(extension_misc::EXTENSION_ICON_SMALLISH,
- extension_misc::EXTENSION_ICON_SMALLISH);
- ImageLoadingTracker loader(this);
- loader.LoadImage(extension.get(),
- image_resource,
- max_size,
- ImageLoadingTracker::CACHE);
-
- // The image isn't cached, so we should not have received notification.
- EXPECT_EQ(0, image_loaded_count());
-
- WaitForImageLoad();
-
- // We should have gotten the image.
- EXPECT_EQ(1, image_loaded_count());
-
- // Check that the image was loaded.
- EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
- image_.ToSkBitmap()->width());
-
- // The image should be cached in the Extension.
- EXPECT_TRUE(extension->HasCachedImage(image_resource, max_size));
-
- // Make sure the image is in the extension.
- EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
- extension->GetCachedImage(image_resource, max_size).width());
-
- // Ask the tracker for the image again, this should call us back immediately.
- loader.LoadImage(extension.get(),
- image_resource,
- max_size,
- ImageLoadingTracker::CACHE);
- // We should have gotten the image.
- EXPECT_EQ(1, image_loaded_count());
-
- // Check that the image was loaded.
- EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
- image_.ToSkBitmap()->width());
-}
-
-// Tests deleting an extension while waiting for the image to load doesn't cause
-// problems.
-TEST_F(ImageLoadingTrackerTest, DeleteExtensionWhileWaitingForCache) {
- scoped_refptr<Extension> extension(CreateExtension(
- "image_loading_tracker", Manifest::INVALID_LOCATION));
- ASSERT_TRUE(extension.get() != NULL);
-
- ExtensionResource image_resource =
- extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH,
- ExtensionIconSet::MATCH_EXACTLY);
- ImageLoadingTracker loader(this);
- loader.LoadImage(extension.get(),
- image_resource,
- gfx::Size(extension_misc::EXTENSION_ICON_SMALLISH,
- extension_misc::EXTENSION_ICON_SMALLISH),
- ImageLoadingTracker::CACHE);
-
- // The image isn't cached, so we should not have received notification.
- EXPECT_EQ(0, image_loaded_count());
-
- // Send out notification the extension was uninstalled.
- extensions::UnloadedExtensionInfo details(extension.get(),
- extension_misc::UNLOAD_REASON_UNINSTALL);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_EXTENSION_UNLOADED,
- content::NotificationService::AllSources(),
- content::Details<extensions::UnloadedExtensionInfo>(&details));
-
- // Chuck the extension, that way if anyone tries to access it we should crash
- // or get valgrind errors.
- extension = NULL;
-
- WaitForImageLoad();
-
- // Even though we deleted the extension, we should still get the image.
- // We should still have gotten the image.
- EXPECT_EQ(1, image_loaded_count());
-
- // Check that the image was loaded.
- EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
- image_.ToSkBitmap()->width());
-}
-
-// Tests loading multiple dimensions of the same image.
-TEST_F(ImageLoadingTrackerTest, MultipleImages) {
- scoped_refptr<Extension> extension(CreateExtension(
- "image_loading_tracker", Manifest::INVALID_LOCATION));
- ASSERT_TRUE(extension.get() != NULL);
-
- std::vector<ImageLoadingTracker::ImageRepresentation> info_list;
- int sizes[] = {extension_misc::EXTENSION_ICON_SMALLISH,
- extension_misc::EXTENSION_ICON_BITTY};
- for (size_t i = 0; i < arraysize(sizes); ++i) {
- ExtensionResource resource =
- extension->GetIconResource(sizes[i], ExtensionIconSet::MATCH_EXACTLY);
- info_list.push_back(ImageLoadingTracker::ImageRepresentation(
- resource,
- ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER,
- gfx::Size(sizes[i], sizes[i]),
- ui::SCALE_FACTOR_NONE));
- }
-
- ImageLoadingTracker loader(this);
- loader.LoadImages(extension.get(), info_list, ImageLoadingTracker::CACHE);
-
- // The image isn't cached, so we should not have received notification.
- EXPECT_EQ(0, image_loaded_count());
-
- WaitForImageLoad();
-
- // We should have gotten the image.
- EXPECT_EQ(1, image_loaded_count());
-
- // Check that all images were loaded.
- std::vector<gfx::ImageSkiaRep> image_reps =
- image_.ToImageSkia()->image_reps();
- ASSERT_EQ(2u, image_reps.size());
- const gfx::ImageSkiaRep* img_rep1 = &image_reps[0];
- const gfx::ImageSkiaRep* img_rep2 = &image_reps[1];
- if (img_rep1->pixel_width() > img_rep2->pixel_width()) {
- std::swap(img_rep1, img_rep2);
- }
- EXPECT_EQ(extension_misc::EXTENSION_ICON_BITTY,
- img_rep1->pixel_width());
- EXPECT_EQ(extension_misc::EXTENSION_ICON_SMALLISH,
- img_rep2->pixel_width());
-}
« no previous file with comments | « chrome/browser/extensions/image_loading_tracker.cc ('k') | chrome/browser/extensions/tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698