diff options
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/mock_render_thread.cc | 27 | ||||
-rw-r--r-- | chrome/renderer/mock_render_thread.h | 15 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 2 | ||||
-rw-r--r-- | chrome/renderer/render_view_unittest.cc | 35 |
4 files changed, 76 insertions, 3 deletions
diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc index 19fdd48..b133238 100644 --- a/chrome/renderer/mock_render_thread.cc +++ b/chrome/renderer/mock_render_thread.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -73,6 +73,12 @@ void MockRenderThread::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, OnMsgOpenChannelToExtension); +#if defined(OS_WIN) + IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings, + OnGetDefaultPrintSettings); + IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptedPrint, + OnScriptedPrint); +#endif IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() } @@ -89,3 +95,22 @@ void MockRenderThread::OnMsgOpenChannelToExtension( const std::string& extension_id, int* channel_id) { *channel_id = 0; } + +void MockRenderThread::OnGetDefaultPrintSettings(ViewMsg_Print_Params* params) { + memset(params, 0, sizeof(ViewMsg_Print_Params)); + params->dpi = 72; + params->desired_dpi = 72; + params->document_cookie = 1; + params->printable_size = gfx::Size(500, 500); +} + +void MockRenderThread::OnScriptedPrint(gfx::NativeViewId host_window, + int cookie, + int expected_pages_count, + ViewMsg_PrintPages_Params* settings) { + memset(settings, 0, sizeof(ViewMsg_PrintPages_Params)); + settings->params.dpi = 72; + settings->params.document_cookie = 1; + settings->params.desired_dpi = 72; + settings->params.printable_size = gfx::Size(500, 500); +} diff --git a/chrome/renderer/mock_render_thread.h b/chrome/renderer/mock_render_thread.h index a89822a6..f88543b 100644 --- a/chrome/renderer/mock_render_thread.h +++ b/chrome/renderer/mock_render_thread.h @@ -1,15 +1,19 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_RENDERER_MOCK_RENDER_THREAD_H_ #define CHROME_RENDERER_MOCK_RENDER_THREAD_H_ +#include <string> #include <vector> #include "chrome/common/ipc_test_sink.h" #include "chrome/renderer/render_thread.h" +struct ViewMsg_Print_Params; +struct ViewMsg_PrintPages_Params; + // This class is very simple mock of RenderThread. It simulates an IPC channel // which supports only two messages: // ViewHostMsg_CreateWidget : sync message sent by the Widget. @@ -73,6 +77,15 @@ class MockRenderThread : public RenderThreadBase { void OnMsgOpenChannelToExtension(const std::string& extension_id, int* channel_id); + // The RenderView expects default print settings. + void OnGetDefaultPrintSettings(ViewMsg_Print_Params* setting); + + // The RenderView expects final print settings from the user. + void OnScriptedPrint(gfx::NativeViewId host_window, + int cookie, + int expected_pages_count, + ViewMsg_PrintPages_Params* settings); + IPC::TestSink sink_; // Routing id what will be assigned to the Widget. diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index dd9b7c6..d0264f3 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -6,6 +6,7 @@ #define CHROME_RENDERER_RENDER_VIEW_H_ #include <string> +#include <queue> #include <vector> #include "base/basictypes.h" @@ -401,6 +402,7 @@ class RenderView : public RenderWidget, FRIEND_TEST(RenderViewTest, OnImeStateChanged); FRIEND_TEST(RenderViewTest, ImeComposition); FRIEND_TEST(RenderViewTest, OnSetTextDirection); + FRIEND_TEST(RenderViewTest, OnPrintPages); explicit RenderView(RenderThreadBase* render_thread); diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc index 3be31bd..85ad59e 100644 --- a/chrome/renderer/render_view_unittest.cc +++ b/chrome/renderer/render_view_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -276,3 +276,36 @@ TEST_F(RenderViewTest, OnSetTextDirection) { EXPECT_EQ(output, kTextDirection[i].expected_result); } } + +// Tests that printing pages work and sending and receiving messages through +// that channel all works. +TEST_F(RenderViewTest, OnPrintPages) { +#if defined(OS_WIN) + // 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.page_number); +#else + NOTIMPLEMENTED(); +#endif +} |