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

Side by Side Diff: ui/snapshot/snapshot_mac_unittest.mm

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 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
« no previous file with comments | « ui/snapshot/snapshot_aura_unittest.cc ('k') | ui/surface/transport_dib_posix.cc » ('j') | 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 "ui/snapshot/snapshot.h" 5 #include "ui/snapshot/snapshot.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include <memory>
10
9 #include "base/mac/scoped_nsobject.h" 11 #include "base/mac/scoped_nsobject.h"
10 #include "base/mac/sdk_forward_declarations.h" 12 #include "base/mac/sdk_forward_declarations.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
13 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
14 15
15 namespace ui { 16 namespace ui {
16 namespace { 17 namespace {
17 18
18 typedef PlatformTest GrabWindowSnapshotTest; 19 typedef PlatformTest GrabWindowSnapshotTest;
19 20
20 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) { 21 TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) {
21 // Launch a test window so we can take a snapshot. 22 // Launch a test window so we can take a snapshot.
22 NSRect frame = NSMakeRect(0, 0, 400, 400); 23 NSRect frame = NSMakeRect(0, 0, 400, 400);
23 base::scoped_nsobject<NSWindow> window( 24 base::scoped_nsobject<NSWindow> window(
24 [[NSWindow alloc] initWithContentRect:frame 25 [[NSWindow alloc] initWithContentRect:frame
25 styleMask:NSBorderlessWindowMask 26 styleMask:NSBorderlessWindowMask
26 backing:NSBackingStoreBuffered 27 backing:NSBackingStoreBuffered
27 defer:NO]); 28 defer:NO]);
28 [window setBackgroundColor:[NSColor whiteColor]]; 29 [window setBackgroundColor:[NSColor whiteColor]];
29 [window makeKeyAndOrderFront:NSApp]; 30 [window makeKeyAndOrderFront:NSApp];
30 31
31 scoped_ptr<std::vector<unsigned char> > png_representation( 32 std::unique_ptr<std::vector<unsigned char>> png_representation(
32 new std::vector<unsigned char>); 33 new std::vector<unsigned char>);
33 gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height); 34 gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height);
34 EXPECT_TRUE(ui::GrabWindowSnapshot(window, png_representation.get(), 35 EXPECT_TRUE(ui::GrabWindowSnapshot(window, png_representation.get(),
35 bounds)); 36 bounds));
36 37
37 // Copy png back into NSData object so we can make sure we grabbed a png. 38 // Copy png back into NSData object so we can make sure we grabbed a png.
38 base::scoped_nsobject<NSData> image_data( 39 base::scoped_nsobject<NSData> image_data(
39 [[NSData alloc] initWithBytes:&(*png_representation)[0] 40 [[NSData alloc] initWithBytes:&(*png_representation)[0]
40 length:png_representation->size()]); 41 length:png_representation->size()]);
41 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()]; 42 NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()];
42 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]); 43 EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]);
43 CGFloat scaleFactor = 1.0f; 44 CGFloat scaleFactor = 1.0f;
44 if ([window respondsToSelector:@selector(backingScaleFactor)]) 45 if ([window respondsToSelector:@selector(backingScaleFactor)])
45 scaleFactor = [window backingScaleFactor]; 46 scaleFactor = [window backingScaleFactor];
46 EXPECT_EQ(400 * scaleFactor, CGImageGetWidth([rep CGImage])); 47 EXPECT_EQ(400 * scaleFactor, CGImageGetWidth([rep CGImage]));
47 NSColor* color = [rep colorAtX:200 * scaleFactor y:200 * scaleFactor]; 48 NSColor* color = [rep colorAtX:200 * scaleFactor y:200 * scaleFactor];
48 CGFloat red = 0, green = 0, blue = 0, alpha = 0; 49 CGFloat red = 0, green = 0, blue = 0, alpha = 0;
49 [color getRed:&red green:&green blue:&blue alpha:&alpha]; 50 [color getRed:&red green:&green blue:&blue alpha:&alpha];
50 EXPECT_GE(red + green + blue, 3.0); 51 EXPECT_GE(red + green + blue, 3.0);
51 } 52 }
52 53
53 } // namespace 54 } // namespace
54 } // namespace ui 55 } // namespace ui
OLDNEW
« no previous file with comments | « ui/snapshot/snapshot_aura_unittest.cc ('k') | ui/surface/transport_dib_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698