OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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. | |
4 | |
5 #include "base/command_line.h" | |
6 #include "base/file_util.h" | |
7 #include "base/md5.h" | |
8 #include "chrome/test/base/chrome_render_view_test.h" | |
9 #include "chrome/renderer/automation/automation_renderer_helper.h" | |
10 #include "content/public/renderer/render_view.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" | |
14 | |
15 namespace { | |
16 | |
17 const char kThreeBoxesHTML[] = | |
18 "<style> * { margin:0px; padding:0px } </style>" | |
19 "<body>" | |
20 " <div style='background:red;width:100;height:100'></div>" | |
21 " <div style='background:green;width:100;height:100'></div>" | |
22 " <div style='background:blue;width:100;height:100'></div>" | |
23 "</body>"; | |
24 | |
25 const char kThreeBoxesMD5[] = "3adefecb4472e6ba1812f9af1fdea3e4"; | |
26 | |
27 void CompareSnapshot(const std::vector<unsigned char>& png_data, | |
28 const std::string& reference_md5) { | |
29 std::string png_data_str(reinterpret_cast<const char*>(&png_data[0]), | |
30 png_data.size()); | |
31 if (CommandLine::ForCurrentProcess()->HasSwitch("dump-test-image")) { | |
32 FilePath path = FilePath().AppendASCII("snapshot" + reference_md5 + ".png"); | |
33 EXPECT_EQ(file_util::WriteFile(path, png_data_str.c_str(), png_data.size()), | |
34 static_cast<int>(png_data.size())); | |
35 } | |
36 EXPECT_STREQ(reference_md5.c_str(), base::MD5String(png_data_str).c_str()); | |
37 } | |
38 | |
39 } // namespace | |
40 | |
41 typedef ChromeRenderViewTest AutomationRendererHelperTest; | |
42 | |
43 TEST_F(AutomationRendererHelperTest, BasicSnapshot) { | |
44 GetWebWidget()->resize(WebKit::WebSize(100, 300)); | |
45 LoadHTML(kThreeBoxesHTML); | |
46 std::vector<unsigned char> png_data; | |
47 std::string error_msg; | |
48 ASSERT_TRUE(AutomationRendererHelper::Get(view_)->SnapshotEntirePage( | |
49 view_->GetWebView(), &png_data, &error_msg)) << error_msg; | |
50 CompareSnapshot(png_data, kThreeBoxesMD5); | |
51 } | |
52 | |
53 TEST_F(AutomationRendererHelperTest, ScrollingSnapshot) { | |
54 GetWebWidget()->resize(WebKit::WebSize(40, 90)); | |
55 LoadHTML(kThreeBoxesHTML); | |
56 std::vector<unsigned char> png_data; | |
57 std::string error_msg; | |
58 ASSERT_TRUE(AutomationRendererHelper::Get(view_)->SnapshotEntirePage( | |
59 view_->GetWebView(), &png_data, &error_msg)) << error_msg; | |
60 CompareSnapshot(png_data, kThreeBoxesMD5); | |
61 } | |
62 | |
63 TEST_F(AutomationRendererHelperTest, RTLSnapshot) { | |
64 GetWebWidget()->resize(WebKit::WebSize(40, 90)); | |
65 const char kThreeBoxesRTLHTML[] = | |
66 "<style> * { margin:0px; padding:0px } </style>" | |
67 "<body dir='rtl'>" | |
68 " <div style='background:red;width:100;height:100'></div>" | |
69 " <div style='background:green;width:100;height:100'></div>" | |
70 " <div style='background:blue;width:100;height:100'></div>" | |
71 "</body>"; | |
72 LoadHTML(kThreeBoxesRTLHTML); | |
73 std::vector<unsigned char> png_data; | |
74 std::string error_msg; | |
75 ASSERT_TRUE(AutomationRendererHelper::Get(view_)->SnapshotEntirePage( | |
76 view_->GetWebView(), &png_data, &error_msg)) << error_msg; | |
77 CompareSnapshot(png_data, kThreeBoxesMD5); | |
78 } | |
OLD | NEW |