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 "base/path_service.h"
6 #include "base/run_loop.h"
7 #include "content/public/browser/render_view_host.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/common/content_paths.h"
10 #include "content/shell/browser/shell.h"
11 #include "content/test/content_browser_test.h"
12 #include "content/test/content_browser_test_utils.h"
13 #include "net/base/net_util.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
18 class RenderWidgetHostBrowserTest
: public ContentBrowserTest
{
20 RenderWidgetHostBrowserTest() {}
22 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
23 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA
, &test_dir_
));
26 void GetSnapshotFromRendererCallback(const base::Closure
& quit_closure
,
29 const SkBitmap
& bitmap
) {
31 EXPECT_EQ(success
, true);
33 const int row_bytes
= bitmap
.rowBytesAsPixels();
34 SkColor
* pixels
= reinterpret_cast<SkColor
*>(bitmap
.getPixels());
35 for (int i
= 0; i
< bitmap
.width(); ++i
) {
36 for (int j
= 0; j
< bitmap
.height(); ++j
) {
37 if (pixels
[j
* row_bytes
+ i
] != SK_ColorRED
) {
42 *snapshot_valid
= true;
46 base::FilePath test_dir_
;
49 // Disabled on Windows and CrOS because it is flaky: crbug.com/272379.
50 // Disabled on Ozone due to flake: crbug.com/315392.
51 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(USE_OZONE)
52 #define MAYBE_GetSnapshotFromRendererTest DISABLED_GetSnapshotFromRendererTest
54 #define MAYBE_GetSnapshotFromRendererTest GetSnapshotFromRendererTest
56 IN_PROC_BROWSER_TEST_F(RenderWidgetHostBrowserTest
,
57 MAYBE_GetSnapshotFromRendererTest
) {
58 base::RunLoop run_loop
;
60 NavigateToURL(shell(), GURL(net::FilePathToFileURL(
61 test_dir_
.AppendASCII("rwh_simple.html"))));
63 bool snapshot_valid
= false;
64 RenderViewHost
* const rwh
= shell()->web_contents()->GetRenderViewHost();
65 rwh
->GetSnapshotFromRenderer(gfx::Rect(), base::Bind(
66 &RenderWidgetHostBrowserTest::GetSnapshotFromRendererCallback
,
67 base::Unretained(this),
68 run_loop
.QuitClosure(),
72 EXPECT_EQ(snapshot_valid
, true);
75 } // namespace content