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 | |
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
32 files changed, 673 insertions, 491 deletions
diff --git a/chrome/browser/extensions/extension_messages_browsertest.cc b/chrome/browser/extensions/extension_messages_browsertest.cc index aed3de3..7cb201e 100644 --- a/chrome/browser/extensions/extension_messages_browsertest.cc +++ b/chrome/browser/extensions/extension_messages_browsertest.cc @@ -10,7 +10,7 @@ #include "chrome/renderer/extensions/chrome_v8_context.h" #include "chrome/renderer/extensions/extension_dispatcher.h" #include "chrome/renderer/extensions/renderer_extension_bindings.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 "testing/gtest/include/gtest/gtest.h" @@ -47,9 +47,9 @@ void DispatchOnDisconnect(const ChromeV8ContextSet& v8_context_set, // TODO(aa): Refactor RendererProcessBindings to have fewer dependencies and // make this into a unit test. That will allow us to get rid of cruft like // SetTestExtensionId(). -TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) { +TEST_F(ChromeRenderViewTest, ExtensionMessagesOpenChannel) { extension_dispatcher_->SetTestExtensionId(kTestingExtensionId); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); LoadHTML("<body></body>"); ExecuteJavaScript( "var port = chrome.extension.connect({name:'testName'});" @@ -61,7 +61,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) { // Verify that we opened a channel and sent a message through it. const IPC::Message* open_channel_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( ExtensionHostMsg_OpenChannelToExtension::ID); ASSERT_TRUE(open_channel_msg); void* iter = IPC::SyncMessage::GetDataIterator(open_channel_msg); @@ -70,7 +70,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) { EXPECT_EQ("testName", open_params.d); const IPC::Message* post_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( ExtensionHostMsg_PostMessage::ID); ASSERT_TRUE(post_msg); ExtensionHostMsg_PostMessage::Param post_params; @@ -78,7 +78,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) { EXPECT_EQ("{\"message\":\"content ready\"}", post_params.b); // Now simulate getting a message back from the other side. - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); const int kPortId = 0; RendererExtensionBindings::DeliverMessage( extension_dispatcher_->v8_context_set().GetAll(), @@ -86,7 +86,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) { // Verify that we got it. const IPC::Message* alert_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_RunJavaScriptMessage::ID); ASSERT_TRUE(alert_msg); iter = IPC::SyncMessage::GetDataIterator(alert_msg); @@ -97,7 +97,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) { // Tests that the bindings for handling a new channel connection and channel // closing all works. -TEST_F(RenderViewTest, ExtensionMessagesOnConnect) { +TEST_F(ChromeRenderViewTest, ExtensionMessagesOnConnect) { extension_dispatcher_->SetTestExtensionId(kTestingExtensionId); LoadHTML("<body></body>"); ExecuteJavaScript( @@ -115,7 +115,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) { " alert('disconnected: ' + port.test);" "}"); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Simulate a new connection being opened. const int kPortId = 0; @@ -125,7 +125,7 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) { // Verify that we handled the new connection by posting a message. const IPC::Message* post_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( ExtensionHostMsg_PostMessage::ID); ASSERT_TRUE(post_msg); ExtensionHostMsg_PostMessage::Param post_params; @@ -135,14 +135,14 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) { EXPECT_EQ(expected_msg, post_params.b); // Now simulate getting a message back from the channel opener. - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); RendererExtensionBindings::DeliverMessage( extension_dispatcher_->v8_context_set().GetAll(), kPortId, "{\"val\": 42}", NULL); // Verify that we got it. const IPC::Message* alert_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_RunJavaScriptMessage::ID); ASSERT_TRUE(alert_msg); void* iter = IPC::SyncMessage::GetDataIterator(alert_msg); @@ -151,12 +151,12 @@ TEST_F(RenderViewTest, ExtensionMessagesOnConnect) { EXPECT_EQ(ASCIIToUTF16("got: 42"), alert_param.a); // Now simulate the channel closing. - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); DispatchOnDisconnect(extension_dispatcher_->v8_context_set(), kPortId); // Verify that we got it. alert_msg = - render_thread_.sink().GetUniqueMessageMatching( + render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_RunJavaScriptMessage::ID); ASSERT_TRUE(alert_msg); iter = IPC::SyncMessage::GetDataIterator(alert_msg); diff --git a/chrome/browser/sessions/tab_restore_service_browsertest.cc b/chrome/browser/sessions/tab_restore_service_browsertest.cc index 4895fef5..6284ea1 100644 --- a/chrome/browser/sessions/tab_restore_service_browsertest.cc +++ b/chrome/browser/sessions/tab_restore_service_browsertest.cc @@ -8,11 +8,12 @@ #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" -#include "chrome/test/base/render_view_test.h" +#include "chrome/test/base/chrome_render_view_test.h" #include "chrome/test/base/testing_profile.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/test_tab_contents.h" +#include "content/test/render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" @@ -119,8 +120,8 @@ class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { GURL url3_; scoped_ptr<TabRestoreService> service_; TabRestoreTimeFactory* time_factory_; - RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox - webkit_platform_support_; + content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox + webkit_platform_support_; }; TEST_F(TabRestoreServiceTest, Basic) { diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 3374609..53b4789 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -140,14 +140,10 @@ 'browser/ui/tab_contents/test_tab_contents_wrapper.h', 'common/pref_store_observer_mock.cc', 'common/pref_store_observer_mock.h', - 'renderer/mock_keyboard.cc', - 'renderer/mock_keyboard.h', - 'renderer/mock_keyboard_driver_win.cc', - 'renderer/mock_keyboard_driver_win.h', + 'renderer/chrome_mock_render_thread.cc', + 'renderer/chrome_mock_render_thread.h', 'renderer/mock_printer.cc', 'renderer/mock_printer.h', - 'renderer/mock_render_thread.cc', - 'renderer/mock_render_thread.h', 'renderer/safe_browsing/mock_feature_extractor_clock.cc', 'renderer/safe_browsing/mock_feature_extractor_clock.h', 'test/automation/automation_handle_tracker.cc', @@ -1898,10 +1894,10 @@ 'service/service_process_unittest.cc', 'test/base/browser_with_test_window_test.cc', 'test/base/browser_with_test_window_test.h', + 'test/base/chrome_render_view_test.cc', + 'test/base/chrome_render_view_test.h', 'test/base/menu_model_test.cc', 'test/base/menu_model_test.h', - 'test/base/render_view_test.cc', - 'test/base/render_view_test.h', 'test/base/v8_unit_test.cc', 'test/base/v8_unit_test.h', 'test/data/resource.rc', @@ -2522,8 +2518,8 @@ 'renderer/translate_helper_browsertest.cc', 'test/automation/dom_automation_browsertest.cc', 'test/base/in_process_browser_test_browsertest.cc', - 'test/base/render_view_test.cc', - 'test/base/render_view_test.h', + 'test/base/chrome_render_view_test.cc', + 'test/base/chrome_render_view_test.h', 'test/base/chrome_test_launcher.cc', 'test/data/webui/assertions.js', 'test/data/webui/async_gen-inl.h', 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/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); diff --git a/chrome/test/base/chrome_render_view_test.cc b/chrome/test/base/chrome_render_view_test.cc new file mode 100644 index 0000000..4c4e96a --- /dev/null +++ b/chrome/test/base/chrome_render_view_test.cc @@ -0,0 +1,90 @@ +// 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/test/base/chrome_render_view_test.h" + +#include "chrome/browser/extensions/extension_function_dispatcher.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/print_messages.h" +#include "chrome/common/render_messages.h" +#include "chrome/renderer/autofill/password_autofill_manager.h" +#include "chrome/renderer/extensions/chrome_v8_context_set.h" +#include "chrome/renderer/extensions/chrome_v8_extension.h" +#include "chrome/renderer/extensions/event_bindings.h" +#include "chrome/renderer/extensions/extension_dispatcher.h" +#include "chrome/renderer/extensions/extension_process_bindings.h" +#include "chrome/renderer/extensions/renderer_extension_bindings.h" +#include "content/common/dom_storage_common.h" +#include "content/common/native_web_keyboard_event.h" +#include "content/common/renderer_preferences.h" +#include "content/common/view_messages.h" +#include "content/renderer/render_view_impl.h" +#include "content/renderer/renderer_main_platform_delegate.h" +#include "content/test/mock_render_process.h" +#include "content/test/mock_render_thread.h" +#include "grit/renderer_resources.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" +#include "webkit/glue/webkit_glue.h" + +#if defined(OS_LINUX) && !defined(USE_AURA) +#include "ui/base/gtk/event_synthesis_gtk.h" +#endif + +using WebKit::WebFrame; +using WebKit::WebInputEvent; +using WebKit::WebMouseEvent; +using WebKit::WebScriptController; +using WebKit::WebScriptSource; +using WebKit::WebString; +using WebKit::WebURLRequest; +using autofill::AutofillAgent; +using autofill::PasswordAutofillManager; + +ChromeRenderViewTest::ChromeRenderViewTest() : extension_dispatcher_(NULL) { +} + +ChromeRenderViewTest::~ChromeRenderViewTest() { +} + +void ChromeRenderViewTest::SetUp() { + content::GetContentClient()->set_renderer(&chrome_content_renderer_client_); + extension_dispatcher_ = new ExtensionDispatcher(); + chrome_content_renderer_client_.SetExtensionDispatcher(extension_dispatcher_); + + chrome_render_thread_ = new ChromeMockRenderThread(); + render_thread_.reset(chrome_render_thread_); + content::RenderViewTest::SetUp(); + + WebScriptController::registerExtension(new ChromeV8Extension( + "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL)); + WebScriptController::registerExtension(EventBindings::Get( + extension_dispatcher_)); + WebScriptController::registerExtension(RendererExtensionBindings::Get( + extension_dispatcher_)); + WebScriptController::registerExtension(ExtensionProcessBindings::Get( + extension_dispatcher_)); + WebScriptController::registerExtension(new ChromeV8Extension( + "extensions/apitest.js", IDR_EXTENSION_APITEST_JS, NULL)); + + // RenderView doesn't expose it's PasswordAutofillManager or + // AutofillAgent objects, because it has no need to store them directly + // (they're stored as RenderViewObserver*). So just create another set. + password_autofill_ = new PasswordAutofillManager(view_); + autofill_agent_ = new AutofillAgent(view_, password_autofill_); +} + +void ChromeRenderViewTest::TearDown() { + content::RenderViewTest::TearDown(); + + render_thread_->SendCloseMessage(); + + extension_dispatcher_->OnRenderProcessShutdown(); + extension_dispatcher_ = NULL; +} diff --git a/chrome/test/base/chrome_render_view_test.h b/chrome/test/base/chrome_render_view_test.h new file mode 100644 index 0000000..7085970 --- /dev/null +++ b/chrome/test/base/chrome_render_view_test.h @@ -0,0 +1,43 @@ +// 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_TEST_BASE_CHROME_RENDER_VIEW_TEST_H_ +#define CHROME_TEST_BASE_CHROME_RENDER_VIEW_TEST_H_ +#pragma once + +#include <string> + +#include "chrome/renderer/autofill/autofill_agent.h" +#include "chrome/renderer/chrome_mock_render_thread.h" +#include "chrome/renderer/chrome_content_renderer_client.h" +#include "content/test/render_view_test.h" + +class ExtensionDispatcher; + +namespace autofill { +class AutofillAgent; +class PasswordAutofillManager; +} + +class ChromeRenderViewTest : public content::RenderViewTest { + public: + ChromeRenderViewTest(); + virtual ~ChromeRenderViewTest(); + + protected: + // testing::Test + virtual void SetUp(); + virtual void TearDown(); + + chrome::ChromeContentRendererClient chrome_content_renderer_client_; + ExtensionDispatcher* extension_dispatcher_; + + autofill::PasswordAutofillManager* password_autofill_; + autofill::AutofillAgent* autofill_agent_; + + // Naked pointer as ownership is with content::RenderViewTest::render_thread_. + ChromeMockRenderThread* chrome_render_thread_; +}; + +#endif // CHROME_TEST_BASE_CHROME_RENDER_VIEW_TEST_H_ diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 51717b2..dcbe198 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -60,10 +60,18 @@ 'test/browser_test_base.h', 'test/content_test_suite.cc', 'test/content_test_suite.h', + 'test/mock_keyboard.cc', + 'test/mock_keyboard.h', + 'test/mock_keyboard_driver_win.cc', + 'test/mock_keyboard_driver_win.h', 'test/mock_render_process.cc', 'test/mock_render_process.h', + 'test/mock_render_thread.cc', + 'test/mock_render_thread.h', 'test/render_view_fake_resources_test.cc', 'test/render_view_fake_resources_test.h', + 'test/render_view_test.cc', + 'test/render_view_test.h', 'test/test_browser_context.cc', 'test/test_browser_context.h', 'test/test_content_client.cc', diff --git a/content/renderer/external_popup_menu_unittest.cc b/content/renderer/external_popup_menu_unittest.cc index e6578e7..a1eeed0 100644 --- a/content/renderer/external_popup_menu_unittest.cc +++ b/content/renderer/external_popup_menu_unittest.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 "base/utf_string_conversions.h" -#include "chrome/test/base/render_view_test.h" #include "content/common/view_messages.h" #include "content/renderer/render_view_impl.h" +#include "content/test/render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" @@ -19,7 +19,7 @@ const char* const kEmptySelectID = "myEmptySelect"; } // namespace -class ExternalPopupMenuTest : public RenderViewTest { +class ExternalPopupMenuTest : public content::RenderViewTest { public: ExternalPopupMenuTest() {} @@ -28,7 +28,7 @@ class ExternalPopupMenuTest : public RenderViewTest { } virtual void SetUp() { - RenderViewTest::SetUp(); + content::RenderViewTest::SetUp(); // We need to set this explictly as RenderMain is not run. WebKit::WebView::setUseExternalPopupMenus(true); @@ -71,7 +71,7 @@ class ExternalPopupMenuTest : public RenderViewTest { // Normal case: test showing a select popup, canceling/selecting an item. TEST_F(ExternalPopupMenuTest, NormalCase) { - IPC::TestSink& sink = render_thread_.sink(); + IPC::TestSink& sink = render_thread_->sink(); // Click the text field once. EXPECT_TRUE(SimulateElementClick(kSelectID)); diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc index c944606..defa228 100644 --- a/content/renderer/render_view_browsertest.cc +++ b/content/renderer/render_view_browsertest.cc @@ -7,10 +7,10 @@ #include "base/shared_memory.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "chrome/test/base/render_view_test.h" #include "content/common/native_web_keyboard_event.h" #include "content/common/view_messages.h" #include "content/renderer/render_view_impl.h" +#include "content/test/render_view_test.h" #include "net/base/net_errors.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" @@ -26,7 +26,7 @@ using WebKit::WebString; using WebKit::WebTextDirection; using WebKit::WebURLError; -class RenderViewImplTest : public RenderViewTest { +class RenderViewImplTest : public content::RenderViewTest { public: RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); @@ -43,15 +43,15 @@ TEST_F(RenderViewImplTest, OnNavStateChanged) { LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); // We should NOT have gotten a form state change notification yet. - EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( + EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( ViewHostMsg_UpdateState::ID)); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Change the value of the input. We should have gotten an update state // notification. We need to spin the message loop to catch this update. ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); ProcessPendingMessages(); - EXPECT_TRUE(render_thread_.sink().GetUniqueMessageMatching( + EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID)); } @@ -65,20 +65,20 @@ TEST_F(RenderViewImplTest, LastCommittedUpdateState) { LoadHTML("<div>Page B</div>"); // Check for a valid UpdateState message for page A. - const IPC::Message* msg_A = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_A); int page_id_A; std::string state_A; ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); EXPECT_EQ(1, page_id_A); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Load page C, which will trigger an UpdateState message for page B. LoadHTML("<div>Page C</div>"); // Check for a valid UpdateState for page B. - const IPC::Message* msg_B = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_B); int page_id_B; @@ -86,13 +86,13 @@ TEST_F(RenderViewImplTest, LastCommittedUpdateState) { ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); EXPECT_EQ(2, page_id_B); EXPECT_NE(state_A, state_B); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Load page D, which will trigger an UpdateState message for page C. LoadHTML("<div>Page D</div>"); // Check for a valid UpdateState for page C. - const IPC::Message* msg_C = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_C); int page_id_C; @@ -100,7 +100,7 @@ TEST_F(RenderViewImplTest, LastCommittedUpdateState) { ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C); EXPECT_EQ(3, page_id_C); EXPECT_NE(state_B, state_C); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Go back to C and commit, preparing for our real test. ViewMsg_Navigate_Params params_C; @@ -113,7 +113,7 @@ TEST_F(RenderViewImplTest, LastCommittedUpdateState) { params_C.state = state_C; view()->OnNavigate(params_C); ProcessPendingMessages(); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Go back twice quickly, such that page B does not have a chance to commit. // This leads to two changes to the back/forward list but only one change to @@ -144,7 +144,7 @@ TEST_F(RenderViewImplTest, LastCommittedUpdateState) { // Now ensure that the UpdateState message we receive is consistent // and represents page C in both page_id and state. - const IPC::Message* msg = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg); int page_id; @@ -173,14 +173,14 @@ TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { EXPECT_EQ(2, view()->history_page_ids_[1]); // Check for a valid UpdateState message for page A. - const IPC::Message* msg_A = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_A); int page_id_A; std::string state_A; ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); EXPECT_EQ(1, page_id_A); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Back to page A (page_id 1) and commit. ViewMsg_Navigate_Params params_A; @@ -237,14 +237,14 @@ TEST_F(RenderViewImplTest, DontIgnoreBackAfterNavEntryLimit) { EXPECT_EQ(2, view()->history_page_ids_[1]); // Check for a valid UpdateState message for page A. - const IPC::Message* msg_A = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_A); int page_id_A; std::string state_A; ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); EXPECT_EQ(1, page_id_A); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Load page C, which will trigger an UpdateState message for page B. LoadHTML("<div>Page C</div>"); @@ -253,14 +253,14 @@ TEST_F(RenderViewImplTest, DontIgnoreBackAfterNavEntryLimit) { EXPECT_EQ(3, view()->history_page_ids_[2]); // Check for a valid UpdateState message for page B. - const IPC::Message* msg_B = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_B); int page_id_B; std::string state_B; ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); EXPECT_EQ(2, page_id_B); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Suppose the browser has limited the number of NavigationEntries to 2. // It has now dropped the first entry, but the renderer isn't notified. @@ -297,7 +297,7 @@ TEST_F(RenderViewImplTest, OnImeStateChanged) { "<input id=\"test2\" type=\"password\"></input>" "</body>" "</html>"); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); const int kRepeatCount = 10; for (int i = 0; i < kRepeatCount; i++) { @@ -305,12 +305,12 @@ TEST_F(RenderViewImplTest, OnImeStateChanged) { // activate IMEs. ExecuteJavaScript("document.getElementById('test1').focus();"); ProcessPendingMessages(); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Update the IME status and verify if our IME backend sends an IPC message // to activate IMEs. view()->UpdateInputMethod(); - const IPC::Message* msg = render_thread_.sink().GetMessageAt(0); + const IPC::Message* msg = render_thread_->sink().GetMessageAt(0); EXPECT_TRUE(msg != NULL); EXPECT_EQ(ViewHostMsg_ImeUpdateTextInputState::ID, msg->type()); ViewHostMsg_ImeUpdateTextInputState::Param params; @@ -323,12 +323,12 @@ TEST_F(RenderViewImplTest, OnImeStateChanged) { // de-activate IMEs. ExecuteJavaScript("document.getElementById('test2').focus();"); ProcessPendingMessages(); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // Update the IME status and verify if our IME backend sends an IPC message // to de-activate IMEs. view()->UpdateInputMethod(); - msg = render_thread_.sink().GetMessageAt(0); + msg = render_thread_->sink().GetMessageAt(0); EXPECT_TRUE(msg != NULL); EXPECT_EQ(ViewHostMsg_ImeUpdateTextInputState::ID, msg->type()); ViewHostMsg_ImeUpdateTextInputState::Read(msg, ¶ms); @@ -461,7 +461,7 @@ TEST_F(RenderViewImplTest, ImeComposition) { // TODO(hbono): we should verify messages to be sent from the back-end. view()->UpdateInputMethod(); ProcessPendingMessages(); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); if (ime_message->result) { // Retrieve the content of this page and compare it with the expected @@ -490,7 +490,7 @@ TEST_F(RenderViewImplTest, OnSetTextDirection) { "<div id=\"result\" contenteditable=\"true\"></div>" "</body>" "</html>"); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); static const struct { WebTextDirection direction; @@ -565,7 +565,7 @@ TEST_F(RenderViewImplTest, OnHandleKeyboardEvent) { "</body>" "</html>"); ExecuteJavaScript("document.getElementById('test').focus();"); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); static const MockKeyboard::Layout kLayouts[] = { #if defined(OS_WIN) @@ -826,7 +826,7 @@ TEST_F(RenderViewImplTest, InsertCharacters) { "</body>" "</html>"); ExecuteJavaScript("document.getElementById('test').focus();"); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); // For each key code, we send three keyboard events. // * Pressing only the key; diff --git a/content/renderer/render_view_browsertest_mac.mm b/content/renderer/render_view_browsertest_mac.mm index 8784c2c..218680c 100644 --- a/content/renderer/render_view_browsertest_mac.mm +++ b/content/renderer/render_view_browsertest_mac.mm @@ -4,14 +4,16 @@ #include "base/string_util.h" #include "base/string16.h" -#include "chrome/test/base/render_view_test.h" #include "content/common/native_web_keyboard_event.h" #include "content/renderer/render_view_impl.h" +#include "content/test/render_view_test.h" #include "testing/gtest/include/gtest/gtest.h" #include <Cocoa/Cocoa.h> #include <Carbon/Carbon.h> // for the kVK_* constants. +using content::RenderViewTest; + NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { UniChar uniChar = 0; switch(code) { @@ -98,7 +100,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) { sprintf(htmlBuffer, kRawHtml, "true"); view->set_send_content_state_immediately(true); LoadHTML(htmlBuffer); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); const char* kArrowDownScrollDown = "40,false,false,true,false\n1936\np1\n\np2"; @@ -123,7 +125,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) { sprintf(htmlBuffer, kRawHtml, "false"); view->set_send_content_state_immediately(true); LoadHTML(htmlBuffer); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); const char* kArrowDownNoScroll = "40,false,false,true,false\np1\n\np2"; diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 2869dce..5ab8f8c 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -84,6 +84,7 @@ class WaitableEvent; } // namespace base namespace content { +class RenderViewTest; class NavigationState; class P2PSocketDispatcher; class RenderViewObserver; @@ -649,7 +650,7 @@ class RenderViewImpl : public RenderWidget, // For unit tests. friend class ExternalPopupMenuTest; friend class PepperDeviceTest; - friend class RenderViewTest; + friend class content::RenderViewTest; FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange); FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, NormalCase); diff --git a/chrome/renderer/mock_keyboard.cc b/content/test/mock_keyboard.cc index b18f3f6..0862a31 100644 --- a/chrome/renderer/mock_keyboard.cc +++ b/content/test/mock_keyboard.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2009 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/renderer/mock_keyboard.h" +#include "content/test/mock_keyboard.h" #include "base/logging.h" diff --git a/chrome/renderer/mock_keyboard.h b/content/test/mock_keyboard.h index 842ec63..6f49297 100644 --- a/chrome/renderer/mock_keyboard.h +++ b/content/test/mock_keyboard.h @@ -1,9 +1,9 @@ -// Copyright (c) 2009 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. -#ifndef CHROME_RENDERER_MOCK_KEYBOARD_H_ -#define CHROME_RENDERER_MOCK_KEYBOARD_H_ +#ifndef CONTENT_TEST_MOCK_KEYBOARD_H_ +#define CONTENT_TEST_MOCK_KEYBOARD_H_ #pragma once #include <string> @@ -11,7 +11,7 @@ #include "base/basictypes.h" #if defined(OS_WIN) -#include "chrome/renderer/mock_keyboard_driver_win.h" +#include "content/test/mock_keyboard_driver_win.h" #endif // A mock keyboard interface. @@ -104,4 +104,4 @@ class MockKeyboard { DISALLOW_COPY_AND_ASSIGN(MockKeyboard); }; -#endif // CHROME_RENDERER_MOCK_KEYBOARD_H_ +#endif // CONTENT_TEST_MOCK_KEYBOARD_H_ diff --git a/chrome/renderer/mock_keyboard_driver_win.cc b/content/test/mock_keyboard_driver_win.cc index ea88007..9d57fb3 100644 --- a/chrome/renderer/mock_keyboard_driver_win.cc +++ b/content/test/mock_keyboard_driver_win.cc @@ -1,12 +1,12 @@ -// 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/renderer/mock_keyboard_driver_win.h" +#include "content/test/mock_keyboard_driver_win.h" #include "base/basictypes.h" #include "base/logging.h" -#include "chrome/renderer/mock_keyboard.h" +#include "content/test/mock_keyboard.h" MockKeyboardDriverWin::MockKeyboardDriverWin() { // Save the keyboard layout and status of the application. diff --git a/chrome/renderer/mock_keyboard_driver_win.h b/content/test/mock_keyboard_driver_win.h index bbe65f1..44c2b2d 100644 --- a/chrome/renderer/mock_keyboard_driver_win.h +++ b/content/test/mock_keyboard_driver_win.h @@ -1,9 +1,9 @@ -// Copyright (c) 2009 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. -#ifndef CHROME_RENDERER_MOCK_KEYBOARD_DRIVER_WIN_H_ -#define CHROME_RENDERER_MOCK_KEYBOARD_DRIVER_WIN_H_ +#ifndef CONTENT_TEST_MOCK_KEYBOARD_DRIVER_WIN_H_ +#define CONTENT_TEST_MOCK_KEYBOARD_DRIVER_WIN_H_ #pragma once #include <windows.h> @@ -39,4 +39,4 @@ class MockKeyboardDriverWin { DISALLOW_COPY_AND_ASSIGN(MockKeyboardDriverWin); }; -#endif // CHROME_RENDERER_MOCK_KEYBOARD_DRIVER_WIN_H_ +#endif // CONTENT_TEST_MOCK_KEYBOARD_DRIVER_WIN_H_ diff --git a/content/test/mock_render_thread.cc b/content/test/mock_render_thread.cc new file mode 100644 index 0000000..36c9f83 --- /dev/null +++ b/content/test/mock_render_thread.cc @@ -0,0 +1,184 @@ +// 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 "content/test/mock_render_thread.h" + +#include "base/process_util.h" +#include "content/common/view_messages.h" +#include "ipc/ipc_message_utils.h" +#include "ipc/ipc_sync_message.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace content { + +MockRenderThread::MockRenderThread() + : routing_id_(0), opener_id_(0) { +} + +MockRenderThread::~MockRenderThread() { +} + +// 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); +} + +// 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_; +} + +bool MockRenderThread::OnMessageReceived(const IPC::Message& msg) { + // Save the message in the sink. + sink_.OnMessageReceived(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_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP_EX() + return handled; +} + +#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) + +} // namespace content diff --git a/chrome/renderer/mock_render_thread.h b/content/test/mock_render_thread.h index cf18ed9..0cc8db4 100644 --- a/chrome/renderer/mock_render_thread.h +++ b/content/test/mock_render_thread.h @@ -2,16 +2,11 @@ // 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_ +#ifndef CONTENT_TEST_MOCK_RENDER_THREAD_H_ +#define CONTENT_TEST_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" @@ -20,17 +15,9 @@ 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; +namespace content { -// This class is very simple mock of RenderThread. It simulates an IPC channel +// This class is a 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. @@ -98,67 +85,21 @@ class MockRenderThread : public content::RenderThread { // 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); + protected: + // This function operates as a regular IPC listener. Subclasses + // overriding this should first delegate to this implementation. + virtual 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. @@ -173,19 +114,8 @@ class MockRenderThread : public content::RenderThread { // 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_ +} // namespace content + +#endif // CONTENT_TEST_MOCK_RENDER_THREAD_H_ diff --git a/chrome/test/base/render_view_test.cc b/content/test/render_view_test.cc index 0734dc0..b575550 100644 --- a/chrome/test/base/render_view_test.cc +++ b/content/test/render_view_test.cc @@ -2,19 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/base/render_view_test.h" - -#include "chrome/browser/extensions/extension_function_dispatcher.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/print_messages.h" -#include "chrome/common/render_messages.h" -#include "chrome/renderer/autofill/password_autofill_manager.h" -#include "chrome/renderer/extensions/chrome_v8_context_set.h" -#include "chrome/renderer/extensions/chrome_v8_extension.h" -#include "chrome/renderer/extensions/event_bindings.h" -#include "chrome/renderer/extensions/extension_dispatcher.h" -#include "chrome/renderer/extensions/extension_process_bindings.h" -#include "chrome/renderer/extensions/renderer_extension_bindings.h" +#include "content/test/render_view_test.h" + #include "content/common/dom_storage_common.h" #include "content/common/native_web_keyboard_event.h" #include "content/common/renderer_preferences.h" @@ -22,7 +11,6 @@ #include "content/renderer/render_view_impl.h" #include "content/renderer/renderer_main_platform_delegate.h" #include "content/test/mock_render_process.h" -#include "grit/renderer_resources.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" @@ -43,15 +31,15 @@ using WebKit::WebScriptController; using WebKit::WebScriptSource; using WebKit::WebString; using WebKit::WebURLRequest; -using autofill::AutofillAgent; -using autofill::PasswordAutofillManager; namespace { -const int32 kRouteId = 5; const int32 kOpenerId = 7; +const int32 kRouteId = 5; } // namespace -RenderViewTest::RenderViewTest() : extension_dispatcher_(NULL), view_(NULL) { +namespace content { + +RenderViewTest::RenderViewTest() : view_(NULL) { } RenderViewTest::~RenderViewTest() { @@ -97,9 +85,17 @@ void RenderViewTest::LoadHTML(const char* html) { } void RenderViewTest::SetUp() { - content::GetContentClient()->set_renderer(&chrome_content_renderer_client_); - extension_dispatcher_ = new ExtensionDispatcher(); - chrome_content_renderer_client_.SetExtensionDispatcher(extension_dispatcher_); + // Subclasses can set the ContentClient's renderer before calling + // RenderViewTest::SetUp(). + if (!GetContentClient()->renderer()) + GetContentClient()->set_renderer(&mock_content_renderer_client_); + + // Subclasses can set render_thread_ with their own implementation before + // calling RenderViewTest::SetUp(). + if (!render_thread_.get()) + render_thread_.reset(new MockRenderThread()); + render_thread_->set_routing_id(kRouteId); + sandbox_init_wrapper_.reset(new SandboxInitWrapper()); command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); params_.reset(new MainFunctionParams(*command_line_, *sandbox_init_wrapper_, @@ -112,21 +108,8 @@ void RenderViewTest::SetUp() { webkit_glue::SetJavaScriptFlags(" --expose-gc"); WebKit::initialize(&webkit_platform_support_); - WebScriptController::registerExtension(new ChromeV8Extension( - "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL)); - WebScriptController::registerExtension(EventBindings::Get( - extension_dispatcher_)); - WebScriptController::registerExtension(RendererExtensionBindings::Get( - extension_dispatcher_)); - WebScriptController::registerExtension(ExtensionProcessBindings::Get( - extension_dispatcher_)); - WebScriptController::registerExtension(new ChromeV8Extension( - "extensions/apitest.js", IDR_EXTENSION_APITEST_JS, NULL)); - mock_process_.reset(new MockRenderProcess); - render_thread_.set_routing_id(kRouteId); - // This needs to pass the mock render thread to the view. RenderViewImpl* view = RenderViewImpl::Create( 0, @@ -142,12 +125,6 @@ void RenderViewTest::SetUp() { // Attach a pseudo keyboard device to this object. mock_keyboard_.reset(new MockKeyboard()); - - // RenderView doesn't expose it's PasswordAutofillManager or - // AutofillAgent objects, because it has no need to store them directly - // (they're stored as RenderViewObserver*). So just create another set. - password_autofill_ = new PasswordAutofillManager(view_); - autofill_agent_ = new AutofillAgent(view_, password_autofill_); } void RenderViewTest::TearDown() { @@ -155,8 +132,6 @@ void RenderViewTest::TearDown() { GetMainFrame()->collectGarbage(); GetMainFrame()->collectGarbage(); - render_thread_.SendCloseMessage(); - // Run the loop so the release task from the renderwidget executes. ProcessPendingMessages(); @@ -180,9 +155,6 @@ void RenderViewTest::TearDown() { params_.reset(); command_line_.reset(); sandbox_init_wrapper_.reset(); - - extension_dispatcher_->OnRenderProcessShutdown(); - extension_dispatcher_ = NULL; } int RenderViewTest::SendKeyEvent(MockKeyboard::Layout layout, @@ -362,3 +334,5 @@ WebKit::WebWidget* RenderViewTest::GetWebWidget() { RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_); return impl->webwidget(); } + +} // namespace content diff --git a/chrome/test/base/render_view_test.h b/content/test/render_view_test.h index c757280..6cf1a14 100644 --- a/chrome/test/base/render_view_test.h +++ b/content/test/render_view_test.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_TEST_BASE_RENDER_VIEW_TEST_H_ -#define CHROME_TEST_BASE_RENDER_VIEW_TEST_H_ +#ifndef CONTENT_TEST_RENDER_VIEW_TEST_H_ +#define CONTENT_TEST_RENDER_VIEW_TEST_H_ #pragma once #include <string> @@ -11,18 +11,16 @@ #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "chrome/renderer/autofill/autofill_agent.h" -#include "chrome/renderer/mock_keyboard.h" -#include "chrome/renderer/mock_render_thread.h" #include "content/common/main_function_params.h" #include "content/common/native_web_keyboard_event.h" #include "content/common/sandbox_init_wrapper.h" +#include "content/renderer/mock_content_renderer_client.h" #include "content/renderer/renderer_webkitplatformsupport_impl.h" -#include "chrome/renderer/chrome_content_renderer_client.h" +#include "content/test/mock_keyboard.h" +#include "content/test/mock_render_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" -class ExtensionDispatcher; class MockRenderProcess; class RendererMainPlatformDelegate; struct ViewMsg_Navigate_Params; @@ -31,11 +29,6 @@ namespace WebKit { class WebWidget; } -namespace autofill { -class AutofillAgent; -class PasswordAutofillManager; -} - namespace content { class RenderView; } @@ -44,6 +37,8 @@ namespace gfx { class Rect; } +namespace content { + class RenderViewTest : public testing::Test { public: // A special WebKitPlatformSupportImpl class for getting rid off the @@ -113,24 +108,22 @@ class RenderViewTest : public testing::Test { virtual void TearDown(); MessageLoop msg_loop_; - chrome::ChromeContentRendererClient chrome_content_renderer_client_; - ExtensionDispatcher* extension_dispatcher_; - MockRenderThread render_thread_; scoped_ptr<MockRenderProcess> mock_process_; // We use a naked pointer because we don't want to expose RenderViewImpl in // the embedder's namespace. content::RenderView* view_; RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_; + MockContentRendererClient mock_content_renderer_client_; scoped_ptr<MockKeyboard> mock_keyboard_; + scoped_ptr<MockRenderThread> render_thread_; // Used to setup the process so renderers can run. scoped_ptr<RendererMainPlatformDelegate> platform_; scoped_ptr<MainFunctionParams> params_; scoped_ptr<CommandLine> command_line_; scoped_ptr<SandboxInitWrapper> sandbox_init_wrapper_; - - autofill::PasswordAutofillManager* password_autofill_; - autofill::AutofillAgent* autofill_agent_; }; -#endif // CHROME_TEST_BASE_RENDER_VIEW_TEST_H_ +} // namespace content + +#endif // CONTENT_TEST_RENDER_VIEW_TEST_H_ diff --git a/content/test/render_widget_browsertest.cc b/content/test/render_widget_browsertest.cc index 0ac6637..a81cb9a 100644 --- a/content/test/render_widget_browsertest.cc +++ b/content/test/render_widget_browsertest.cc @@ -51,12 +51,12 @@ void RenderWidgetTest::ResizeAndPaint(const gfx::Size& page_size, impl->OnMsgPaintAtSize(pixels->handle(), g_sequence_num, page_size, desired_size); ProcessPendingMessages(); - const IPC::Message* msg = render_thread_.sink().GetUniqueMessageMatching( + const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( ViewHostMsg_PaintAtSize_ACK::ID); ASSERT_NE(static_cast<IPC::Message*>(NULL), msg); ViewHostMsg_PaintAtSize_ACK::Param params; ViewHostMsg_PaintAtSize_ACK::Read(msg, ¶ms); - render_thread_.sink().ClearMessages(); + render_thread_->sink().ClearMessages(); EXPECT_EQ(g_sequence_num, params.a); gfx::Size size = params.b; EXPECT_EQ(desired_size, size); diff --git a/content/test/render_widget_browsertest.h b/content/test/render_widget_browsertest.h index c3e0def..f0d1c53 100644 --- a/content/test/render_widget_browsertest.h +++ b/content/test/render_widget_browsertest.h @@ -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. @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "base/file_path.h" -#include "chrome/test/base/render_view_test.h" +#include "content/test/render_view_test.h" namespace gfx { class Size; @@ -17,7 +17,7 @@ class Size; class SkBitmap; class TransportDIB; -class RenderWidgetTest : public RenderViewTest { +class RenderWidgetTest : public content::RenderViewTest { public: RenderWidgetTest(); |