OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include <vector> | |
7 | 6 |
8 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
9 | 8 |
10 #include "base/file_path.h" | 9 #include "base/file_path.h" |
11 #include "base/file_util.h" | 10 #include "base/file_util.h" |
12 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/scoped_nsobject.h" | 12 #include "base/scoped_nsobject.h" |
14 #include "base/scoped_ptr.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
17 | 15 |
18 namespace base { | 16 namespace base { |
19 namespace mac { | 17 namespace mac { |
20 | 18 |
21 namespace { | 19 namespace { |
22 | 20 |
23 typedef PlatformTest MacUtilTest; | 21 typedef PlatformTest MacUtilTest; |
24 | 22 |
(...skipping 20 matching lines...) Expand all Loading... |
45 EXPECT_TRUE(GetUserDirectory(NSLibraryDirectory, &library_dir)); | 43 EXPECT_TRUE(GetUserDirectory(NSLibraryDirectory, &library_dir)); |
46 EXPECT_FALSE(library_dir.empty()); | 44 EXPECT_FALSE(library_dir.empty()); |
47 } | 45 } |
48 | 46 |
49 TEST_F(MacUtilTest, TestLibraryPath) { | 47 TEST_F(MacUtilTest, TestLibraryPath) { |
50 FilePath library_dir = GetUserLibraryPath(); | 48 FilePath library_dir = GetUserLibraryPath(); |
51 // Make sure the string isn't empty. | 49 // Make sure the string isn't empty. |
52 EXPECT_FALSE(library_dir.value().empty()); | 50 EXPECT_FALSE(library_dir.value().empty()); |
53 } | 51 } |
54 | 52 |
55 TEST_F(MacUtilTest, TestGrabWindowSnapshot) { | |
56 // Launch a test window so we can take a snapshot. | |
57 NSRect frame = NSMakeRect(0, 0, 400, 400); | |
58 scoped_nsobject<NSWindow> window( | |
59 [[NSWindow alloc] initWithContentRect:frame | |
60 styleMask:NSBorderlessWindowMask | |
61 backing:NSBackingStoreBuffered | |
62 defer:NO]); | |
63 [window setBackgroundColor:[NSColor whiteColor]]; | |
64 [window makeKeyAndOrderFront:NSApp]; | |
65 | |
66 scoped_ptr<std::vector<unsigned char> > png_representation( | |
67 new std::vector<unsigned char>); | |
68 int width, height; | |
69 GrabWindowSnapshot(window, png_representation.get(), | |
70 &width, &height); | |
71 | |
72 // Copy png back into NSData object so we can make sure we grabbed a png. | |
73 scoped_nsobject<NSData> image_data( | |
74 [[NSData alloc] initWithBytes:&(*png_representation)[0] | |
75 length:png_representation->size()]); | |
76 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; | |
77 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); | |
78 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); | |
79 NSColor* color = [rep colorAtX:200 y:200]; | |
80 CGFloat red = 0, green = 0, blue = 0, alpha = 0; | |
81 [color getRed:&red green:&green blue:&blue alpha:&alpha]; | |
82 EXPECT_GE(red + green + blue, 3.0); | |
83 } | |
84 | |
85 TEST_F(MacUtilTest, TestGetAppBundlePath) { | 53 TEST_F(MacUtilTest, TestGetAppBundlePath) { |
86 FilePath out; | 54 FilePath out; |
87 | 55 |
88 // Make sure it doesn't crash. | 56 // Make sure it doesn't crash. |
89 out = GetAppBundlePath(FilePath()); | 57 out = GetAppBundlePath(FilePath()); |
90 EXPECT_TRUE(out.empty()); | 58 EXPECT_TRUE(out.empty()); |
91 | 59 |
92 // Some more invalid inputs. | 60 // Some more invalid inputs. |
93 const char* invalid_inputs[] = { | 61 const char* invalid_inputs[] = { |
94 "/", "/foo", "foo", "/foo/bar.", "foo/bar.", "/foo/bar./bazquux", | 62 "/", "/foo", "foo", "/foo/bar.", "foo/bar.", "/foo/bar./bazquux", |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EXPECT_EQ(2U, [array retainCount]); | 154 EXPECT_EQ(2U, [array retainCount]); |
187 | 155 |
188 NSObjectRelease(array); | 156 NSObjectRelease(array); |
189 EXPECT_EQ(1U, [array retainCount]); | 157 EXPECT_EQ(1U, [array retainCount]); |
190 } | 158 } |
191 | 159 |
192 } // namespace | 160 } // namespace |
193 | 161 |
194 } // namespace mac | 162 } // namespace mac |
195 } // namespace base | 163 } // namespace base |
OLD | NEW |