diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-14 17:28:23 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-14 17:28:23 +0000 |
commit | c6d068ff599527ce4fccd39fd593099aada24d67 (patch) | |
tree | 5923cd9a4583780ce8d3384c24ec1a972156add9 /chrome/renderer | |
parent | 595bfa8b392c172ff1b70c0d329d2bc1102ec242 (diff) | |
download | chromium_src-c6d068ff599527ce4fccd39fd593099aada24d67.zip chromium_src-c6d068ff599527ce4fccd39fd593099aada24d67.tar.gz chromium_src-c6d068ff599527ce4fccd39fd593099aada24d67.tar.bz2 |
Split most of RenderViewTest and associated classes into content.
BUG=99224
TEST=existing browser_tests, unit_tests
Review URL: http://codereview.chromium.org/8230034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105511 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
17 files changed, 223 insertions, 813 deletions
diff --git a/chrome/renderer/autofill/autofill_agent.h b/chrome/renderer/autofill/autofill_agent.h index 01644fc..a5e8462 100644 --- a/chrome/renderer/autofill/autofill_agent.h +++ b/chrome/renderer/autofill/autofill_agent.h @@ -177,8 +177,8 @@ class AutofillAgent : public content::RenderViewObserver, base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_; friend class PasswordAutofillManagerTest; - FRIEND_TEST_ALL_PREFIXES(RenderViewTest, SendForms); - FRIEND_TEST_ALL_PREFIXES(RenderViewTest, FillFormElement); + FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, SendForms); + FRIEND_TEST_ALL_PREFIXES(ChromeRenderViewTest, FillFormElement); FRIEND_TEST_ALL_PREFIXES(PasswordAutofillManagerTest, WaitUsername); FRIEND_TEST_ALL_PREFIXES(PasswordAutofillManagerTest, SuggestionAccept); FRIEND_TEST_ALL_PREFIXES(PasswordAutofillManagerTest, SuggestionSelect); diff --git a/chrome/renderer/autofill/autofill_browsertest.cc b/chrome/renderer/autofill/autofill_browsertest.cc index 9648532..e101eaa 100644 --- a/chrome/renderer/autofill/autofill_browsertest.cc +++ b/chrome/renderer/autofill/autofill_browsertest.cc @@ -4,7 +4,7 @@ #include "base/utf_string_conversions.h" #include "chrome/common/autofill_messages.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" @@ -21,7 +21,7 @@ using webkit_glue::FormField; namespace autofill { -TEST_F(RenderViewTest, SendForms) { +TEST_F(ChromeRenderViewTest, SendForms) { // Don't want any delay for form state sync changes. This will still post a // message so updates will get coalesced, but as soon as we spin the message // loop, it will generate an update. @@ -41,7 +41,7 @@ TEST_F(RenderViewTest, SendForms) { // Verify that "FormsSeen" sends the expected number of fields. ProcessPendingMessages(); - const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( + const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( AutofillHostMsg_FormsSeen::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), message); AutofillHostMsg_FormsSeen::Param params; @@ -94,8 +94,9 @@ TEST_F(RenderViewTest, SendForms) { -1); ProcessPendingMessages(); - const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( - AutofillHostMsg_FillAutofillFormData::ID); + const IPC::Message* message2 = + render_thread_->sink().GetUniqueMessageMatching( + AutofillHostMsg_FillAutofillFormData::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); AutofillHostMsg_FillAutofillFormData::Param params2; AutofillHostMsg_FillAutofillFormData::Read(message2, ¶ms2); @@ -121,7 +122,7 @@ TEST_F(RenderViewTest, SendForms) { EXPECT_FORM_FIELD_EQUALS(expected, form2.fields[2]); } -TEST_F(RenderViewTest, FillFormElement) { +TEST_F(ChromeRenderViewTest, FillFormElement) { // Don't want any delay for form state sync changes. This will still post a // message so updates will get coalesced, but as soon as we spin the message // loop, it will generate an update. @@ -134,7 +135,7 @@ TEST_F(RenderViewTest, FillFormElement) { // Verify that "FormsSeen" isn't sent, as there are too few fields. ProcessPendingMessages(); - const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( + const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( AutofillHostMsg_FormsSeen::ID); ASSERT_EQ(static_cast<IPC::Message*>(NULL), message); @@ -157,8 +158,9 @@ TEST_F(RenderViewTest, FillFormElement) { 0); ProcessPendingMessages(); - const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( - AutofillHostMsg_FillAutofillFormData::ID); + const IPC::Message* message2 = + render_thread_->sink().GetUniqueMessageMatching( + AutofillHostMsg_FillAutofillFormData::ID); // No message should be sent in this case. |firstname| is filled directly. ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); diff --git a/chrome/renderer/autofill/form_autocomplete_browsertest.cc b/chrome/renderer/autofill/form_autocomplete_browsertest.cc index 101b812..6621690 100644 --- a/chrome/renderer/autofill/form_autocomplete_browsertest.cc +++ b/chrome/renderer/autofill/form_autocomplete_browsertest.cc @@ -4,7 +4,7 @@ #include "base/time.h" #include "chrome/common/autofill_messages.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" @@ -19,7 +19,7 @@ using WebKit::WebString; using WebKit::WebTextDirection; using WebKit::WebURLError; -typedef RenderViewTest FormAutocompleteTest; +typedef ChromeRenderViewTest FormAutocompleteTest; // Tests that submitting a form generates a FormSubmitted message // with the form fields. @@ -32,7 +32,7 @@ TEST_F(FormAutocompleteTest, NormalFormSubmit) { ExecuteJavaScript("document.getElementById('myForm').submit();"); ProcessPendingMessages(); - const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( + const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( AutofillHostMsg_FormSubmitted::ID); ASSERT_TRUE(message != NULL); @@ -64,7 +64,7 @@ TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { ProcessPendingMessages(); // No FormSubmitted message should have been sent. - EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( + EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( AutofillHostMsg_FormSubmitted::ID)); } @@ -81,7 +81,7 @@ TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { ProcessPendingMessages(); // No FormSubmitted message should have been sent. - const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( + const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( AutofillHostMsg_FormSubmitted::ID); ASSERT_TRUE(message != NULL); @@ -119,6 +119,6 @@ TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { ProcessPendingMessages(); // No FormSubmitted message should have been sent. - EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( + EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( AutofillHostMsg_FormSubmitted::ID)); } diff --git a/chrome/renderer/autofill/form_autofill_browsertest.cc b/chrome/renderer/autofill/form_autofill_browsertest.cc index 858164f..b30b62f 100644 --- a/chrome/renderer/autofill/form_autofill_browsertest.cc +++ b/chrome/renderer/autofill/form_autofill_browsertest.cc @@ -11,7 +11,7 @@ #include "base/utf_string_conversions.h" #include "chrome/renderer/autofill/form_autofill_util.h" #include "chrome/renderer/autofill/form_cache.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" @@ -47,9 +47,9 @@ using autofill::WebFormControlElementToFormField; using webkit_glue::FormData; using webkit_glue::FormField; -class FormAutofillTest : public RenderViewTest { +class FormAutofillTest : public ChromeRenderViewTest { public: - FormAutofillTest() : RenderViewTest() {} + FormAutofillTest() : ChromeRenderViewTest() {} virtual ~FormAutofillTest() {} void ExpectLabels(const char* html, diff --git a/chrome/renderer/autofill/password_autofill_manager_browsertest.cc b/chrome/renderer/autofill/password_autofill_manager_browsertest.cc index 51cac3d..e974208 100644 --- a/chrome/renderer/autofill/password_autofill_manager_browsertest.cc +++ b/chrome/renderer/autofill/password_autofill_manager_browsertest.cc @@ -7,7 +7,7 @@ #include "chrome/common/autofill_messages.h" #include "chrome/renderer/autofill/autofill_agent.h" #include "chrome/renderer/autofill/password_autofill_manager.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" @@ -55,7 +55,7 @@ const char* const kFormHTML = namespace autofill { -class PasswordAutofillManagerTest : public RenderViewTest { +class PasswordAutofillManagerTest : public ChromeRenderViewTest { public: PasswordAutofillManagerTest() { } @@ -70,7 +70,7 @@ class PasswordAutofillManagerTest : public RenderViewTest { } virtual void SetUp() { - RenderViewTest::SetUp(); + ChromeRenderViewTest::SetUp(); // Add a preferred login and an additional login to the FillData. username1_ = ASCIIToUTF16(kAliceUsername); diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/chrome_mock_render_thread.cc index cecb6db..3e2df0f 100644 --- a/chrome/renderer/mock_render_thread.cc +++ b/chrome/renderer/chrome_mock_render_thread.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/renderer/mock_render_thread.h" +#include "chrome/renderer/chrome_mock_render_thread.h" #include <fcntl.h> @@ -19,160 +19,24 @@ #include "printing/page_range.h" #include "testing/gtest/include/gtest/gtest.h" -MockRenderThread::MockRenderThread() - : routing_id_(0), - opener_id_(0), - widget_(NULL), - reply_deserializer_(NULL), - printer_(new MockPrinter), +ChromeMockRenderThread::ChromeMockRenderThread() + : printer_(new MockPrinter), print_dialog_user_response_(true), print_preview_cancel_page_number_(-1), print_preview_pages_remaining_(0) { } -MockRenderThread::~MockRenderThread() { +ChromeMockRenderThread::~ChromeMockRenderThread() { } -// Called by the Widget. Used to send messages to the browser. -// We short-circuit the mechanism and handle the messages right here on this -// class. -bool MockRenderThread::Send(IPC::Message* msg) { - // We need to simulate a synchronous channel, thus we are going to receive - // through this function messages, messages with reply and reply messages. - // We can only handle one synchronous message at a time. - if (msg->is_reply()) { - if (reply_deserializer_.get()) { - reply_deserializer_->SerializeOutputParameters(*msg); - reply_deserializer_.reset(); - } - } else { - if (msg->is_sync()) { - // We actually need to handle deleting the reply deserializer for sync - // messages. - reply_deserializer_.reset( - static_cast<IPC::SyncMessage*>(msg)->GetReplyDeserializer()); - } - OnMessageReceived(*msg); - } - delete msg; - return true; -} - -MessageLoop* MockRenderThread::GetMessageLoop() { - return NULL; -} - -IPC::SyncChannel* MockRenderThread::GetChannel() { - return NULL; -} - -std::string MockRenderThread::GetLocale() { - return std::string(); -} - -void MockRenderThread::AddRoute(int32 routing_id, - IPC::Channel::Listener* listener) { - EXPECT_EQ(routing_id_, routing_id); - widget_ = listener; -} - -void MockRenderThread::RemoveRoute(int32 routing_id) { - EXPECT_EQ(routing_id_, routing_id); - widget_ = NULL; -} - -void MockRenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { - filter->OnFilterAdded(&sink()); -} - -void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { - filter->OnFilterRemoved(); -} - -void MockRenderThread::SetOutgoingMessageFilter( - IPC::ChannelProxy::OutgoingMessageFilter* filter) { -} - -void MockRenderThread::AddObserver(content::RenderProcessObserver* observer) { -} - -void MockRenderThread::RemoveObserver( - content::RenderProcessObserver* observer) { -} - -void MockRenderThread::SetResourceDispatcherDelegate( - content::ResourceDispatcherDelegate* delegate) { -} - -void MockRenderThread::WidgetHidden() { -} - -void MockRenderThread::WidgetRestored() { -} - -void MockRenderThread::EnsureWebKitInitialized() { -} - -void MockRenderThread::RecordUserMetrics(const std::string& action) { -} - -base::SharedMemoryHandle MockRenderThread::HostAllocateSharedMemoryBuffer( - uint32 buffer_size) { - base::SharedMemory shared_buf; - if (!shared_buf.CreateAndMapAnonymous(buffer_size)) { - NOTREACHED() << "Cannot map shared memory buffer"; - return base::SharedMemory::NULLHandle(); - } - base::SharedMemoryHandle handle; - shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), &handle); - return handle; -} - -void MockRenderThread::RegisterExtension(v8::Extension* extension) { -} - -bool MockRenderThread::IsRegisteredExtension( - const std::string& v8_extension_name) const { - return false; -} - -void MockRenderThread::ScheduleIdleHandler(double initial_delay_s) { -} - -void MockRenderThread::IdleHandler() { -} - -double MockRenderThread::GetIdleNotificationDelayInS() const { - return 0.0; -} - -void MockRenderThread::SetIdleNotificationDelayInS( - double idle_notification_delay_in_s) { -} - -#if defined(OS_WIN) -void MockRenderThread::PreCacheFont(const LOGFONT& log_font) { -} - -void MockRenderThread::ReleaseCachedFonts() { -} - -#endif // OS_WIN - -void MockRenderThread::SendCloseMessage() { - ViewMsg_Close msg(routing_id_); - widget_->OnMessageReceived(msg); -} - -bool MockRenderThread::OnMessageReceived(const IPC::Message& msg) { - // Save the message in the sink. - sink_.OnMessageReceived(msg); +bool ChromeMockRenderThread::OnMessageReceived(const IPC::Message& msg) { + if (content::MockRenderThread::OnMessageReceived(msg)) + return true; // Some messages we do special handling. 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_BEGIN_MESSAGE_MAP_EX(ChromeMockRenderThread, msg, msg_is_ok) IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, OnMsgOpenChannelToExtension) IPC_MESSAGE_HANDLER(PrintHostMsg_GetDefaultPrintSettings, @@ -200,33 +64,15 @@ bool MockRenderThread::OnMessageReceived(const IPC::Message& msg) { return handled; } -// The Widget expects to be returned valid route_id. -void MockRenderThread::OnMsgCreateWidget(int opener_id, - WebKit::WebPopupType popup_type, - int* route_id) { - opener_id_ = opener_id; - *route_id = routing_id_; -} - -void MockRenderThread::OnMsgOpenChannelToExtension( +void ChromeMockRenderThread::OnMsgOpenChannelToExtension( int routing_id, const std::string& source_extension_id, const std::string& target_extension_id, const std::string& channel_name, int* port_id) { *port_id = 0; } -#if defined(OS_WIN) -void MockRenderThread::OnDuplicateSection( - base::SharedMemoryHandle renderer_handle, - base::SharedMemoryHandle* browser_handle) { - // We don't have to duplicate the input handles since RenderViewTest does not - // separate a browser process from a renderer process. - *browser_handle = renderer_handle; -} -#endif // defined(OS_WIN) - #if defined(OS_CHROMEOS) -void MockRenderThread::OnAllocateTempFileForPrinting( +void ChromeMockRenderThread::OnAllocateTempFileForPrinting( base::FileDescriptor* renderer_fd, int* browser_fd) { renderer_fd->fd = *browser_fd = -1; @@ -240,18 +86,18 @@ void MockRenderThread::OnAllocateTempFileForPrinting( } } -void MockRenderThread::OnTempFileForPrintingWritten(int browser_fd) { +void ChromeMockRenderThread::OnTempFileForPrintingWritten(int browser_fd) { close(browser_fd); } #endif // defined(OS_CHROMEOS) -void MockRenderThread::OnGetDefaultPrintSettings( +void ChromeMockRenderThread::OnGetDefaultPrintSettings( PrintMsg_Print_Params* params) { if (printer_.get()) printer_->GetDefaultPrintSettings(params); } -void MockRenderThread::OnScriptedPrint( +void ChromeMockRenderThread::OnScriptedPrint( const PrintHostMsg_ScriptedPrint_Params& params, PrintMsg_PrintPages_Params* settings) { if (print_dialog_user_response_ && printer_.get()) { @@ -262,36 +108,38 @@ void MockRenderThread::OnScriptedPrint( } } -void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { +void ChromeMockRenderThread::OnDidGetPrintedPagesCount( + int cookie, int number_pages) { if (printer_.get()) printer_->SetPrintedPagesCount(cookie, number_pages); } -void MockRenderThread::OnDidPrintPage( +void ChromeMockRenderThread::OnDidPrintPage( const PrintHostMsg_DidPrintPage_Params& params) { if (printer_.get()) printer_->PrintPage(params); } -void MockRenderThread::OnDidGetPreviewPageCount( +void ChromeMockRenderThread::OnDidGetPreviewPageCount( const PrintHostMsg_DidGetPreviewPageCount_Params& params) { print_preview_pages_remaining_ = params.page_count; } -void MockRenderThread::OnDidPreviewPage( +void ChromeMockRenderThread::OnDidPreviewPage( const PrintHostMsg_DidPreviewPage_Params& params) { DCHECK(params.page_number >= printing::FIRST_PAGE_INDEX); print_preview_pages_remaining_--; } -void MockRenderThread::OnCheckForCancel(const std::string& preview_ui_addr, - int preview_request_id, - bool* cancel) { +void ChromeMockRenderThread::OnCheckForCancel( + const std::string& preview_ui_addr, + int preview_request_id, + bool* cancel) { *cancel = (print_preview_pages_remaining_ == print_preview_cancel_page_number_); } -void MockRenderThread::OnUpdatePrintSettings( +void ChromeMockRenderThread::OnUpdatePrintSettings( int document_cookie, const base::DictionaryValue& job_settings, PrintMsg_PrintPages_Params* params) { @@ -337,14 +185,14 @@ void MockRenderThread::OnUpdatePrintSettings( } } -void MockRenderThread::set_print_dialog_user_response(bool response) { +void ChromeMockRenderThread::set_print_dialog_user_response(bool response) { print_dialog_user_response_ = response; } -void MockRenderThread::set_print_preview_cancel_page_number(int page) { +void ChromeMockRenderThread::set_print_preview_cancel_page_number(int page) { print_preview_cancel_page_number_ = page; } -int MockRenderThread::print_preview_pages_remaining() { +int ChromeMockRenderThread::print_preview_pages_remaining() { return print_preview_pages_remaining_; } diff --git a/chrome/renderer/chrome_mock_render_thread.h b/chrome/renderer/chrome_mock_render_thread.h new file mode 100644 index 0000000..0ad4798 --- /dev/null +++ b/chrome/renderer/chrome_mock_render_thread.h @@ -0,0 +1,102 @@ +// Copyright (c) 2011 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_CHROME_MOCK_RENDER_THREAD_H_ +#define CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ +#pragma once + +#include <string> + +#include "base/compiler_specific.h" +#include "chrome/common/extensions/extension_set.h" +#include "chrome/renderer/mock_printer.h" +#include "content/test/mock_render_thread.h" + +namespace base { +class DictionaryValue; +} + +struct PrintHostMsg_DidGetPreviewPageCount_Params; +struct PrintHostMsg_DidPreviewPage_Params; +struct PrintHostMsg_ScriptedPrint_Params; +struct PrintMsg_PrintPages_Params; +struct PrintMsg_Print_Params; + +// Extends content::MockRenderThread to know about printing and +// extension messages. +class ChromeMockRenderThread : public content::MockRenderThread { + public: + ChromeMockRenderThread(); + virtual ~ChromeMockRenderThread(); + + ////////////////////////////////////////////////////////////////////////// + // The following functions are called by the test itself. + + // Returns the pseudo-printer instance. + MockPrinter* printer() const { return printer_.get(); } + + // Call with |response| set to true if the user wants to print. + // False if the user decides to cancel. + void set_print_dialog_user_response(bool response); + + // Cancel print preview when print preview has |page| remaining pages. + void set_print_preview_cancel_page_number(int page); + + // Get the number of pages to generate for print preview. + int print_preview_pages_remaining(); + + private: + // Overrides base class implementation to add custom handling for + // print and extensions. + virtual bool OnMessageReceived(const IPC::Message& msg); + + // The callee expects to be returned a valid channel_id. + void OnMsgOpenChannelToExtension( + int routing_id, const std::string& extension_id, + const std::string& source_extension_id, + const std::string& target_extension_id, int* port_id); + +#if defined(OS_CHROMEOS) + void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd, + int* browser_fd); + void OnTempFileForPrintingWritten(int browser_fd); +#endif + + // PrintWebViewHelper expects default print settings. + void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting); + + // PrintWebViewHelper expects final print settings from the user. + void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, + PrintMsg_PrintPages_Params* settings); + + void OnDidGetPrintedPagesCount(int cookie, int number_pages); + void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); + void OnDidGetPreviewPageCount( + const PrintHostMsg_DidGetPreviewPageCount_Params& params); + void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); + void OnCheckForCancel(const std::string& preview_ui_addr, + int preview_request_id, + bool* cancel); + + + // For print preview, PrintWebViewHelper will update settings. + void OnUpdatePrintSettings(int document_cookie, + const base::DictionaryValue& job_settings, + PrintMsg_PrintPages_Params* params); + + // A mock printer device used for printing tests. + scoped_ptr<MockPrinter> printer_; + + // True to simulate user clicking print. False to cancel. + bool print_dialog_user_response_; + + // Simulates cancelling print preview if |print_preview_pages_remaining_| + // equals this. + int print_preview_cancel_page_number_; + + // Number of pages to generate for print preview. + int print_preview_pages_remaining_; +}; + +#endif // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ diff --git a/chrome/renderer/content_settings_observer_browsertest.cc b/chrome/renderer/content_settings_observer_browsertest.cc index 206fd6f..735501d 100644 --- a/chrome/renderer/content_settings_observer_browsertest.cc +++ b/chrome/renderer/content_settings_observer_browsertest.cc @@ -5,7 +5,7 @@ #include "chrome/common/content_settings.h" #include "chrome/common/render_messages.h" #include "chrome/renderer/content_settings_observer.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "content/common/view_messages.h" #include "content/public/renderer/render_view.h" #include "ipc/ipc_message_macros.h" @@ -50,7 +50,7 @@ bool MockContentSettingsObserver::Send(IPC::Message* message) { } // namespace -TEST_F(RenderViewTest, DidBlockContentType) { +TEST_F(ChromeRenderViewTest, DidBlockContentType) { MockContentSettingsObserver observer(view_); EXPECT_CALL(observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string())); @@ -72,7 +72,7 @@ TEST_F(RenderViewTest, DidBlockContentType) { } // Tests that multiple invokations of AllowDOMStorage result in a single IPC. -TEST_F(RenderViewTest, AllowDOMStorage) { +TEST_F(ChromeRenderViewTest, AllowDOMStorage) { // Load some HTML, so we have a valid security origin. LoadHTML("<html></html>"); MockContentSettingsObserver observer(view_); @@ -89,7 +89,7 @@ TEST_F(RenderViewTest, AllowDOMStorage) { } // Regression test for http://crbug.com/35011 -TEST_F(RenderViewTest, JSBlockSentAfterPageLoad) { +TEST_F(ChromeRenderViewTest, JSBlockSentAfterPageLoad) { // 1. Load page with JS. std::string html = "<html>" "<head>" @@ -98,7 +98,7 @@ TEST_F(RenderViewTest, JSBlockSentAfterPageLoad) { "<body>" "</body>" "</html>"; - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); LoadHTML(html.c_str()); // 2. Block JavaScript. @@ -112,7 +112,7 @@ TEST_F(RenderViewTest, JSBlockSentAfterPageLoad) { // Make sure no pending messages are in the queue. ProcessPendingMessages(); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // 3. Reload page. ViewMsg_Navigate_Params params; @@ -128,8 +128,8 @@ TEST_F(RenderViewTest, JSBlockSentAfterPageLoad) { // the navigation notifiction is sent. int navigation_index = -1; int block_index = -1; - for (size_t i = 0; i < render_thread_.sink().message_count(); ++i) { - const IPC::Message* msg = render_thread_.sink().GetMessageAt(i); + for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { + const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); if (msg->type() == ViewHostMsg_FrameNavigate::ID) navigation_index = i; if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) @@ -140,7 +140,7 @@ TEST_F(RenderViewTest, JSBlockSentAfterPageLoad) { EXPECT_LT(navigation_index, block_index); } -TEST_F(RenderViewTest, PluginsTemporarilyAllowed) { +TEST_F(ChromeRenderViewTest, PluginsTemporarilyAllowed) { // Load some HTML. LoadHTML("<html>Foo</html>"); diff --git a/chrome/renderer/mock_keyboard.cc b/chrome/renderer/mock_keyboard.cc deleted file mode 100644 index b18f3f6..0000000 --- a/chrome/renderer/mock_keyboard.cc +++ /dev/null @@ -1,47 +0,0 @@ -// 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. - -#include "chrome/renderer/mock_keyboard.h" - -#include "base/logging.h" - -MockKeyboard::MockKeyboard() - : keyboard_layout_(LAYOUT_NULL), - keyboard_modifiers_(INVALID) { -} - -MockKeyboard::~MockKeyboard() { -} - -int MockKeyboard::GetCharacters(Layout layout, - int key_code, - Modifiers modifiers, - std::wstring* output) { -#if defined(OS_WIN) - CHECK(output); - // Change the keyboard layout only when we have to because it takes a lot of - // time to load a keyboard-layout driver. - // When we change the layout, we reset the modifier status to force updating - // the keyboard status. - if (layout != keyboard_layout_) { - if (!driver_.SetLayout(layout)) - return -1; - keyboard_layout_ = layout; - keyboard_modifiers_ = INVALID; - } - - // Update the keyboard states. - if (modifiers != keyboard_modifiers_) { - if (!driver_.SetModifiers(modifiers)) - return -1; - keyboard_modifiers_ = modifiers; - } - - // Retrieve Unicode characters associate with the key code. - return driver_.GetCharacters(key_code, output); -#else - NOTIMPLEMENTED(); - return -1; -#endif -} diff --git a/chrome/renderer/mock_keyboard.h b/chrome/renderer/mock_keyboard.h deleted file mode 100644 index 842ec63..0000000 --- a/chrome/renderer/mock_keyboard.h +++ /dev/null @@ -1,107 +0,0 @@ -// 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_KEYBOARD_H_ -#define CHROME_RENDERER_MOCK_KEYBOARD_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" - -#if defined(OS_WIN) -#include "chrome/renderer/mock_keyboard_driver_win.h" -#endif - -// A mock keyboard interface. -// This class defines a pseudo keyboard device, which implements mappings from -// a tuple (layout, key code, modifiers) to Unicode characters so that -// engineers can write RenderViewTest cases without taking care of such -// mappings. (This mapping is not trivial when using non-US keyboards.) -// A pseudo keyboard device consists of two parts: a platform-independent part -// and a platform-dependent part. This class implements the platform-independent -// part. The platform-dependet part is implemented in the MockKeyboardWin class. -// This class is usually called from RenderViewTest::SendKeyEvent(). -class MockKeyboard { - public: - // Represents keyboard-layouts. - enum Layout { - LAYOUT_NULL, - LAYOUT_ARABIC, - LAYOUT_BULGARIAN, - LAYOUT_CHINESE_TRADITIONAL, - LAYOUT_CZECH, - LAYOUT_DANISH, - LAYOUT_GERMAN, - LAYOUT_GREEK, - LAYOUT_UNITED_STATES, - LAYOUT_SPANISH, - LAYOUT_FINNISH, - LAYOUT_FRENCH, - LAYOUT_HEBREW, - LAYOUT_HUNGARIAN, - LAYOUT_ICELANDIC, - LAYOUT_ITALIAN, - LAYOUT_JAPANESE, - LAYOUT_KOREAN, - LAYOUT_POLISH, - LAYOUT_PORTUGUESE_BRAZILIAN, - LAYOUT_ROMANIAN, - LAYOUT_RUSSIAN, - LAYOUT_CROATIAN, - LAYOUT_SLOVAK, - LAYOUT_THAI, - LAYOUT_SWEDISH, - LAYOUT_TURKISH_Q, - LAYOUT_VIETNAMESE, - LAYOUT_DEVANAGARI_INSCRIPT, - LAYOUT_PORTUGUESE, - LAYOUT_UNITED_STATES_DVORAK, - LAYOUT_CANADIAN_FRENCH, - }; - - // Enumerates keyboard modifiers. - // These modifiers explicitly distinguish left-keys and right-keys because we - // should emulate AltGr (right-alt) key, used by many European keyboards to - // input alternate graph characters. - enum Modifiers { - INVALID = -1, - NONE = 0, - LEFT_SHIFT = 1 << 0, - LEFT_CONTROL = 1 << 1, - LEFT_ALT = 1 << 2, - LEFT_META = 1 << 3, - RIGHT_SHIFT = 1 << 4, - RIGHT_CONTROL = 1 << 5, - RIGHT_ALT = 1 << 6, - RIGHT_META = 1 << 7, - KEYPAD = 1 << 8, - AUTOREPEAAT = 1 << 9, - }; - - MockKeyboard(); - ~MockKeyboard(); - - // Retrieves Unicode characters composed from the the specified keyboard - // layout, key code, and modifiers, i.e. characters returned when we type - // specified keys on a specified layout. - // This function returns the length of Unicode characters filled in the - // |output| parameter. - int GetCharacters(Layout layout, - int key_code, - Modifiers modifiers, - std::wstring* output); - - private: - Layout keyboard_layout_; - Modifiers keyboard_modifiers_; - -#if defined(OS_WIN) - MockKeyboardDriverWin driver_; -#endif - - DISALLOW_COPY_AND_ASSIGN(MockKeyboard); -}; - -#endif // CHROME_RENDERER_MOCK_KEYBOARD_H_ diff --git a/chrome/renderer/mock_keyboard_driver_win.cc b/chrome/renderer/mock_keyboard_driver_win.cc deleted file mode 100644 index ea88007..0000000 --- a/chrome/renderer/mock_keyboard_driver_win.cc +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (c) 2010 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. - -#include "chrome/renderer/mock_keyboard_driver_win.h" - -#include "base/basictypes.h" -#include "base/logging.h" -#include "chrome/renderer/mock_keyboard.h" - -MockKeyboardDriverWin::MockKeyboardDriverWin() { - // Save the keyboard layout and status of the application. - // This class changes the keyboard layout and status of this application. - // This change may break succeeding tests. To prevent this possible break, we - // should save the layout and status here to restore when this instance is - // destroyed. - original_keyboard_layout_ = GetKeyboardLayout(0); - active_keyboard_layout_ = original_keyboard_layout_; - GetKeyboardState(&original_keyboard_states_[0]); - - const UINT num_keyboard_layouts = GetKeyboardLayoutList(0, NULL); - DCHECK(num_keyboard_layouts > 0); - - orig_keyboard_layouts_list_.resize(num_keyboard_layouts); - GetKeyboardLayoutList(num_keyboard_layouts, &orig_keyboard_layouts_list_[0]); - - memset(&keyboard_states_[0], 0, sizeof(keyboard_states_)); -} - -MockKeyboardDriverWin::~MockKeyboardDriverWin() { - // Unload the keyboard-layout driver, restore the keyboard state, and reset - // the keyboard layout for succeeding tests. - MaybeUnloadActiveLayout(); - SetKeyboardState(&original_keyboard_states_[0]); - ActivateKeyboardLayout(original_keyboard_layout_, KLF_RESET); -} - -void MockKeyboardDriverWin::MaybeUnloadActiveLayout() { - // Workaround for http://crbug.com/12093 - // Only unload a keyboard layout if it was loaded by this mock driver. - // Contrary to the documentation on MSDN unloading a keyboard layout - // previously loaded by the system causes that layout to stop working. - // We have confirmation of this behavior on XP & Vista. - for (size_t i = 0; i < orig_keyboard_layouts_list_.size(); ++i) { - if (orig_keyboard_layouts_list_[i] == active_keyboard_layout_) - return; - } - - // If we got here, this keyboard layout wasn't loaded by the system so it's - // safe to unload it ourselve's. - UnloadKeyboardLayout(active_keyboard_layout_); - active_keyboard_layout_ = original_keyboard_layout_; -} - -bool MockKeyboardDriverWin::SetLayout(int layout) { - // Unload the current keyboard-layout driver and load a new keyboard-layout - // driver for mapping a virtual key-code to a Unicode character. - MaybeUnloadActiveLayout(); - - // Scan the mapping table and retrieve a Language ID for the input layout. - // Load the keyboard-layout driver when we find a Language ID. - // This Language IDs are copied from the registry - // "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard layouts". - // TODO(hbono): Add more keyboard-layout drivers. - static const struct { - const wchar_t* language; - MockKeyboard::Layout keyboard_layout; - } kLanguageIDs[] = { - {L"00000401", MockKeyboard::LAYOUT_ARABIC}, - {L"00000402", MockKeyboard::LAYOUT_BULGARIAN}, - {L"00000404", MockKeyboard::LAYOUT_CHINESE_TRADITIONAL}, - {L"00000405", MockKeyboard::LAYOUT_CZECH}, - {L"00000406", MockKeyboard::LAYOUT_DANISH}, - {L"00000407", MockKeyboard::LAYOUT_GERMAN}, - {L"00000408", MockKeyboard::LAYOUT_GREEK}, - {L"00000409", MockKeyboard::LAYOUT_UNITED_STATES}, - {L"0000040a", MockKeyboard::LAYOUT_SPANISH}, - {L"0000040b", MockKeyboard::LAYOUT_FINNISH}, - {L"0000040c", MockKeyboard::LAYOUT_FRENCH}, - {L"0000040d", MockKeyboard::LAYOUT_HEBREW}, - {L"0000040e", MockKeyboard::LAYOUT_HUNGARIAN}, - {L"00000410", MockKeyboard::LAYOUT_ITALIAN}, - {L"00000411", MockKeyboard::LAYOUT_JAPANESE}, - {L"00000412", MockKeyboard::LAYOUT_KOREAN}, - {L"00000415", MockKeyboard::LAYOUT_POLISH}, - {L"00000416", MockKeyboard::LAYOUT_PORTUGUESE_BRAZILIAN}, - {L"00000418", MockKeyboard::LAYOUT_ROMANIAN}, - {L"00000419", MockKeyboard::LAYOUT_RUSSIAN}, - {L"0000041a", MockKeyboard::LAYOUT_CROATIAN}, - {L"0000041b", MockKeyboard::LAYOUT_SLOVAK}, - {L"0000041e", MockKeyboard::LAYOUT_THAI}, - {L"0000041d", MockKeyboard::LAYOUT_SWEDISH}, - {L"0000041f", MockKeyboard::LAYOUT_TURKISH_Q}, - {L"0000042a", MockKeyboard::LAYOUT_VIETNAMESE}, - {L"00000439", MockKeyboard::LAYOUT_DEVANAGARI_INSCRIPT}, - {L"00000816", MockKeyboard::LAYOUT_PORTUGUESE}, - {L"00001409", MockKeyboard::LAYOUT_UNITED_STATES_DVORAK}, - {L"00001009", MockKeyboard::LAYOUT_CANADIAN_FRENCH}, - }; - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLanguageIDs); ++i) { - if (layout == kLanguageIDs[i].keyboard_layout) { - HKL new_keyboard_layout = LoadKeyboardLayout(kLanguageIDs[i].language, - KLF_ACTIVATE); - // loaded_keyboard_layout_ must always have a valid keyboard handle - // so we only assign upon success. - if (new_keyboard_layout) { - active_keyboard_layout_ = new_keyboard_layout; - return true; - } - - return false; - } - } - - // Return false if there are not any matching drivers. - return false; -} - -bool MockKeyboardDriverWin::SetModifiers(int modifiers) { - // Over-write the keyboard status with our modifier-key status. - // WebInputEventFactory::keyboardEvent() uses GetKeyState() to retrive - // modifier-key status. So, we update the modifier-key status with this - // SetKeyboardState() call before creating NativeWebKeyboardEvent - // instances. - memset(&keyboard_states_[0], 0, sizeof(keyboard_states_)); - static const struct { - int key_code; - int mask; - } kModifierMasks[] = { - {VK_SHIFT, MockKeyboard::LEFT_SHIFT | MockKeyboard::RIGHT_SHIFT}, - {VK_CONTROL, MockKeyboard::LEFT_CONTROL | MockKeyboard::RIGHT_CONTROL}, - {VK_MENU, MockKeyboard::LEFT_ALT | MockKeyboard::RIGHT_ALT}, - {VK_LSHIFT, MockKeyboard::LEFT_SHIFT}, - {VK_LCONTROL, MockKeyboard::LEFT_CONTROL}, - {VK_LMENU, MockKeyboard::LEFT_ALT}, - {VK_RSHIFT, MockKeyboard::RIGHT_SHIFT}, - {VK_RCONTROL, MockKeyboard::RIGHT_CONTROL}, - {VK_RMENU, MockKeyboard::RIGHT_ALT}, - }; - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kModifierMasks); ++i) { - const int kKeyDownMask = 0x80; - if (modifiers & kModifierMasks[i].mask) - keyboard_states_[kModifierMasks[i].key_code] = kKeyDownMask; - } - SetKeyboardState(&keyboard_states_[0]); - - return true; -} - -int MockKeyboardDriverWin::GetCharacters(int key_code, - std::wstring* output) { - // Retrieve Unicode characters composed from the input key-code and - // the mofifiers. - CHECK(output); - wchar_t code[16]; - int length = ToUnicodeEx(key_code, MapVirtualKey(key_code, 0), - &keyboard_states_[0], &code[0], arraysize(code), 0, - active_keyboard_layout_); - if (length > 0) - output->assign(code); - return length; -} diff --git a/chrome/renderer/mock_keyboard_driver_win.h b/chrome/renderer/mock_keyboard_driver_win.h deleted file mode 100644 index bbe65f1..0000000 --- a/chrome/renderer/mock_keyboard_driver_win.h +++ /dev/null @@ -1,42 +0,0 @@ -// 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_KEYBOARD_DRIVER_WIN_H_ -#define CHROME_RENDERER_MOCK_KEYBOARD_DRIVER_WIN_H_ -#pragma once - -#include <windows.h> - -#include <string> -#include <vector> -#include "base/basictypes.h" - -// Implements the platform-dependent part of a pseudo keyboard device for -// Windows. -class MockKeyboardDriverWin { - public: - MockKeyboardDriverWin(); - ~MockKeyboardDriverWin(); - - bool SetLayout(int layout); - bool SetModifiers(int modifiers); - int GetCharacters(int key_code, std::wstring* code); - - private: - void MaybeUnloadActiveLayout(); - - // The list of keyboard drivers that are installed on this machine. - std::vector<HKL> orig_keyboard_layouts_list_; - // The active keyboard driver at the time the Ctor was called. - HKL original_keyboard_layout_; - // The currently active driver. - HKL active_keyboard_layout_; - BYTE original_keyboard_states_[256]; - - BYTE keyboard_states_[256]; - - DISALLOW_COPY_AND_ASSIGN(MockKeyboardDriverWin); -}; - -#endif // CHROME_RENDERER_MOCK_KEYBOARD_DRIVER_WIN_H_ diff --git a/chrome/renderer/mock_render_thread.h b/chrome/renderer/mock_render_thread.h deleted file mode 100644 index cf18ed9..0000000 --- a/chrome/renderer/mock_render_thread.h +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (c) 2011 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_ -#pragma once - -#include <string> - -#include "base/compiler_specific.h" -#include "base/shared_memory.h" -#include "chrome/common/extensions/extension_set.h" -#include "chrome/renderer/mock_printer.h" -#include "content/public/renderer/render_thread.h" -#include "ipc/ipc_test_sink.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" - -namespace IPC { -class MessageReplyDeserializer; -} - -namespace base { -class DictionaryValue; -} - -struct PrintHostMsg_DidGetPreviewPageCount_Params; -struct PrintHostMsg_DidPreviewPage_Params; -struct PrintHostMsg_ScriptedPrint_Params; -struct PrintMsg_PrintPages_Params; -struct PrintMsg_Print_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. -// ViewMsg_Close : async, send to the Widget. -class MockRenderThread : public content::RenderThread { - public: - MockRenderThread(); - virtual ~MockRenderThread(); - - // Provides access to the messages that have been received by this thread. - IPC::TestSink& sink() { return sink_; } - - // content::RenderThread implementation: - virtual bool Send(IPC::Message* msg) OVERRIDE; - virtual MessageLoop* GetMessageLoop() OVERRIDE; - virtual IPC::SyncChannel* GetChannel() OVERRIDE; - virtual std::string GetLocale() OVERRIDE; - virtual void AddRoute(int32 routing_id, - IPC::Channel::Listener* listener) OVERRIDE; - virtual void RemoveRoute(int32 routing_id) OVERRIDE; - virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; - virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE; - virtual void SetOutgoingMessageFilter( - IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE; - virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE; - virtual void RemoveObserver( - content::RenderProcessObserver* observer) OVERRIDE; - virtual void SetResourceDispatcherDelegate( - content::ResourceDispatcherDelegate* delegate) OVERRIDE; - virtual void WidgetHidden() OVERRIDE; - virtual void WidgetRestored() OVERRIDE; - virtual void EnsureWebKitInitialized() OVERRIDE; - virtual void RecordUserMetrics(const std::string& action) OVERRIDE; - virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer( - uint32 buffer_size) OVERRIDE; - virtual void RegisterExtension(v8::Extension* extension) OVERRIDE; - virtual bool IsRegisteredExtension( - const std::string& v8_extension_name) const OVERRIDE; - virtual void ScheduleIdleHandler(double initial_delay_s) OVERRIDE; - virtual void IdleHandler() OVERRIDE; - virtual double GetIdleNotificationDelayInS() const OVERRIDE; - virtual void SetIdleNotificationDelayInS( - double idle_notification_delay_in_s) OVERRIDE; -#if defined(OS_WIN) - virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE; - virtual void ReleaseCachedFonts() OVERRIDE; -#endif - - ////////////////////////////////////////////////////////////////////////// - // The following functions are called by the test itself. - - void set_routing_id(int32 id) { - routing_id_ = id; - } - - int32 opener_id() const { - return opener_id_; - } - - bool has_widget() const { - return widget_ ? true : false; - } - - // Simulates the Widget receiving a close message. This should result - // on releasing the internal reference counts and destroying the internal - // state. - void SendCloseMessage(); - - // Returns the pseudo-printer instance. - MockPrinter* printer() const { return printer_.get(); } - - // Call with |response| set to true if the user wants to print. - // False if the user decides to cancel. - void set_print_dialog_user_response(bool response); - - // Cancel print preview when print preview has |page| remaining pages. - void set_print_preview_cancel_page_number(int page); - - // Get the number of pages to generate for print preview. - int print_preview_pages_remaining(); - - private: - // This function operates as a regular IPC listener. - bool OnMessageReceived(const IPC::Message& msg); - - // The Widget expects to be returned valid route_id. - void OnMsgCreateWidget(int opener_id, - WebKit::WebPopupType popup_type, - int* route_id); - - // The callee expects to be returned a valid channel_id. - void OnMsgOpenChannelToExtension( - int routing_id, const std::string& extension_id, - const std::string& source_extension_id, - const std::string& target_extension_id, int* port_id); - -#if defined(OS_WIN) - void OnDuplicateSection(base::SharedMemoryHandle renderer_handle, - base::SharedMemoryHandle* browser_handle); -#endif - -#if defined(OS_CHROMEOS) - void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd, - int* browser_fd); - void OnTempFileForPrintingWritten(int browser_fd); -#endif - - // PrintWebViewHelper expects default print settings. - void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting); - - // PrintWebViewHelper expects final print settings from the user. - void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, - PrintMsg_PrintPages_Params* settings); - - void OnDidGetPrintedPagesCount(int cookie, int number_pages); - void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); - void OnDidGetPreviewPageCount( - const PrintHostMsg_DidGetPreviewPageCount_Params& params); - void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); - void OnCheckForCancel(const std::string& preview_ui_addr, - int preview_request_id, - bool* cancel); - - - // For print preview, PrintWebViewHelper will update settings. - void OnUpdatePrintSettings(int document_cookie, - const base::DictionaryValue& job_settings, - PrintMsg_PrintPages_Params* params); - - IPC::TestSink sink_; - - // Routing id what will be assigned to the Widget. - int32 routing_id_; - - // Opener id reported by the Widget. - int32 opener_id_; - - // We only keep track of one Widget, we learn its pointer when it - // adds a new route. - IPC::Channel::Listener* widget_; - - // The last known good deserializer for sync messages. - scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer_; - - // A mock printer device used for printing tests. - scoped_ptr<MockPrinter> printer_; - - // True to simulate user clicking print. False to cancel. - bool print_dialog_user_response_; - - // Simulates cancelling print preview if |print_preview_pages_remaining_| - // equals this. - int print_preview_cancel_page_number_; - - // Number of pages to generate for print preview. - int print_preview_pages_remaining_; -}; - -#endif // CHROME_RENDERER_MOCK_RENDER_THREAD_H_ diff --git a/chrome/renderer/page_click_tracker_browsertest.cc b/chrome/renderer/page_click_tracker_browsertest.cc index f960553..bf034bc 100644 --- a/chrome/renderer/page_click_tracker_browsertest.cc +++ b/chrome/renderer/page_click_tracker_browsertest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -6,7 +6,7 @@ #include "chrome/common/render_messages.h" #include "chrome/renderer/page_click_listener.h" #include "chrome/renderer/page_click_tracker.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "content/public/renderer/render_view.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" @@ -48,7 +48,7 @@ class TestPageClickListener : public PageClickListener { }; // Tests that PageClickTracker does notify correctly when a node is clicked. -TEST_F(RenderViewTest, PageClickTracker) { +TEST_F(ChromeRenderViewTest, PageClickTracker) { // RenderView creates PageClickTracker but it doesn't keep it around. Rather // than make it do so for the test, we create a new object. PageClickTracker* page_click_tracker = new PageClickTracker(view_); diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc index 3c362cf..9f0a9ac 100644 --- a/chrome/renderer/print_web_view_helper_browsertest.cc +++ b/chrome/renderer/print_web_view_helper_browsertest.cc @@ -5,7 +5,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/print_messages.h" #include "chrome/renderer/print_web_view_helper.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "content/public/renderer/render_view.h" #include "printing/print_job_constants.h" #include "testing/gtest/include/gtest/gtest.h" @@ -56,7 +56,7 @@ void CreatePrintSettingsDictionary(DictionaryValue* dict) { } // namespace -class PrintWebViewHelperTestBase : public RenderViewTest { +class PrintWebViewHelperTestBase : public ChromeRenderViewTest { public: PrintWebViewHelperTestBase() {} ~PrintWebViewHelperTestBase() {} @@ -72,7 +72,7 @@ class PrintWebViewHelperTestBase : public RenderViewTest { // the print code. #else const IPC::Message* page_cnt_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( PrintHostMsg_DidGetPrintedPagesCount::ID); ASSERT_TRUE(page_cnt_msg); PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; @@ -85,12 +85,12 @@ class PrintWebViewHelperTestBase : public RenderViewTest { // Verifies whether the pages printed or not. void VerifyPagesPrinted(bool printed) { #if defined(OS_CHROMEOS) - bool did_print_msg = (render_thread_.sink().GetUniqueMessageMatching( + bool did_print_msg = (render_thread_->sink().GetUniqueMessageMatching( PrintHostMsg_TempFileForPrintingWritten::ID) != NULL); ASSERT_EQ(printed, did_print_msg); #else const IPC::Message* print_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( PrintHostMsg_DidPrintPage::ID); bool did_print_msg = (NULL != print_msg); ASSERT_EQ(printed, did_print_msg); @@ -121,7 +121,7 @@ class PrintWebViewHelperTest : public PrintWebViewHelperTestBase { virtual ~PrintWebViewHelperTest() {} virtual void SetUp() { - RenderViewTest::SetUp(); + ChromeRenderViewTest::SetUp(); } protected: @@ -151,7 +151,7 @@ TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { // frequently. TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { // Pretend user will cancel printing. - render_thread_.set_print_dialog_user_response(false); + chrome_render_thread_->set_print_dialog_user_response(false); // Try to print with window.print() a few times. LoadHTML(kPrintWithJSHTML); LoadHTML(kPrintWithJSHTML); @@ -159,13 +159,13 @@ TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { VerifyPagesPrinted(false); // Pretend user will print. (but printing is blocked.) - render_thread_.set_print_dialog_user_response(true); + chrome_render_thread_->set_print_dialog_user_response(true); LoadHTML(kPrintWithJSHTML); VerifyPagesPrinted(false); // Unblock script initiated printing and verify printing works. PrintWebViewHelper::Get(view_)->ResetScriptedPrintCount(); - render_thread_.printer()->ResetPrinter(); + chrome_render_thread_->printer()->ResetPrinter(); LoadHTML(kPrintWithJSHTML); VerifyPageCount(1); VerifyPagesPrinted(true); @@ -201,7 +201,7 @@ TEST_F(PrintWebViewHelperTest, PrintWithIframe) { PrintWebViewHelper::Get(view_)->OnPrintPages(); // Verify output through MockPrinter. - const MockPrinter* printer(render_thread_.printer()); + const MockPrinter* printer(chrome_render_thread_->printer()); ASSERT_EQ(1, printer->GetPrintedPages()); const printing::Image& image1(printer->GetPrintedPage(0)->image()); @@ -258,7 +258,7 @@ const TestPageData kTestPages[] = { TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { bool baseline = false; - EXPECT_TRUE(render_thread_.printer() != NULL); + EXPECT_TRUE(chrome_render_thread_->printer() != NULL); for (size_t i = 0; i < arraysize(kTestPages); ++i) { // Load an HTML page and print it. LoadHTML(kTestPages[i].page); @@ -270,12 +270,12 @@ TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { // 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(); + size_t pages = chrome_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); + int width = chrome_render_thread_->printer()->GetWidth(0); + int height = chrome_render_thread_->printer()->GetHeight(0); // Check with margin for error. This has been failing with a one pixel // offset on our buildbot. @@ -288,7 +288,8 @@ TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { // 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)); + EXPECT_TRUE( + chrome_render_thread_->printer()->GetBitmapChecksum(0, &bitmap_actual)); if (kTestPages[i].checksum) EXPECT_EQ(kTestPages[i].checksum, bitmap_actual); @@ -297,11 +298,11 @@ TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { // create base-line results. FilePath source_path; file_util::CreateTemporaryFile(&source_path); - render_thread_.printer()->SaveSource(0, source_path); + chrome_render_thread_->printer()->SaveSource(0, source_path); FilePath bitmap_path; file_util::CreateTemporaryFile(&bitmap_path); - render_thread_.printer()->SaveBitmap(0, bitmap_path); + chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path); } } } @@ -319,26 +320,27 @@ class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kEnablePrintPreview); - RenderViewTest::SetUp(); + ChromeRenderViewTest::SetUp(); } protected: void VerifyPrintPreviewCancelled(bool did_cancel) { bool print_preview_cancelled = - (render_thread_.sink().GetUniqueMessageMatching( + (render_thread_->sink().GetUniqueMessageMatching( PrintHostMsg_PrintPreviewCancelled::ID) != NULL); EXPECT_EQ(did_cancel, print_preview_cancelled); } void VerifyPrintPreviewFailed(bool did_fail) { - bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching( - PrintHostMsg_PrintPreviewFailed::ID) != NULL); + bool print_preview_failed = + (render_thread_->sink().GetUniqueMessageMatching( + PrintHostMsg_PrintPreviewFailed::ID) != NULL); EXPECT_EQ(did_fail, print_preview_failed); } void VerifyPrintPreviewGenerated(bool generated_preview) { const IPC::Message* preview_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( PrintHostMsg_MetafileReadyForPrinting::ID); bool did_get_preview_msg = (NULL != preview_msg); ASSERT_EQ(generated_preview, did_get_preview_msg); @@ -352,14 +354,14 @@ class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { } void VerifyPrintFailed(bool did_fail) { - bool print_failed = (render_thread_.sink().GetUniqueMessageMatching( + bool print_failed = (render_thread_->sink().GetUniqueMessageMatching( PrintHostMsg_PrintingFailed::ID) != NULL); EXPECT_EQ(did_fail, print_failed); } void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) { bool print_preview_invalid_printer_settings = - (render_thread_.sink().GetUniqueMessageMatching( + (render_thread_->sink().GetUniqueMessageMatching( PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL); EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings); } @@ -367,9 +369,9 @@ class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { // |page_number| is 0-based. void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) { bool msg_found = false; - size_t msg_count = render_thread_.sink().message_count(); + size_t msg_count = render_thread_->sink().message_count(); for (size_t i = 0; i < msg_count; ++i) { - const IPC::Message* msg = render_thread_.sink().GetMessageAt(i); + const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); if (msg->type() == PrintHostMsg_DidPreviewPage::ID) { PrintHostMsg_DidPreviewPage::Param page_param; PrintHostMsg_DidPreviewPage::Read(msg, &page_param); @@ -399,7 +401,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { CreatePrintSettingsDictionary(&dict); OnPrintPreview(dict); - EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); + EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); VerifyPrintPreviewCancelled(false); VerifyPrintPreviewFailed(false); VerifyPrintPreviewGenerated(true); @@ -448,7 +450,7 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { DictionaryValue empty_dict; OnPrintPreview(empty_dict); - EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); + EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); VerifyPrintPreviewCancelled(false); VerifyPrintPreviewFailed(true); VerifyPrintPreviewGenerated(false); @@ -460,13 +462,14 @@ TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) { LoadHTML(kLongPageHTML); const int kCancelPage = 3; - render_thread_.set_print_preview_cancel_page_number(kCancelPage); + chrome_render_thread_->set_print_preview_cancel_page_number(kCancelPage); // Fill in some dummy values. DictionaryValue dict; CreatePrintSettingsDictionary(&dict); OnPrintPreview(dict); - EXPECT_EQ(kCancelPage, render_thread_.print_preview_pages_remaining()); + EXPECT_EQ(kCancelPage, + chrome_render_thread_->print_preview_pages_remaining()); VerifyPrintPreviewCancelled(true); VerifyPrintPreviewFailed(false); VerifyPrintPreviewGenerated(false); @@ -506,7 +509,7 @@ TEST_F(PrintWebViewHelperPreviewTest, LoadHTML(kPrintPreviewHTML); // Set mock printer to provide invalid settings. - render_thread_.printer()->UseInvalidSettings(); + chrome_render_thread_->printer()->UseInvalidSettings(); // Fill in some dummy values. DictionaryValue dict; @@ -515,7 +518,7 @@ TEST_F(PrintWebViewHelperPreviewTest, // We should have received invalid printer settings from |printer_|. VerifyPrintPreviewInvalidPrinterSettings(true); - EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); + EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); // It should receive the invalid printer settings message only. VerifyPrintPreviewFailed(false); @@ -527,7 +530,7 @@ TEST_F(PrintWebViewHelperPreviewTest, LoadHTML(kPrintPreviewHTML); // Set mock printer to provide invalid settings. - render_thread_.printer()->UseInvalidSettings(); + chrome_render_thread_->printer()->UseInvalidSettings(); // Fill in some dummy values. DictionaryValue dict; diff --git a/chrome/renderer/safe_browsing/malware_dom_details_browsertest.cc b/chrome/renderer/safe_browsing/malware_dom_details_browsertest.cc index afd5def..034655f 100644 --- a/chrome/renderer/safe_browsing/malware_dom_details_browsertest.cc +++ b/chrome/renderer/safe_browsing/malware_dom_details_browsertest.cc @@ -5,10 +5,10 @@ #include "base/stringprintf.h" #include "chrome/common/safe_browsing/safebrowsing_messages.h" #include "chrome/renderer/safe_browsing/malware_dom_details.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "net/base/escape.h" -typedef RenderViewTest MalwareDOMDetailsTest; +typedef ChromeRenderViewTest MalwareDOMDetailsTest; TEST_F(MalwareDOMDetailsTest, Everything) { diff --git a/chrome/renderer/translate_helper_browsertest.cc b/chrome/renderer/translate_helper_browsertest.cc index 56ead08..4efb35d 100644 --- a/chrome/renderer/translate_helper_browsertest.cc +++ b/chrome/renderer/translate_helper_browsertest.cc @@ -1,11 +1,11 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. #include "chrome/common/chrome_constants.h" #include "chrome/common/render_messages.h" #include "chrome/renderer/translate_helper.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "content/public/renderer/render_view.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -39,21 +39,26 @@ class TestTranslateHelper : public TranslateHelper { DISALLOW_COPY_AND_ASSIGN(TestTranslateHelper); }; -class TranslateHelperTest : public RenderViewTest { +class TranslateHelperTest : public ChromeRenderViewTest { public: TranslateHelperTest() : translate_helper_(NULL) {} protected: virtual void SetUp() { - RenderViewTest::SetUp(); + ChromeRenderViewTest::SetUp(); translate_helper_ = new TestTranslateHelper(view_); } + virtual void TearDown() { + delete translate_helper_; + ChromeRenderViewTest::TearDown(); + } + bool GetPageTranslatedMessage(int* page_id, std::string* original_lang, std::string* target_lang, TranslateErrors::Type* error) { - const IPC::Message* message = render_thread_.sink(). + const IPC::Message* message = render_thread_->sink(). GetUniqueMessageMatching(ChromeViewHostMsg_PageTranslated::ID); if (!message) return false; @@ -299,37 +304,37 @@ TEST_F(TranslateHelperTest, MultipleDifferentTranslations) { // Tests that we send the right translatable for a page and that we respect the // "no translate" meta-tag. -TEST_F(RenderViewTest, TranslatablePage) { +TEST_F(ChromeRenderViewTest, TranslatablePage) { // Suppress the normal delay that occurs when the page is loaded before which // the renderer sends the page contents to the browser. SendContentStateImmediately(); LoadHTML("<html><body>A random page with random content.</body></html>"); ProcessPendingMessages(); - const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* message = render_thread_->sink().GetUniqueMessageMatching( ChromeViewHostMsg_TranslateLanguageDetermined::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), message); ChromeViewHostMsg_TranslateLanguageDetermined::Param params; ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); EXPECT_TRUE(params.b); // Translatable should be true. - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Now the page specifies the META tag to prevent translation. LoadHTML("<html><head><meta name=\"google\" value=\"notranslate\"></head>" "<body>A random page with random content.</body></html>"); ProcessPendingMessages(); - message = render_thread_.sink().GetUniqueMessageMatching( + message = render_thread_->sink().GetUniqueMessageMatching( ChromeViewHostMsg_TranslateLanguageDetermined::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), message); ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); EXPECT_FALSE(params.b); // Translatable should be false. - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Try the alternate version of the META tag (content instead of value). LoadHTML("<html><head><meta name=\"google\" content=\"notranslate\"></head>" "<body>A random page with random content.</body></html>"); ProcessPendingMessages(); - message = render_thread_.sink().GetUniqueMessageMatching( + message = render_thread_->sink().GetUniqueMessageMatching( ChromeViewHostMsg_TranslateLanguageDetermined::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), message); ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); @@ -338,7 +343,7 @@ TEST_F(RenderViewTest, TranslatablePage) { // Tests that the language meta tag takes precedence over the CLD when reporting // the page's language. -TEST_F(RenderViewTest, LanguageMetaTag) { +TEST_F(ChromeRenderViewTest, LanguageMetaTag) { // Suppress the normal delay that occurs when the page is loaded before which // the renderer sends the page contents to the browser. SendContentStateImmediately(); @@ -346,20 +351,20 @@ TEST_F(RenderViewTest, LanguageMetaTag) { LoadHTML("<html><head><meta http-equiv=\"content-language\" content=\"es\">" "</head><body>A random page with random content.</body></html>"); ProcessPendingMessages(); - const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* message = render_thread_->sink().GetUniqueMessageMatching( ChromeViewHostMsg_TranslateLanguageDetermined::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), message); ChromeViewHostMsg_TranslateLanguageDetermined::Param params; ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); EXPECT_EQ("es", params.a); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Makes sure we support multiple languages specified. LoadHTML("<html><head><meta http-equiv=\"content-language\" " "content=\" fr , es,en \">" "</head><body>A random page with random content.</body></html>"); ProcessPendingMessages(); - message = render_thread_.sink().GetUniqueMessageMatching( + message = render_thread_->sink().GetUniqueMessageMatching( ChromeViewHostMsg_TranslateLanguageDetermined::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), message); ChromeViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); |