OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/memory/scoped_nsobject.h" |
10 #include "base/memory/scoped_ptr.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" |
11 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
12 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
13 | 16 |
14 namespace chrome { | 17 namespace chrome { |
15 namespace { | 18 namespace { |
16 | 19 |
17 typedef PlatformTest GrabWindowSnapshotTest; | 20 typedef PlatformTest GrabWindowSnapshotTest; |
18 | 21 |
19 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) { | 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 |
20 // Launch a test window so we can take a snapshot. | 27 // Launch a test window so we can take a snapshot. |
21 NSRect frame = NSMakeRect(0, 0, 400, 400); | 28 NSRect frame = NSMakeRect(0, 0, 400, 400); |
22 scoped_nsobject<NSWindow> window( | 29 scoped_nsobject<NSWindow> window( |
23 [[NSWindow alloc] initWithContentRect:frame | 30 [[NSWindow alloc] initWithContentRect:frame |
24 styleMask:NSBorderlessWindowMask | 31 styleMask:NSBorderlessWindowMask |
25 backing:NSBackingStoreBuffered | 32 backing:NSBackingStoreBuffered |
26 defer:NO]); | 33 defer:NO]); |
27 [window setBackgroundColor:[NSColor whiteColor]]; | 34 [window setBackgroundColor:[NSColor whiteColor]]; |
28 [window makeKeyAndOrderFront:NSApp]; | 35 [window makeKeyAndOrderFront:NSApp]; |
29 | 36 |
(...skipping 10 matching lines...) Expand all Loading... |
40 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); | 47 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); |
41 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); | 48 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); |
42 NSColor* color = [rep colorAtX:200 y:200]; | 49 NSColor* color = [rep colorAtX:200 y:200]; |
43 CGFloat red = 0, green = 0, blue = 0, alpha = 0; | 50 CGFloat red = 0, green = 0, blue = 0, alpha = 0; |
44 [color getRed:&red green:&green blue:&blue alpha:&alpha]; | 51 [color getRed:&red green:&green blue:&blue alpha:&alpha]; |
45 EXPECT_GE(red + green + blue, 3.0); | 52 EXPECT_GE(red + green + blue, 3.0); |
46 } | 53 } |
47 | 54 |
48 } // namespace | 55 } // namespace |
49 } // namespace chrome | 56 } // namespace chrome |
OLD | NEW |