summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/render_view_unittest.cc
diff options
context:
space:
mode:
authorhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-23 03:09:52 +0000
committerhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-23 03:09:52 +0000
commitfa8a2b1b050009d67e03cf03a26d7d558afe0ecb (patch)
tree09108ff8271c1ca005d439213db16a784977175f /chrome/renderer/render_view_unittest.cc
parentb6b60c9b2afa70010fe38ed7c753f4c8e37e7131 (diff)
downloadchromium_src-fa8a2b1b050009d67e03cf03a26d7d558afe0ecb.zip
chromium_src-fa8a2b1b050009d67e03cf03a26d7d558afe0ecb.tar.gz
chromium_src-fa8a2b1b050009d67e03cf03a26d7d558afe0ecb.tar.bz2
Adds a RenderViewTest.PrintLayoutTest.
This change adds a new test 'RenderViewTest.PrintLayoutTest', which prints an HTML page and verify its output. To process a print job and verify its output, this change adds a pseudo-printer device "MockPrinter" into the MockRenderThread object. This MockPrinter object receives print-related IPC messages, process print jobs, and store the MD5 checksum of the output data. The current RenderViewTest.PrintLayoutTest retrieves the MD5 checksum values and just compare them with expected values. Nevertheless, please feel free to give me your ideas to improve this test. Finally, this change is inspired by PrintingLayoutTextTests (created by maruel) and a RenderViewTest.OnPrintPages (created by Mohamed Mansour). I would like to express my best gratitude to them. BUG=none TEST=none Review URL: http://codereview.chromium.org/100255 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16834 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/render_view_unittest.cc')
-rw-r--r--chrome/renderer/render_view_unittest.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc
index 8537583..781c62a 100644
--- a/chrome/renderer/render_view_unittest.cc
+++ b/chrome/renderer/render_view_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/file_util.h"
#include "chrome/common/native_web_keyboard_event.h"
#include "chrome/common/render_messages.h"
#include "chrome/test/render_view_test.h"
@@ -311,6 +312,93 @@ TEST_F(RenderViewTest, OnPrintPages) {
#endif
}
+// Tests if we can print a page and verify its results.
+// This test prints HTML pages into a pseudo printer and check their outputs,
+// i.e. a simplified version of the PrintingLayoutTextTest UI test.
+namespace {
+// Test cases used in this test.
+const struct {
+ const char* page;
+ int printed_pages;
+ int width;
+ int height;
+ const char* checksum;
+ const wchar_t* file;
+} kTestPages[] = {
+ {"<html>"
+ "<head>"
+ "<meta"
+ " http-equiv=\"Content-Type\""
+ " content=\"text/html; charset=utf-8\"/>"
+ "<title>Test 1</title>"
+ "</head>"
+ "<body style=\"background-color: white;\">"
+ "<p style=\"font-family: arial;\">Hello World!</p>"
+ "</body>",
+ 1, 764, 42,
+ NULL,
+ NULL,
+ },
+};
+} // namespace
+
+TEST_F(RenderViewTest, PrintLayoutTest) {
+#if defined(OS_WIN)
+ bool baseline = false;
+
+ EXPECT_TRUE(render_thread_.printer() != NULL);
+ for (size_t i = 0; i < arraysize(kTestPages); ++i) {
+ // Load an HTML page and print it.
+ LoadHTML(kTestPages[i].page);
+ view_->OnPrintPages();
+
+ // MockRenderThread::Send() just calls MockRenderThread::OnMsgReceived().
+ // So, all IPC messages sent in the above RenderView::OnPrintPages() call
+ // has been handled by the MockPrinter object, i.e. this printing job
+ // has been already finished.
+ // So, we can start checking the output pages of this printing job.
+ // Retrieve the number of pages actually printed.
+ size_t pages = render_thread_.printer()->GetPrintedPages();
+ EXPECT_EQ(kTestPages[i].printed_pages, pages);
+
+ // Retrieve the width and height of the output page.
+ int width = render_thread_.printer()->GetWidth(0);
+ int height = render_thread_.printer()->GetHeight(0);
+ EXPECT_EQ(kTestPages[i].width, width);
+ EXPECT_EQ(kTestPages[i].height, height);
+
+ // Retrieve the checksum of the bitmap data from the pseudo printer and
+ // compare it with the expected result.
+ std::string bitmap_actual;
+ EXPECT_TRUE(render_thread_.printer()->GetBitmapChecksum(0, &bitmap_actual));
+ if (kTestPages[i].checksum)
+ EXPECT_EQ(kTestPages[i].checksum, bitmap_actual);
+
+ // Retrieve the bitmap data from the pseudo printer.
+ // TODO(hbono): implement a function which retrieves an expected result
+ // from a file and compares it with this bitmap data.
+ const void* bitmap_data;
+ size_t bitmap_size;
+ EXPECT_TRUE(render_thread_.printer()->GetBitmap(0, &bitmap_data,
+ &bitmap_size));
+
+ if (baseline) {
+ // Save the source data and the bitmap data into temporary files to
+ // create base-line results.
+ FilePath source_path;
+ file_util::CreateTemporaryFileName(&source_path);
+ render_thread_.printer()->SaveSource(0, source_path.value());
+
+ FilePath bitmap_path;
+ file_util::CreateTemporaryFileName(&bitmap_path);
+ render_thread_.printer()->SaveBitmap(0, bitmap_path.value());
+ }
+ }
+#else
+ NOTIMPLEMENTED();
+#endif
+}
+
// Test that we can receive correct DOM events when we send input events
// through the RenderWidget::OnHandleInputEvent() function.
TEST_F(RenderViewTest, OnHandleKeyboardEvent) {