| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Cocoa/Cocoa.h> | |
| 6 | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/mac/mac_util.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "chrome/common/chrome_constants.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "testing/platform_test.h" | |
| 13 #include "ui/gfx/mac/nsimage_cache.h" | |
| 14 | |
| 15 // This tests nsimage_cache, which lives in base/. The unit test is in | |
| 16 // chrome/ because it depends on having a built-up Chrome present. | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 class NSImageCacheTest : public PlatformTest { | |
| 21 public: | |
| 22 }; | |
| 23 | |
| 24 TEST_F(NSImageCacheTest, LookupFound) { | |
| 25 EXPECT_TRUE(gfx::GetCachedImageWithName(@"product_logo_32.png") != nil) | |
| 26 << "Failed to find the toolbar image?"; | |
| 27 } | |
| 28 | |
| 29 TEST_F(NSImageCacheTest, LookupCached) { | |
| 30 EXPECT_EQ(gfx::GetCachedImageWithName(@"product_logo_32.png"), | |
| 31 gfx::GetCachedImageWithName(@"product_logo_32.png")) | |
| 32 << "Didn't get the same NSImage back?"; | |
| 33 } | |
| 34 | |
| 35 TEST_F(NSImageCacheTest, LookupMiss) { | |
| 36 EXPECT_TRUE(gfx::GetCachedImageWithName(@"should_not.exist") == nil) | |
| 37 << "There shouldn't be an image with this name?"; | |
| 38 } | |
| 39 | |
| 40 TEST_F(NSImageCacheTest, LookupFoundAndClear) { | |
| 41 NSImage *first = gfx::GetCachedImageWithName(@"product_logo_32.png"); | |
| 42 // Hang on to the first image so that the second one doesn't get allocated | |
| 43 // in the same location by (bad) luck. | |
| 44 [[first retain] autorelease]; | |
| 45 EXPECT_TRUE(first != nil) | |
| 46 << "Failed to find the toolbar image?"; | |
| 47 gfx::ClearCachedImages(); | |
| 48 NSImage *second = gfx::GetCachedImageWithName(@"product_logo_32.png"); | |
| 49 EXPECT_TRUE(second != nil) | |
| 50 << "Failed to find the toolbar image...again?"; | |
| 51 EXPECT_NE(second, first) | |
| 52 << "how'd we get the same image after a cache clear?"; | |
| 53 } | |
| 54 | |
| 55 TEST_F(NSImageCacheTest, AutoTemplating) { | |
| 56 NSImage *templateImage = | |
| 57 gfx::GetCachedImageWithName(@"find_next_Template.pdf"); | |
| 58 EXPECT_TRUE([templateImage isTemplate] == YES) | |
| 59 << "Image ending in 'Template' should be marked as being a template"; | |
| 60 NSImage *nonTemplateImage = | |
| 61 gfx::GetCachedImageWithName(@"aliasCursor.png"); | |
| 62 EXPECT_FALSE([nonTemplateImage isTemplate] == YES) | |
| 63 << "Image not ending in 'Template' should not be marked as being a " | |
| 64 "template"; | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| OLD | NEW |