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

Unified Diff: ui/snapshot/snapshot_mac_unittest.mm

Issue 2592983002: [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: Disabled test on MacOS >=10.11, added ref to bug. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/snapshot/snapshot_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/snapshot/snapshot_mac_unittest.mm
diff --git a/ui/snapshot/snapshot_mac_unittest.mm b/ui/snapshot/snapshot_mac_unittest.mm
index d1d9250464012794bb20f25093d7326d35136a89..860b692fce0d965dcda271d2b58fd53f6ab42d84 100644
--- a/ui/snapshot/snapshot_mac_unittest.mm
+++ b/ui/snapshot/snapshot_mac_unittest.mm
@@ -8,38 +8,41 @@
#include <memory>
+#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/mac/sdk_forward_declarations.h"
#include "testing/platform_test.h"
#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/image/image.h"
+#import "ui/gfx/test/ui_cocoa_test_helper.h"
namespace ui {
namespace {
-typedef PlatformTest GrabWindowSnapshotTest;
+typedef CocoaTest GrabWindowSnapshotTest;
TEST_F(GrabWindowSnapshotTest, TestGrabWindowSnapshot) {
+ // TODO(https://crbug.com/685088): This test fails on MacOS 10.11 and above.
+ if (base::mac::IsAtLeastOS10_11())
+ return;
+
// Launch a test window so we can take a snapshot.
NSRect frame = NSMakeRect(0, 0, 400, 400);
- base::scoped_nsobject<NSWindow> window(
- [[NSWindow alloc] initWithContentRect:frame
- styleMask:NSBorderlessWindowMask
- backing:NSBackingStoreBuffered
- defer:NO]);
+ NSWindow* window = test_window();
+ [window setFrame:frame display:false];
[window setBackgroundColor:[NSColor whiteColor]];
[window makeKeyAndOrderFront:NSApp];
+ [window display];
- std::unique_ptr<std::vector<unsigned char>> png_representation(
- new std::vector<unsigned char>);
+ gfx::Image image;
gfx::Rect bounds = gfx::Rect(0, 0, frame.size.width, frame.size.height);
- EXPECT_TRUE(ui::GrabWindowSnapshot(window, png_representation.get(),
- bounds));
-
- // Copy png back into NSData object so we can make sure we grabbed a png.
- base::scoped_nsobject<NSData> image_data(
- [[NSData alloc] initWithBytes:&(*png_representation)[0]
- length:png_representation->size()]);
- NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:image_data.get()];
+ EXPECT_TRUE(ui::GrabWindowSnapshot(window, bounds, &image));
+
+ NSImage* nsImage = image.ToNSImage();
+ CGImageRef cgImage =
+ [nsImage CGImageForProposedRect:nil context:nil hints:nil];
+ base::scoped_nsobject<NSBitmapImageRep> rep(
+ [[NSBitmapImageRep alloc] initWithCGImage:cgImage]);
EXPECT_TRUE([rep isKindOfClass:[NSBitmapImageRep class]]);
CGFloat scaleFactor = 1.0f;
if ([window respondsToSelector:@selector(backingScaleFactor)])
« no previous file with comments | « ui/snapshot/snapshot_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698