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

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

Issue 10957031: GrabWindowSnapshotTest.TestGrabWindowSnapshot fails in HighDPI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 #if !defined(MAC_OS_X_VERSION_10_7) || \
15 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
16
17 @interface NSWindow (LionAPI)
18 - (CGFloat)backingScaleFactor;
19 @end
20
21 #endif // 10.7
22
14 namespace chrome { 23 namespace chrome {
15 namespace { 24 namespace {
16 25
17 typedef PlatformTest GrabWindowSnapshotTest; 26 typedef PlatformTest GrabWindowSnapshotTest;
18 27
19 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) { 28 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) {
20 // Launch a test window so we can take a snapshot. 29 // Launch a test window so we can take a snapshot.
21 NSRect frame = NSMakeRect(0, 0, 400, 400); 30 NSRect frame = NSMakeRect(0, 0, 400, 400);
22 scoped_nsobject<NSWindow> window( 31 scoped_nsobject<NSWindow> window(
23 [[NSWindow alloc] initWithContentRect:frame 32 [[NSWindow alloc] initWithContentRect:frame
24 styleMask:NSBorderlessWindowMask 33 styleMask:NSBorderlessWindowMask
25 backing:NSBackingStoreBuffered 34 backing:NSBackingStoreBuffered
26 defer:NO]); 35 defer:NO]);
27 [window setBackgroundColor:[NSColor whiteColor]]; 36 [window setBackgroundColor:[NSColor whiteColor]];
28 [window makeKeyAndOrderFront:NSApp]; 37 [window makeKeyAndOrderFront:NSApp];
29 38
30 scoped_ptr<std::vector<unsigned char> > png_representation( 39 scoped_ptr<std::vector<unsigned char> > png_representation(
31 new std::vector<unsigned char>); 40 new std::vector<unsigned char>);
32 gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height); 41 gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height);
33 EXPECT_TRUE(internal::GrabWindowSnapshot(window, png_representation.get(), 42 EXPECT_TRUE(internal::GrabWindowSnapshot(window, png_representation.get(),
34 bounds)); 43 bounds));
35 44
36 // Copy png back into NSData object so we can make sure we grabbed a png. 45 // Copy png back into NSData object so we can make sure we grabbed a png.
37 scoped_nsobject<NSData> image_data( 46 scoped_nsobject<NSData> image_data(
38 [[NSData alloc] initWithBytes:&(*png_representation)[0] 47 [[NSData alloc] initWithBytes:&(*png_representation)[0]
39 length:png_representation->size()]); 48 length:png_representation->size()]);
40 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; 49 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()];
41 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); 50 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]);
42 EXPECT_TRUE(CGImageGetWidth([rep CGImage]) == 400); 51 CGFloat scaleFactor = 1.0f;
43 NSColor* color = [rep colorAtX:200 y:200]; 52 if ([window respondsToSelector:@selector(backingScaleFactor)])
53 scaleFactor = [window backingScaleFactor];
54 EXPECT_EQ(400UL * scaleFactor, CGImageGetWidth([rep CGImage]));
Nico 2012/09/21 03:37:44 Do you need the UL? It's multiplied by a float, th
dhollowa 2012/09/21 04:06:51 Ah yes, I'd converted to UL prior to adding the sc
55 NSColor* color = [rep colorAtX:200 * scaleFactor y:200 * scaleFactor];
44 CGFloat red = 0, green = 0, blue = 0, alpha = 0; 56 CGFloat red = 0, green = 0, blue = 0, alpha = 0;
45 [color getRed:&red green:&green blue:&blue alpha:&alpha]; 57 [color getRed:&red green:&green blue:&blue alpha:&alpha];
46 EXPECT_GE(red + green + blue, 3.0); 58 EXPECT_GE(red + green + blue, 3.0);
47 } 59 }
48 60
49 } // namespace 61 } // namespace
50 } // namespace chrome 62 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698