From 15d890b1a9a05e7d1733ff3cefd68a13d07bfe2b Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Mon, 24 May 2010 20:01:07 +0000 Subject: 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 --- chrome/renderer/mock_render_thread.cc | 39 +++++++++++++--- chrome/renderer/mock_render_thread.h | 6 +++ chrome/renderer/render_view_unittest.cc | 79 ++++++++------------------------- chrome/test/render_view_test.cc | 34 ++++++++++++++ chrome/test/render_view_test.h | 7 +++ printing/pdf_ps_metafile_cairo.cc | 2 +- 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 + +#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(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("

Hello World!

"); 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("HelloWorld"); - // 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[] = "Lorem Ipsum:" "