1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h"
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
9 class RenderWidgetSnapshotTakerTest : public ChromeRenderViewHostTestHarness {
11 RenderWidgetSnapshotTakerTest() : snapshot_ready_called_(false) {}
13 void SnapshotReady(const SkBitmap& bitmap) {
14 snapshot_ready_called_ = true;
17 bool snapshot_ready_called() const {
18 return snapshot_ready_called_;
22 bool snapshot_ready_called_;
26 // RenderWidgetHost::AskForSnapshot is not implemented for X11
27 // (http://crbug.com/89777).
28 #define MAYBE_WidgetDidReceivePaintAtSizeAck \
29 DISABLED_WidgetDidReceivePaintAtSizeAck
31 #define MAYBE_WidgetDidReceivePaintAtSizeAck WidgetDidReceivePaintAtSizeAck
34 // Just checks the callback runs in WidgetDidReceivePaintAtSizeAck.
35 TEST_F(RenderWidgetSnapshotTakerTest, MAYBE_WidgetDidReceivePaintAtSizeAck) {
36 RenderWidgetSnapshotTaker snapshot_taker;
37 const gfx::Size size(100, 100);
38 snapshot_taker.AskForSnapshot(
40 base::Bind(&RenderWidgetSnapshotTakerTest::SnapshotReady,
41 base::Unretained(this)),
44 EXPECT_EQ(1U, snapshot_taker.callback_map_.size());
45 const int sequence_num = 1;
46 snapshot_taker.WidgetDidReceivePaintAtSizeAck(
47 content::RenderViewHostTestHarness::rvh(),
50 EXPECT_TRUE(snapshot_taker.callback_map_.empty());
51 EXPECT_TRUE(snapshot_ready_called());
55 // RenderWidgetHost::AskForSnapshot is not implemented for X11
56 // (http://crbug.com/89777).
57 #define MAYBE_WidgetDidReceivePaintAtSizeAckFail \
58 DISABLED_WidgetDidReceivePaintAtSizeAckFail
60 #define MAYBE_WidgetDidReceivePaintAtSizeAckFail \
61 WidgetDidReceivePaintAtSizeAckFail
64 // Checks the case where RenderWidgetSnapshotTaker receives an ack with a wrong
65 // size. The should result in a failure and the callback should not be called.
66 TEST_F(RenderWidgetSnapshotTakerTest,
67 MAYBE_WidgetDidReceivePaintAtSizeAckFail) {
68 RenderWidgetSnapshotTaker snapshot_taker;
69 const gfx::Size size(100, 100);
70 snapshot_taker.AskForSnapshot(
72 base::Bind(&RenderWidgetSnapshotTakerTest::SnapshotReady,
73 base::Unretained(this)),
76 EXPECT_EQ(1U, snapshot_taker.callback_map_.size());
77 const int sequence_num = 1;
78 // Ensure this is bigger than the max scale factor X the size.
79 const gfx::Size size2(300, 300);
80 snapshot_taker.WidgetDidReceivePaintAtSizeAck(
81 content::RenderViewHostTestHarness::rvh(),
84 EXPECT_FALSE(snapshot_taker.callback_map_.empty());
85 EXPECT_FALSE(snapshot_ready_called());