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