Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(888)

Side by Side Diff: chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm

Issue 10826011: chrome: Put window_snapshot into chrome namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #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 "testing/platform_test.h" 11 #include "testing/platform_test.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 13
14 namespace browser { 14 namespace chrome {
15 namespace { 15 namespace {
16 16
17 typedef PlatformTest GrabWindowSnapshotTest; 17 typedef PlatformTest GrabWindowSnapshotTest;
18 18
19 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) { 19 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) {
20 // Launch a test window so we can take a snapshot. 20 // Launch a test window so we can take a snapshot.
21 NSRect frame = NSMakeRect(0, 0, 400, 400); 21 NSRect frame = NSMakeRect(0, 0, 400, 400);
22 scoped_nsobject<NSWindow> window( 22 scoped_nsobject<NSWindow> window(
23 [[NSWindow alloc] initWithContentRect:frame 23 [[NSWindow alloc] initWithContentRect:frame
24 styleMask:NSBorderlessWindowMask 24 styleMask:NSBorderlessWindowMask
25 backing:NSBackingStoreBuffered 25 backing:NSBackingStoreBuffered
26 defer:NO]); 26 defer:NO]);
27 [window setBackgroundColor:[NSColor whiteColor]]; 27 [window setBackgroundColor:[NSColor whiteColor]];
28 [window makeKeyAndOrderFront:NSApp]; 28 [window makeKeyAndOrderFront:NSApp];
29 29
30 scoped_ptr<std::vector<unsigned char> > png_representation( 30 scoped_ptr<std::vector<unsigned char> > png_representation(
31 new std::vector<unsigned char>); 31 new std::vector<unsigned char>);
32 gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height); 32 gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height);
33 EXPECT_TRUE(browser::GrabWindowSnapshot(window, png_representation.get(), 33 EXPECT_TRUE(GrabWindowSnapshot(window, png_representation.get(), bounds));
34 bounds));
35 34
36 // Copy png back into NSData object so we can make sure we grabbed a png. 35 // Copy png back into NSData object so we can make sure we grabbed a png.
37 scoped_nsobject<NSData> image_data( 36 scoped_nsobject<NSData> image_data(
38 [[NSData alloc] initWithBytes:&(*png_representation)[0] 37 [[NSData alloc] initWithBytes:&(*png_representation)[0]
39 length:png_representation->size()]); 38 length:png_representation->size()]);
40 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; 39 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()];
41 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); 40 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]);
42 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); 41 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400);
43 NSColor* color = [rep colorAtX:200 y:200]; 42 NSColor* color = [rep colorAtX:200 y:200];
44 CGFloat red = 0, green = 0, blue = 0, alpha = 0; 43 CGFloat red = 0, green = 0, blue = 0, alpha = 0;
45 [color getRed:&red green:&green blue:&blue alpha:&alpha]; 44 [color getRed:&red green:&green blue:&blue alpha:&alpha];
46 EXPECT_GE(red + green + blue, 3.0); 45 EXPECT_GE(red + green + blue, 3.0);
47 } 46 }
48 47
49 } // namespace 48 } // namespace
50 } // namespace browser 49 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/window_snapshot/window_snapshot_mac.mm ('k') | chrome/browser/ui/window_snapshot/window_snapshot_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698