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

Side by Side Diff: chrome/browser/ui/cocoa/nsimage_cache_unittest.mm

Issue 5961007: Move nsimage_cache from base to app/mac. Use the app::mac namespace. Update c... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "app/mac/nsimage_cache.h"
7 #include "base/file_path.h" 8 #include "base/file_path.h"
8 #include "base/mac_util.h" 9 #include "base/mac_util.h"
9 #include "base/nsimage_cache_mac.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "chrome/common/chrome_constants.h" 11 #include "chrome/common/chrome_constants.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
14 14
15 // This tests nsimage_cache, which lives in base/. The unit test is in 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. 16 // chrome/ because it depends on having a built-up Chrome present.
17 17
18 namespace { 18 namespace {
19 19
20 class NSImageCacheTest : public PlatformTest { 20 class NSImageCacheTest : public PlatformTest {
21 public: 21 public:
22 NSImageCacheTest() { 22 NSImageCacheTest() {
23 // Look in the framework bundle for resources. 23 // Look in the framework bundle for resources.
24 FilePath path; 24 FilePath path;
25 PathService::Get(base::DIR_EXE, &path); 25 PathService::Get(base::DIR_EXE, &path);
26 path = path.Append(chrome::kFrameworkName); 26 path = path.Append(chrome::kFrameworkName);
27 mac_util::SetOverrideAppBundlePath(path); 27 mac_util::SetOverrideAppBundlePath(path);
28 } 28 }
29 virtual ~NSImageCacheTest() { 29 virtual ~NSImageCacheTest() {
30 mac_util::SetOverrideAppBundle(nil); 30 mac_util::SetOverrideAppBundle(nil);
31 } 31 }
32 }; 32 };
33 33
34 TEST_F(NSImageCacheTest, LookupFound) { 34 TEST_F(NSImageCacheTest, LookupFound) {
35 EXPECT_TRUE(nsimage_cache::ImageNamed(@"back_Template.pdf") != nil) 35 EXPECT_TRUE(app::mac::GetCachedImageWithName(@"back_Template.pdf") != nil)
36 << "Failed to find the toolbar image?"; 36 << "Failed to find the toolbar image?";
37 } 37 }
38 38
39 TEST_F(NSImageCacheTest, LookupCached) { 39 TEST_F(NSImageCacheTest, LookupCached) {
40 EXPECT_EQ(nsimage_cache::ImageNamed(@"back_Template.pdf"), 40 EXPECT_EQ(app::mac::GetCachedImageWithName(@"back_Template.pdf"),
41 nsimage_cache::ImageNamed(@"back_Template.pdf")) 41 app::mac::GetCachedImageWithName(@"back_Template.pdf"))
42 << "Didn't get the same NSImage back?"; 42 << "Didn't get the same NSImage back?";
43 } 43 }
44 44
45 TEST_F(NSImageCacheTest, LookupMiss) { 45 TEST_F(NSImageCacheTest, LookupMiss) {
46 EXPECT_TRUE(nsimage_cache::ImageNamed(@"should_not.exist") == nil) 46 EXPECT_TRUE(app::mac::GetCachedImageWithName(@"should_not.exist") == nil)
47 << "There shouldn't be an image with this name?"; 47 << "There shouldn't be an image with this name?";
48 } 48 }
49 49
50 TEST_F(NSImageCacheTest, LookupFoundAndClear) { 50 TEST_F(NSImageCacheTest, LookupFoundAndClear) {
51 NSImage *first = nsimage_cache::ImageNamed(@"back_Template.pdf"); 51 NSImage *first = app::mac::GetCachedImageWithName(@"back_Template.pdf");
52 // Hang on to the first image so that the second one doesn't get allocated 52 // Hang on to the first image so that the second one doesn't get allocated
53 // in the same location by (bad) luck. 53 // in the same location by (bad) luck.
54 [[first retain] autorelease]; 54 [[first retain] autorelease];
55 EXPECT_TRUE(first != nil) 55 EXPECT_TRUE(first != nil)
56 << "Failed to find the toolbar image?"; 56 << "Failed to find the toolbar image?";
57 nsimage_cache::Clear(); 57 app::mac::ClearCachedImages();
58 NSImage *second = nsimage_cache::ImageNamed(@"back_Template.pdf"); 58 NSImage *second = app::mac::GetCachedImageWithName(@"back_Template.pdf");
59 EXPECT_TRUE(second != nil) 59 EXPECT_TRUE(second != nil)
60 << "Failed to find the toolbar image...again?"; 60 << "Failed to find the toolbar image...again?";
61 EXPECT_NE(second, first) 61 EXPECT_NE(second, first)
62 << "how'd we get the same image after a cache clear?"; 62 << "how'd we get the same image after a cache clear?";
63 } 63 }
64 64
65 TEST_F(NSImageCacheTest, AutoTemplating) { 65 TEST_F(NSImageCacheTest, AutoTemplating) {
66 NSImage *templateImage = nsimage_cache::ImageNamed(@"back_Template.pdf"); 66 NSImage *templateImage =
67 app::mac::GetCachedImageWithName(@"back_Template.pdf");
67 EXPECT_TRUE([templateImage isTemplate] == YES) 68 EXPECT_TRUE([templateImage isTemplate] == YES)
68 << "Image ending in 'Template' should be marked as being a template"; 69 << "Image ending in 'Template' should be marked as being a template";
69 NSImage *nonTemplateImage = nsimage_cache::ImageNamed(@"aliasCursor.png"); 70 NSImage *nonTemplateImage =
71 app::mac::GetCachedImageWithName(@"aliasCursor.png");
70 EXPECT_FALSE([nonTemplateImage isTemplate] == YES) 72 EXPECT_FALSE([nonTemplateImage isTemplate] == YES)
71 << "Image not ending in 'Template' should not be marked as being a " 73 << "Image not ending in 'Template' should not be marked as being a "
72 "template"; 74 "template";
73 } 75 }
74 76
75 } // namespace 77 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/notifications/balloon_controller.mm ('k') | chrome/browser/ui/cocoa/reload_button.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698