summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-24 20:01:07 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-24 20:01:07 +0000
commit15d890b1a9a05e7d1733ff3cefd68a13d07bfe2b (patch)
tree9a06d1d3332349acbd6581f40cf84f96413825bb
parent1a999b9b66ba047ddd427b704fa04d5be39f00e0 (diff)
downloadchromium_src-15d890b1a9a05e7d1733ff3cefd68a13d07bfe2b.zip
chromium_src-15d890b1a9a05e7d1733ff3cefd68a13d07bfe2b.tar.gz
chromium_src-15d890b1a9a05e7d1733ff3cefd68a13d07bfe2b.tar.bz2
Port some more RenderViewTests to Linux.
Focus on printing tests. The ones I didn't port may not be worth the effort if we are going to change Linux printing soon. BUG=none TEST=tests pass Review URL: http://codereview.chromium.org/2066016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48072 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/mock_render_thread.cc39
-rw-r--r--chrome/renderer/mock_render_thread.h6
-rw-r--r--chrome/renderer/render_view_unittest.cc79
-rw-r--r--chrome/test/render_view_test.cc34
-rw-r--r--chrome/test/render_view_test.h7
-rw-r--r--printing/pdf_ps_metafile_cairo.cc2
6 files changed, 100 insertions, 67 deletions
diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc
index 0a64f11..57e9d80 100644
--- a/chrome/renderer/mock_render_thread.cc
+++ b/chrome/renderer/mock_render_thread.cc
@@ -4,6 +4,9 @@
#include "chrome/renderer/mock_render_thread.h"
+#include <fcntl.h>
+
+#include "base/file_util.h"
#include "base/process_util.h"
#include "chrome/common/render_messages.h"
#include "ipc/ipc_message_utils.h"
@@ -59,7 +62,7 @@ bool MockRenderThread::Send(IPC::Message* msg) {
}
} else {
if (msg->is_sync()) {
- // We actually need to handle deleting the reply dersializer for sync
+ // We actually need to handle deleting the reply deserializer for sync
// messages.
reply_deserializer_.reset(
static_cast<IPC::SyncMessage*>(msg)->GetReplyDeserializer());
@@ -83,14 +86,14 @@ void MockRenderThread::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
bool msg_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok)
- IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget);
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget)
IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension,
- OnMsgOpenChannelToExtension);
+ OnMsgOpenChannelToExtension)
#if defined(OS_WIN) || defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings,
- OnGetDefaultPrintSettings);
+ OnGetDefaultPrintSettings)
IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptedPrint,
- OnScriptedPrint);
+ OnScriptedPrint)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetPrintedPagesCount,
OnDidGetPrintedPagesCount)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, OnDidPrintPage)
@@ -102,6 +105,12 @@ void MockRenderThread::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_AllocatePDFTransport,
OnAllocatePDFTransport)
#endif
+#if defined(OS_LINUX)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateTempFileForPrinting,
+ OnAllocateTempFileForPrinting)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten,
+ OnTempFileForPrintingWritten)
+#endif
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
}
@@ -145,6 +154,26 @@ void MockRenderThread::OnAllocatePDFTransport(
}
#endif
+#if defined(OS_LINUX)
+void MockRenderThread::OnAllocateTempFileForPrinting(
+ base::FileDescriptor* renderer_fd,
+ int* browser_fd) {
+ renderer_fd->fd = *browser_fd = -1;
+ renderer_fd->auto_close = false;
+
+ FilePath path;
+ if (file_util::CreateTemporaryFile(&path)) {
+ int fd = open(path.value().c_str(), O_WRONLY);
+ DCHECK_GE(fd, 0);
+ renderer_fd->fd = *browser_fd = fd;
+ }
+}
+
+void MockRenderThread::OnTempFileForPrintingWritten(int browser_fd) {
+ close(browser_fd);
+}
+#endif
+
void MockRenderThread::OnGetDefaultPrintSettings(ViewMsg_Print_Params* params) {
if (printer_.get())
printer_->GetDefaultPrintSettings(params);
diff --git a/chrome/renderer/mock_render_thread.h b/chrome/renderer/mock_render_thread.h
index 8e7d210..c297cb8 100644
--- a/chrome/renderer/mock_render_thread.h
+++ b/chrome/renderer/mock_render_thread.h
@@ -101,6 +101,12 @@ class MockRenderThread : public RenderThreadBase {
base::SharedMemoryHandle* handle);
#endif
+#if defined(OS_LINUX)
+ void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd,
+ int* browser_fd);
+ void OnTempFileForPrintingWritten(int browser_fd);
+#endif
+
// The RenderView expects default print settings.
void OnGetDefaultPrintSettings(ViewMsg_Print_Params* setting);
diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc
index f80a834..4420f70 100644
--- a/chrome/renderer/render_view_unittest.cc
+++ b/chrome/renderer/render_view_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/basictypes.h"
+
#include "base/file_util.h"
#include "base/keyboard_codes.h"
#include "base/shared_memory.h"
@@ -293,70 +295,30 @@ TEST_F(RenderViewTest, OnSetTextDirection) {
// Tests that printing pages work and sending and receiving messages through
// that channel all works.
TEST_F(RenderViewTest, OnPrintPages) {
-#if defined(OS_WIN) || defined(OS_MACOSX)
// Lets simulate a print pages with Hello world.
LoadHTML("<body><p>Hello World!</p></body>");
view_->OnPrintPages();
- // The renderer should be done calculating the number of rendered pages
- // according to the specified settings defined in the mock render thread.
- // Verify the page count is correct.
- const IPC::Message* page_cnt_msg =
- render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_DidGetPrintedPagesCount::ID);
- EXPECT_TRUE(page_cnt_msg);
- ViewHostMsg_DidGetPrintedPagesCount::Param post_page_count_param;
- ViewHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg,
- &post_page_count_param);
- EXPECT_EQ(1, post_page_count_param.b);
-
- // Verify the rendered "printed page".
- const IPC::Message* did_print_msg =
- render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_DidPrintPage::ID);
- EXPECT_TRUE(did_print_msg);
- ViewHostMsg_DidPrintPage::Param post_did_print_page_param;
- ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param);
- EXPECT_EQ(0, post_did_print_page_param.a.page_number);
-#else
- NOTIMPLEMENTED();
-#endif
+ VerifyPageCount(1);
+ VerifyPagesPrinted();
}
// Duplicate of OnPrintPagesTest only using javascript to print.
TEST_F(RenderViewTest, PrintWithJavascript) {
-#if defined(OS_WIN) || defined(OS_MACOSX)
// HTML contains a call to window.print()
LoadHTML("<body>Hello<script>window.print()</script>World</body>");
- // The renderer should be done calculating the number of rendered pages
- // according to the specified settings defined in the mock render thread.
- // Verify the page count is correct.
- const IPC::Message* page_cnt_msg =
- render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_DidGetPrintedPagesCount::ID);
- ASSERT_TRUE(page_cnt_msg);
- ViewHostMsg_DidGetPrintedPagesCount::Param post_page_count_param;
- ViewHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg,
- &post_page_count_param);
- EXPECT_EQ(1, post_page_count_param.b);
-
- // Verify the rendered "printed page".
- const IPC::Message* did_print_msg =
- render_thread_.sink().GetUniqueMessageMatching(
- ViewHostMsg_DidPrintPage::ID);
- EXPECT_TRUE(did_print_msg);
- ViewHostMsg_DidPrintPage::Param post_did_print_page_param;
- ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param);
- EXPECT_EQ(0, post_did_print_page_param.a.page_number);
-#else
- NOTIMPLEMENTED();
-#endif
+ VerifyPageCount(1);
+ VerifyPagesPrinted();
}
-TEST_F(RenderViewTest, PrintWithIframe) {
#if defined(OS_WIN) || defined(OS_MACOSX)
- // Document that populates an iframe..
+// TODO(estade): I don't think this test is worth porting to Linux. We will have
+// to rip out and replace most of the IPC code if we ever plan to improve
+// printing, and the comment below by sverrir suggests that it doesn't do much
+// for us anyway.
+TEST_F(RenderViewTest, PrintWithIframe) {
+ // Document that populates an iframe.
const char html[] =
"<html><body>Lorem Ipsum:"
"<iframe name=\"sub1\" id=\"sub1\"></iframe><script>"
@@ -389,10 +351,8 @@ TEST_F(RenderViewTest, PrintWithIframe) {
// page.
EXPECT_NE(0, image1.size().width());
EXPECT_NE(0, image1.size().height());
-#else
- NOTIMPLEMENTED();
-#endif
}
+#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,
@@ -432,8 +392,11 @@ const TestPageData kTestPages[] = {
};
} // namespace
-TEST_F(RenderViewTest, PrintLayoutTest) {
+// TODO(estade): need to port MockPrinter to get this on Linux. This involves
+// hooking up Cairo to read a pdf stream, or accessing the cairo surface in the
+// metafile directly.
#if defined(OS_WIN) || defined(OS_MACOSX)
+TEST_F(RenderViewTest, PrintLayoutTest) {
bool baseline = false;
EXPECT_TRUE(render_thread_.printer() != NULL);
@@ -482,14 +445,11 @@ TEST_F(RenderViewTest, PrintLayoutTest) {
render_thread_.printer()->SaveBitmap(0, bitmap_path);
}
}
-#else
- NOTIMPLEMENTED();
-#endif
}
+#endif
// Print page as bitmap test.
TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
-#if defined(OS_WIN) || defined(OS_MACOSX)
// Lets simulate a print pages with Hello world.
LoadHTML("<body><p>Hello world!</p></body>");
@@ -525,9 +485,6 @@ TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
}
}
ASSERT_TRUE(!is_white);
-#else
- NOTIMPLEMENTED();
-#endif
}
// Test that we can receive correct DOM events when we send input events
diff --git a/chrome/test/render_view_test.cc b/chrome/test/render_view_test.cc
index d4eb90f..07a5e05 100644
--- a/chrome/test/render_view_test.cc
+++ b/chrome/test/render_view_test.cc
@@ -224,3 +224,37 @@ void RenderViewTest::SendNativeKeyEvent(
sizeof(WebKit::WebKeyboardEvent));
view_->OnHandleInputEvent(*input_message);
}
+
+void RenderViewTest::VerifyPageCount(int count) {
+#if defined(OS_WIN) || defined(OS_MACOSX)
+ const IPC::Message* page_cnt_msg =
+ render_thread_.sink().GetUniqueMessageMatching(
+ ViewHostMsg_DidGetPrintedPagesCount::ID);
+ ASSERT_TRUE(page_cnt_msg);
+ ViewHostMsg_DidGetPrintedPagesCount::Param post_page_count_param;
+ ViewHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg,
+ &post_page_count_param);
+ EXPECT_EQ(count, post_page_count_param.b);
+#elif defined(OS_LINUX)
+ // The DidGetPrintedPagesCount message isn't sent on Linux. Right now we
+ // always print all pages, and there are checks to that effect built into
+ // the print code.
+#endif
+}
+
+void RenderViewTest::VerifyPagesPrinted() {
+#if defined(OS_WIN) || defined(OS_MACOSX)
+ const IPC::Message* did_print_msg =
+ render_thread_.sink().GetUniqueMessageMatching(
+ ViewHostMsg_DidPrintPage::ID);
+ ASSERT_TRUE(did_print_msg);
+ ViewHostMsg_DidPrintPage::Param post_did_print_page_param;
+ ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param);
+ EXPECT_EQ(0, post_did_print_page_param.a.page_number);
+#elif defined(OS_LINUX)
+ const IPC::Message* did_print_msg =
+ render_thread_.sink().GetUniqueMessageMatching(
+ ViewHostMsg_TempFileForPrintingWritten::ID);
+ ASSERT_TRUE(did_print_msg);
+#endif
+}
diff --git a/chrome/test/render_view_test.h b/chrome/test/render_view_test.h
index 4834d9a..af6059e 100644
--- a/chrome/test/render_view_test.h
+++ b/chrome/test/render_view_test.h
@@ -50,6 +50,13 @@ class RenderViewTest : public testing::Test {
// Sends one native key event over IPC.
void SendNativeKeyEvent(const NativeWebKeyboardEvent& key_event);
+ // The renderer should be done calculating the number of rendered pages
+ // according to the specified settings defined in the mock render thread.
+ // Verify the page count is correct.
+ void VerifyPageCount(int count);
+ // Verify the rendered "printed page".
+ void VerifyPagesPrinted();
+
// testing::Test
virtual void SetUp();
diff --git a/printing/pdf_ps_metafile_cairo.cc b/printing/pdf_ps_metafile_cairo.cc
index 81050b7..b87992f 100644
--- a/printing/pdf_ps_metafile_cairo.cc
+++ b/printing/pdf_ps_metafile_cairo.cc
@@ -139,7 +139,7 @@ bool PdfPsMetafile::Init(const void* src_buffer, uint32 src_buffer_size) {
return false;
data_ = std::string(reinterpret_cast<const char*>(src_buffer),
- src_buffer_size);
+ src_buffer_size);
return true;
}