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

Unified Diff: ui/snapshot/snapshot_aura_unittest.cc

Issue 2650903003: Revert of [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: 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_aura.cc ('k') | ui/snapshot/snapshot_ios.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/snapshot/snapshot_aura_unittest.cc
diff --git a/ui/snapshot/snapshot_aura_unittest.cc b/ui/snapshot/snapshot_aura_unittest.cc
index 97d4ac4459c4e0e55d8c71e2e01ce239e4bc3c3d..984a231bc2100b2c2f116901fe644154e0b657ae 100644
--- a/ui/snapshot/snapshot_aura_unittest.cc
+++ b/ui/snapshot/snapshot_aura_unittest.cc
@@ -141,14 +141,28 @@
aura::Window::ConvertRectToTarget(
test_window(), root_window(), &source_rect);
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner(
+ new base::TestSimpleTaskRunner());
scoped_refptr<SnapshotHolder> holder(new SnapshotHolder);
ui::GrabWindowSnapshotAsync(
- root_window(), source_rect,
+ root_window(),
+ source_rect,
+ task_runner,
base::Bind(&SnapshotHolder::SnapshotCallback, holder));
- holder->WaitForSnapshot();
- DCHECK(holder->completed());
- return holder->image();
+ // Wait for copy response.
+ WaitForDraw();
+ // Run internal snapshot callback to scale/rotate response image.
+ task_runner->RunUntilIdle();
+ // Run SnapshotHolder callback.
+ helper_->RunAllPendingInMessageLoop();
+
+ if (holder->completed())
+ return holder->image();
+
+ // Callback never called.
+ NOTREACHED();
+ return gfx::Image();
}
private:
@@ -156,13 +170,12 @@
public:
SnapshotHolder() : completed_(false) {}
- void SnapshotCallback(const gfx::Image& image) {
+ void SnapshotCallback(scoped_refptr<base::RefCountedBytes> png_data) {
DCHECK(!completed_);
- image_ = image;
+ image_ = gfx::Image::CreateFrom1xPNGBytes(&(png_data->data()[0]),
+ png_data->size());
completed_ = true;
- run_loop_.Quit();
}
- void WaitForSnapshot() { run_loop_.Run(); }
bool completed() const {
return completed_;
};
@@ -173,7 +186,6 @@
virtual ~SnapshotHolder() {}
- base::RunLoop run_loop_;
gfx::Image image_;
bool completed_;
};
@@ -219,7 +231,7 @@
}
TEST_F(SnapshotAuraTest, UIScale) {
- const float kUIScale = 0.5f;
+ const float kUIScale = 1.25f;
test_screen()->SetUIScale(kUIScale);
gfx::Rect test_bounds(100, 100, 300, 200);
@@ -228,12 +240,11 @@
// Snapshot always captures the physical pixels.
gfx::SizeF snapshot_size(test_bounds.size());
- snapshot_size.Scale(1 / kUIScale);
gfx::Image snapshot = GrabSnapshotForTestWindow();
EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
snapshot.Size().ToString());
- EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 1 / kUIScale));
+ EXPECT_EQ(0u, GetFailedPixelsCount(snapshot));
}
TEST_F(SnapshotAuraTest, DeviceScaleFactor) {
@@ -254,7 +265,7 @@
}
TEST_F(SnapshotAuraTest, RotateAndUIScale) {
- const float kUIScale = 0.5f;
+ const float kUIScale = 1.25f;
test_screen()->SetUIScale(kUIScale);
test_screen()->SetDisplayRotation(display::Display::ROTATE_90);
@@ -264,17 +275,16 @@
// Snapshot always captures the physical pixels.
gfx::SizeF snapshot_size(test_bounds.size());
- snapshot_size.Scale(1 / kUIScale);
gfx::Image snapshot = GrabSnapshotForTestWindow();
EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
snapshot.Size().ToString());
- EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 1 / kUIScale));
+ EXPECT_EQ(0u, GetFailedPixelsCount(snapshot));
}
TEST_F(SnapshotAuraTest, RotateAndUIScaleAndScaleFactor) {
test_screen()->SetDeviceScaleFactor(2.0f);
- const float kUIScale = 0.5f;
+ const float kUIScale = 1.25f;
test_screen()->SetUIScale(kUIScale);
test_screen()->SetDisplayRotation(display::Display::ROTATE_90);
@@ -284,12 +294,12 @@
// Snapshot always captures the physical pixels.
gfx::SizeF snapshot_size(test_bounds.size());
- snapshot_size.Scale(2.0f / kUIScale);
+ snapshot_size.Scale(2.0f);
gfx::Image snapshot = GrabSnapshotForTestWindow();
EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
snapshot.Size().ToString());
- EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2 / kUIScale));
+ EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2));
}
} // namespace ui
« no previous file with comments | « ui/snapshot/snapshot_aura.cc ('k') | ui/snapshot/snapshot_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698