OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #include "ui/window_snapshot/window_snapshot.h" | |
6 | |
7 #import <Cocoa/Cocoa.h> | |
8 | |
9 #include "base/memory/scoped_nsobject.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "testing/platform_test.h" | |
12 #include "ui/gfx/rect.h" | |
13 | |
14 namespace ui { | |
15 namespace { | |
16 | |
17 typedef PlatformTest GrabWindowSnapshotTest; | |
18 | |
19 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) { | |
20 // Launch a test window so we can take a snapshot. | |
21 NSRect frame = NSMakeRect(0, 0, 400, 400); | |
22 scoped_nsobject<NSWindow> window( | |
23 [[NSWindow alloc] initWithContentRect:frame | |
24 styleMask:NSBorderlessWindowMask | |
25 backing:NSBackingStoreBuffered | |
26 defer:NO]); | |
27 [window setBackgroundColor:[NSColor whiteColor]]; | |
28 [window makeKeyAndOrderFront:NSApp]; | |
29 | |
30 scoped_ptr<std::vector<unsigned char> > png_representation( | |
31 new std::vector<unsigned char>); | |
32 gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height); | |
33 EXPECT_TRUE(GrabWindowSnapshot(window, png_representation.get(), bounds)); | |
34 | |
35 // Copy png back into NSData object so we can make sure we grabbed a png. | |
36 scoped_nsobject<NSData> image_data( | |
37 [[NSData alloc] initWithBytes:&(*png_representation)[0] | |
38 length:png_representation->size()]); | |
39 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; | |
40 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); | |
41 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); | |
42 NSColor* color = [rep colorAtX:200 y:200]; | |
43 CGFloat red = 0, green = 0, blue = 0, alpha = 0; | |
44 [color getRed:&red green:&green blue:&blue alpha:&alpha]; | |
45 EXPECT_GE(red + green + blue, 3.0); | |
46 } | |
47 | |
48 } // namespace | |
49 } // namespace ui | |
OLD | NEW |