OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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> |
| 6 #include <vector> |
| 7 |
5 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
6 | 9 |
7 #include <ApplicationServices/ApplicationServices.h> | |
8 | |
9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/scoped_nsobject.h" |
| 12 #include "base/scoped_ptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
12 | 15 |
13 typedef PlatformTest MacUtilTest; | 16 typedef PlatformTest MacUtilTest; |
14 | 17 |
15 TEST_F(MacUtilTest, TestFSRef) { | 18 TEST_F(MacUtilTest, TestFSRef) { |
16 FSRef ref; | 19 FSRef ref; |
17 std::string path("/System/Library"); | 20 std::string path("/System/Library"); |
18 | 21 |
19 ASSERT_TRUE(mac_util::FSRefFromPath(path, &ref)); | 22 ASSERT_TRUE(mac_util::FSRefFromPath(path, &ref)); |
20 EXPECT_EQ(path, mac_util::PathFromFSRef(ref)); | 23 EXPECT_EQ(path, mac_util::PathFromFSRef(ref)); |
21 } | 24 } |
22 | 25 |
23 TEST_F(MacUtilTest, TestLibraryPath) { | 26 TEST_F(MacUtilTest, TestLibraryPath) { |
24 FilePath library_dir = mac_util::GetUserLibraryPath(); | 27 FilePath library_dir = mac_util::GetUserLibraryPath(); |
25 // Make sure the string isn't empty. | 28 // Make sure the string isn't empty. |
26 EXPECT_FALSE(library_dir.value().empty()); | 29 EXPECT_FALSE(library_dir.value().empty()); |
27 } | 30 } |
| 31 |
| 32 TEST_F(MacUtilTest, TestGrabWindowSnapshot) { |
| 33 // Launch a test window so we can take a snapshot. |
| 34 [NSApplication sharedApplication]; |
| 35 NSRect frame = NSMakeRect(0, 0, 400, 400); |
| 36 scoped_nsobject<NSWindow> window( |
| 37 [[NSWindow alloc] initWithContentRect:frame |
| 38 styleMask:NSBorderlessWindowMask |
| 39 backing:NSBackingStoreBuffered |
| 40 defer:NO]); |
| 41 [window setBackgroundColor:[NSColor whiteColor]]; |
| 42 [window makeKeyAndOrderFront:NSApp]; |
| 43 |
| 44 scoped_ptr<std::vector<unsigned char> > png_representation( |
| 45 new std::vector<unsigned char>); |
| 46 mac_util::GrabWindowSnapshot(window, png_representation.get()); |
| 47 |
| 48 // Copy png back into NSData object so we can make sure we grabbed a png. |
| 49 scoped_nsobject<NSData> image_data( |
| 50 [[NSData alloc] initWithBytes:&(*png_representation)[0] |
| 51 length:png_representation->size()]); |
| 52 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; |
| 53 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); |
| 54 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); |
| 55 NSColor* color = [rep colorAtX:200 y:200]; |
| 56 CGFloat red = 0, green = 0, blue = 0, alpha = 0; |
| 57 [color getRed:&red green:&green blue:&blue alpha:&alpha]; |
| 58 EXPECT_GE(red + green + blue, 3.0); |
| 59 } |
OLD | NEW |