summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/nsimage_cache_unittest.mm
blob: 9ecf7472f57f4ebb03e40d15ce0fb0d68182687b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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/nsimage_cache_mac.h"
#include "base/path_service.h"
#include "chrome/common/mac_app_names.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"

// This tests nsimage_cache, which lives in base/.  The unit test is in
// chrome/ because it depends on having a built-up Chrome present.

namespace {

class NSImageCacheTest : public PlatformTest {
 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_Template.pdf") != nil)
      << "Failed to find the toolbar image?";
}

TEST_F(NSImageCacheTest, LookupCached) {
  EXPECT_EQ(nsimage_cache::ImageNamed(@"back_Template.pdf"),
            nsimage_cache::ImageNamed(@"back_Template.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_Template.pdf");
  EXPECT_TRUE(first != nil)
      << "Failed to find the toolbar image?";
  nsimage_cache::Clear();
  EXPECT_NE(first, nsimage_cache::ImageNamed(@"back_Template.pdf"))
      << "how'd we get the same image after a cache clear?";
}

}  // namespace