This source file includes following definitions.
- SetUpOnMainThread
- GetSnapshotFromRendererCallback
- IN_PROC_BROWSER_TEST_F
#include "base/path_service.h"
#include "base/run_loop.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_paths.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
#include "net/base/net_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace content {
class RenderWidgetHostBrowserTest : public ContentBrowserTest {
public:
RenderWidgetHostBrowserTest() {}
virtual void SetUpOnMainThread() OVERRIDE {
ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_dir_));
}
void GetSnapshotFromRendererCallback(const base::Closure& quit_closure,
bool* snapshot_valid,
bool success,
const SkBitmap& bitmap) {
quit_closure.Run();
EXPECT_EQ(success, true);
const int row_bytes = bitmap.rowBytesAsPixels();
SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
for (int i = 0; i < bitmap.width(); ++i) {
for (int j = 0; j < bitmap.height(); ++j) {
if (pixels[j * row_bytes + i] != SK_ColorRED) {
return;
}
}
}
*snapshot_valid = true;
}
protected:
base::FilePath test_dir_;
};
#if defined(USE_AURA) || defined(USE_OZONE)
#define MAYBE_GetSnapshotFromRendererTest DISABLED_GetSnapshotFromRendererTest
#else
#define MAYBE_GetSnapshotFromRendererTest GetSnapshotFromRendererTest
#endif
IN_PROC_BROWSER_TEST_F(RenderWidgetHostBrowserTest,
MAYBE_GetSnapshotFromRendererTest) {
base::RunLoop run_loop;
NavigateToURL(shell(), GURL(net::FilePathToFileURL(
test_dir_.AppendASCII("rwh_simple.html"))));
bool snapshot_valid = false;
RenderViewHost* const rwh = shell()->web_contents()->GetRenderViewHost();
rwh->GetSnapshotFromRenderer(gfx::Rect(), base::Bind(
&RenderWidgetHostBrowserTest::GetSnapshotFromRendererCallback,
base::Unretained(this),
run_loop.QuitClosure(),
&snapshot_valid));
run_loop.Run();
EXPECT_EQ(snapshot_valid, true);
}
}