diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 20:59:32 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 20:59:32 +0000 |
commit | 655345e0991a974109e0f2656f6e00afbe8d9e59 (patch) | |
tree | 7fcca7714b4957f9efed3496e863c4f15b48941a /chrome/browser/cocoa/nsimage_cache_unittest.mm | |
parent | 5ce8cbcbf65f801bc7f52cc035027d0eb907add5 (diff) | |
download | chromium_src-655345e0991a974109e0f2656f6e00afbe8d9e59.zip chromium_src-655345e0991a974109e0f2656f6e00afbe8d9e59.tar.gz chromium_src-655345e0991a974109e0f2656f6e00afbe8d9e59.tar.bz2 |
Added an helper namespace that provides fetches images from the app bundle and caches them, line NSImage imageNamed: but lets us control the bundle that's checked.
Unittest for the helper.
Updated the current places that use +[NSImage imageNamed:] to use our cache helper.
BUG=none
TEST=All the ui images still load.
Review URL: http://codereview.chromium.org/149393
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/nsimage_cache_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/nsimage_cache_unittest.mm | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/nsimage_cache_unittest.mm b/chrome/browser/cocoa/nsimage_cache_unittest.mm new file mode 100644 index 0000000..149fb60 --- /dev/null +++ b/chrome/browser/cocoa/nsimage_cache_unittest.mm @@ -0,0 +1,55 @@ +// Copyright (c) 2009 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. + +#import <Cocoa/Cocoa.h> + +#include "base/file_path.h" +#include "base/mac_util.h" +#include "base/path_service.h" +#include "chrome/browser/cocoa/nsimage_cache.h" +#include "chrome/common/mac_app_names.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class NSImageCacheTest : public testing::Test { + public: + NSImageCacheTest() { + // Look in the Chromium app bundle for resources. + FilePath path; + PathService::Get(base::DIR_EXE, &path); + path = path.AppendASCII(MAC_BROWSER_APP_NAME); + mac_util::SetOverrideAppBundlePath(path); + } + virtual ~NSImageCacheTest() { + mac_util::SetOverrideAppBundle(nil); + } +}; + +TEST_F(NSImageCacheTest, LookupFound) { + EXPECT_TRUE(nsimage_cache::ImageNamed(@"back.pdf") != nil) + << "Failed to find the toolbar image?"; +} + +TEST_F(NSImageCacheTest, LookupCached) { + EXPECT_EQ(nsimage_cache::ImageNamed(@"back.pdf"), + nsimage_cache::ImageNamed(@"back.pdf")) + << "Didn't get the same NSImage back?"; +} + +TEST_F(NSImageCacheTest, LookupMiss) { + EXPECT_TRUE(nsimage_cache::ImageNamed(@"should_not.exist") == nil) + << "There shouldn't be an image with this name?"; +} + +TEST_F(NSImageCacheTest, LookupFoundAndClear) { + NSImage *first = nsimage_cache::ImageNamed(@"back.pdf"); + EXPECT_TRUE(first != nil) + << "Failed to find the toolbar image?"; + nsimage_cache::Clear(); + EXPECT_NE(first, nsimage_cache::ImageNamed(@"back.pdf")) + << "how'd we get the same image after a cache clear?"; +} + +} // namespace |