From 1ee61486ee0854be7b82d9fca66bb49d563ede4c Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Mon, 6 Jul 2009 20:29:18 +0000 Subject: Do some refactoring of renderer_host. This removes the last dependency on tab_contents from the renderer_host code and into the RenderViewHostDelegate. Some of the tests depended on tab_contents, so I moved to a new directory with the tab_contents include allowed via DEPS. Now DEPS can enforce that no additional tab_contents includes are added to renderer_host. RenderViewHost delegate is now pure virtual. After spending a while *again* figuring out why my code didn't work, only to find it was because the default implementation of a function was getting called instead of the real one, I decided to make this pure virtual. It is implemented by TabContents, which implements basically everything, and two other places that implement less. Only two lists of duplicate functions seems not too bad, although long-term it would be nice if this delegate was somehow more succinct. Review URL: http://codereview.chromium.org/155071 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19982 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/back_forward_menu_model_unittest.cc | 2 +- chrome/browser/blocked_popup_container_unittest.cc | 2 +- .../blocked_popup_container_controller_unittest.mm | 2 +- .../browser/debugger/devtools_manager_unittest.cc | 2 +- chrome/browser/dom_ui/dom_ui_unittest.cc | 2 +- .../download/download_request_manager_unittest.cc | 2 +- chrome/browser/download/save_package.h | 1 + chrome/browser/extensions/extension_host.cc | 53 ++- chrome/browser/extensions/extension_host.h | 21 +- chrome/browser/find_backend_unittest.cc | 2 +- chrome/browser/renderer_host/DEPS | 12 + .../renderer_host/cross_site_resource_handler.cc | 33 +- .../renderer_host/render_view_host_delegate.cc | 50 +++ .../renderer_host/render_view_host_delegate.h | 185 ++++----- .../render_view_host_manager_browsertest.cc | 112 ----- .../renderer_host/render_view_host_unittest.cc | 17 - .../renderer_host/render_widget_host_unittest.cc | 2 +- .../renderer_host/resource_dispatcher_host.cc | 8 +- .../renderer_host/resource_dispatcher_host.h | 13 +- .../renderer_host/site_instance_unittest.cc | 458 --------------------- chrome/browser/renderer_host/test/DEPS | 4 + chrome/browser/renderer_host/test/README.txt | 4 + .../test/render_view_host_manager_browsertest.cc | 112 +++++ .../test/render_view_host_unittest.cc | 17 + .../renderer_host/test/site_instance_unittest.cc | 458 +++++++++++++++++++++ .../renderer_host/test/test_render_view_host.cc | 101 +++++ .../renderer_host/test/test_render_view_host.h | 257 ++++++++++++ .../test/web_cache_manager_browsertest.cc | 61 +++ .../browser/renderer_host/test_render_view_host.cc | 101 ----- .../browser/renderer_host/test_render_view_host.h | 257 ------------ .../web_cache_manager_browser_test.cc | 61 --- .../safe_browsing_blocking_page_unittest.cc | 2 +- .../sessions/tab_restore_service_unittest.cc | 2 +- chrome/browser/tab_contents/interstitial_page.cc | 136 +++--- chrome/browser/tab_contents/interstitial_page.h | 18 +- .../tab_contents/navigation_controller_unittest.cc | 2 +- .../render_view_host_manager_unittest.cc | 2 +- chrome/browser/tab_contents/tab_contents.cc | 25 +- chrome/browser/tab_contents/tab_contents.h | 18 +- chrome/browser/tab_contents/test_web_contents.cc | 2 +- .../tab_contents/thumbnail_generator_unittest.cc | 2 +- .../browser/tab_contents/web_contents_unittest.cc | 2 +- chrome/browser/tabs/tab_strip_model_unittest.cc | 2 +- chrome/browser/visitedlink_unittest.cc | 2 +- chrome/chrome.gyp | 13 +- chrome/test/browser_with_test_window_test.h | 2 +- 46 files changed, 1363 insertions(+), 1279 deletions(-) create mode 100644 chrome/browser/renderer_host/DEPS create mode 100644 chrome/browser/renderer_host/render_view_host_delegate.cc delete mode 100755 chrome/browser/renderer_host/render_view_host_manager_browsertest.cc delete mode 100644 chrome/browser/renderer_host/render_view_host_unittest.cc delete mode 100644 chrome/browser/renderer_host/site_instance_unittest.cc create mode 100644 chrome/browser/renderer_host/test/DEPS create mode 100644 chrome/browser/renderer_host/test/README.txt create mode 100755 chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc create mode 100644 chrome/browser/renderer_host/test/render_view_host_unittest.cc create mode 100644 chrome/browser/renderer_host/test/site_instance_unittest.cc create mode 100644 chrome/browser/renderer_host/test/test_render_view_host.cc create mode 100644 chrome/browser/renderer_host/test/test_render_view_host.h create mode 100644 chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc delete mode 100644 chrome/browser/renderer_host/test_render_view_host.cc delete mode 100644 chrome/browser/renderer_host/test_render_view_host.h delete mode 100644 chrome/browser/renderer_host/web_cache_manager_browser_test.cc diff --git a/chrome/browser/back_forward_menu_model_unittest.cc b/chrome/browser/back_forward_menu_model_unittest.cc index 6f442e5..1cc6823 100644 --- a/chrome/browser/back_forward_menu_model_unittest.cc +++ b/chrome/browser/back_forward_menu_model_unittest.cc @@ -9,7 +9,7 @@ #include "base/path_service.h" #include "base/string_util.h" #include "chrome/browser/profile_manager.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" diff --git a/chrome/browser/blocked_popup_container_unittest.cc b/chrome/browser/blocked_popup_container_unittest.cc index 6d872f3..b23cab7 100644 --- a/chrome/browser/blocked_popup_container_unittest.cc +++ b/chrome/browser/blocked_popup_container_unittest.cc @@ -14,7 +14,7 @@ #include "base/path_service.h" #include "chrome/browser/blocked_popup_container.h" #include "chrome/browser/tab_contents/test_web_contents.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/test/testing_profile.h" #include "net/base/net_util.h" diff --git a/chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm b/chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm index 256fb4a..393d4a6 100644 --- a/chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm +++ b/chrome/browser/cocoa/blocked_popup_container_controller_unittest.mm @@ -10,7 +10,7 @@ #import "chrome/browser/cocoa/blocked_popup_container_controller.h" #include "chrome/browser/cocoa/browser_test_helper.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "net/base/net_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/debugger/devtools_manager_unittest.cc b/chrome/browser/debugger/devtools_manager_unittest.cc index a8a9e7a..ddcc54f 100644 --- a/chrome/browser/debugger/devtools_manager_unittest.cc +++ b/chrome/browser/debugger/devtools_manager_unittest.cc @@ -6,7 +6,7 @@ #include "chrome/browser/debugger/devtools_client_host.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/debugger/devtools_window.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "testing/gtest/include/gtest/gtest.h" #include "chrome/common/render_messages.h" diff --git a/chrome/browser/dom_ui/dom_ui_unittest.cc b/chrome/browser/dom_ui/dom_ui_unittest.cc index 43a3f71..4b7015d 100644 --- a/chrome/browser/dom_ui/dom_ui_unittest.cc +++ b/chrome/browser/dom_ui/dom_ui_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/dom_ui/new_tab_ui.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/common/url_constants.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/download/download_request_manager_unittest.cc b/chrome/browser/download/download_request_manager_unittest.cc index a8ece7a..a9f6382 100644 --- a/chrome/browser/download/download_request_manager_unittest.cc +++ b/chrome/browser/download/download_request_manager_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/download/download_request_manager.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/download/save_package.h b/chrome/browser/download/save_package.h index ef475db..8d120602 100644 --- a/chrome/browser/download/save_package.h +++ b/chrome/browser/download/save_package.h @@ -15,6 +15,7 @@ #include "base/ref_counted.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/shell_dialogs.h" +#include "googleurl/src/gurl.h" class SaveFileManager; class SaveItem; diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 15319b3..2169a80 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -165,25 +165,6 @@ void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) { Details(this)); } -WebPreferences ExtensionHost::GetWebkitPrefs() { - PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); - const bool kIsDomUI = true; - return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, kIsDomUI); -} - -void ExtensionHost::RunJavaScriptMessage( - const std::wstring& message, - const std::wstring& default_prompt, - const GURL& frame_url, - const int flags, - IPC::Message* reply_msg, - bool* did_suppress_message) { - // Automatically cancel the javascript alert (otherwise the renderer hangs - // indefinitely). - *did_suppress_message = true; - render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L""); -} - void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { // TODO(aa): This is toolstrip-specific and should probably not be here. // ExtensionToolstrip in bookmark_bar_view.cc? @@ -195,6 +176,32 @@ void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { did_stop_loading_ = true; } +void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, + const std::wstring& default_prompt, + const GURL& frame_url, + const int flags, + IPC::Message* reply_msg, + bool* did_suppress_message) { + // Automatically cancel the javascript alert (otherwise the renderer hangs + // indefinitely). + *did_suppress_message = true; + render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L""); +} + +WebPreferences ExtensionHost::GetWebkitPrefs() { + PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); + const bool kIsDomUI = true; + return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, kIsDomUI); +} + +void ExtensionHost::ProcessDOMUIMessage(const std::string& message, + const std::string& content, + int request_id, + bool has_callback) { + extension_function_dispatcher_->HandleRequest(message, content, request_id, + has_callback); +} + void ExtensionHost::DidInsertCSS() { #if defined(TOOLKIT_VIEWS) if (view_.get()) @@ -304,14 +311,6 @@ Browser* ExtensionHost::GetBrowser() { return browser; } -void ExtensionHost::ProcessDOMUIMessage(const std::string& message, - const std::string& content, - int request_id, - bool has_callback) { - extension_function_dispatcher_->HandleRequest(message, content, request_id, - has_callback); -} - void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { extension_function_dispatcher_.reset( new ExtensionFunctionDispatcher(render_view_host_, this, url_)); diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index a3b04f2..b2f32b2 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -65,25 +65,24 @@ class ExtensionHost : public RenderViewHostDelegate, // process crashed. void RecoverCrashedExtension(); - // RenderViewHostDelegate + // RenderViewHostDelegate implementation. + virtual RenderViewHostDelegate::View* GetViewDelegate() const; virtual const GURL& GetURL() const { return url_; } virtual void RenderViewCreated(RenderViewHost* render_view_host); virtual void RenderViewGone(RenderViewHost* render_view_host); - virtual WebPreferences GetWebkitPrefs(); - virtual void RunJavaScriptMessage( - const std::wstring& message, - const std::wstring& default_prompt, - const GURL& frame_url, - const int flags, - IPC::Message* reply_msg, - bool* did_suppress_message); virtual void DidStopLoading(RenderViewHost* render_view_host); - virtual RenderViewHostDelegate::View* GetViewDelegate() const; - virtual void DidInsertCSS(); + virtual WebPreferences GetWebkitPrefs(); virtual void ProcessDOMUIMessage(const std::string& message, const std::string& content, int request_id, bool has_callback); + virtual void RunJavaScriptMessage(const std::wstring& message, + const std::wstring& default_prompt, + const GURL& frame_url, + const int flags, + IPC::Message* reply_msg, + bool* did_suppress_message); + virtual void DidInsertCSS(); // RenderViewHostDelegate::View virtual void CreateNewWindow(int route_id, diff --git a/chrome/browser/find_backend_unittest.cc b/chrome/browser/find_backend_unittest.cc index e986d5a..afe555a 100644 --- a/chrome/browser/find_backend_unittest.cc +++ b/chrome/browser/find_backend_unittest.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/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/common/url_constants.h" typedef RenderViewHostTestHarness FindBackendTest; diff --git a/chrome/browser/renderer_host/DEPS b/chrome/browser/renderer_host/DEPS new file mode 100644 index 0000000..1c0609d5 --- /dev/null +++ b/chrome/browser/renderer_host/DEPS @@ -0,0 +1,12 @@ +include_rules = [ + # DO NOT ALLOW tab_contents INCLUDES FROM THIS DIRECTORY! The renderer_host + # layer should be usable in contexts other than inside TabContents. Instead, + # you should call upward through the RenderViewHostDelegate interface. If + # your test needs some TabContents code, you can put it in renderer_host/test + # which can include more stuff for testing purposes. + # + # If somebody adds an include and you're fixing the build, please revert them + # instead of commenting out this rule. + "-chrome/browser/tab_contents", +] + diff --git a/chrome/browser/renderer_host/cross_site_resource_handler.cc b/chrome/browser/renderer_host/cross_site_resource_handler.cc index 5064a34..2580344 100644 --- a/chrome/browser/renderer_host/cross_site_resource_handler.cc +++ b/chrome/browser/renderer_host/cross_site_resource_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,18 +6,18 @@ #include "chrome/browser/renderer_host/cross_site_resource_handler.h" +#include "base/message_loop.h" #include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/tab_contents/tab_util.h" -#include "chrome/browser/tab_contents/tab_contents.h" namespace { + // Task to notify the TabContents that a cross-site response has begun, so that // TabContents can tell the old page to run its onunload handler. -class CrossSiteNotifyTabTask : public Task { +class CrossSiteNotifyTask : public Task { public: - CrossSiteNotifyTabTask(int render_process_host_id, - int render_view_id, - int request_id) + CrossSiteNotifyTask(int render_process_host_id, + int render_view_id, + int request_id) : render_process_host_id_(render_process_host_id), render_view_id_(render_view_id), request_id_(request_id) {} @@ -48,17 +48,18 @@ class CancelPendingRenderViewTask : public Task { render_view_id_(render_view_id) {} void Run() { - TabContents* tab_contents = - tab_util::GetTabContentsByID(render_process_host_id_, render_view_id_); - if (tab_contents) - tab_contents->CrossSiteNavigationCanceled(); + RenderViewHost* view = + RenderViewHost::FromID(render_process_host_id_, render_view_id_); + if (view) + view->delegate()->OnCrossSiteNavigationCanceled(); } private: int render_process_host_id_; int render_view_id_; }; -} + +} // namespace CrossSiteResourceHandler::CrossSiteResourceHandler( ResourceHandler* handler, @@ -250,9 +251,9 @@ void CrossSiteResourceHandler::StartCrossSiteTransition( // Tell the tab responsible for this request that a cross-site response is // starting, so that it can tell its old renderer to run its onunload // handler now. We will wait to hear the corresponding ClosePage_ACK. - CrossSiteNotifyTabTask* task = - new CrossSiteNotifyTabTask(render_process_host_id_, - render_view_id_, - request_id); + CrossSiteNotifyTask* task = + new CrossSiteNotifyTask(render_process_host_id_, + render_view_id_, + request_id); rdh_->ui_loop()->PostTask(FROM_HERE, task); } diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc new file mode 100644 index 0000000..4e05a60 --- /dev/null +++ b/chrome/browser/renderer_host/render_view_host_delegate.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/renderer_host/render_view_host_delegate.h" + +#include "base/gfx/rect.h" +#include "chrome/common/renderer_preferences.h" +#include "googleurl/src/gurl.h" +#include "webkit/glue/webpreferences.h" + +RenderViewHostDelegate::View* RenderViewHostDelegate::GetViewDelegate() const { + return NULL; +} + +RenderViewHostDelegate::Save* RenderViewHostDelegate::GetSaveDelegate() const { + return NULL; +} + +const GURL& RenderViewHostDelegate::GetURL() const { + return GURL::EmptyGURL(); +} + +TabContents* RenderViewHostDelegate::GetAsTabContents() { + return NULL; +} + +GURL RenderViewHostDelegate::GetAlternateErrorPageURL() const { + return GURL(); +} + +RendererPreferences RenderViewHostDelegate::GetRendererPrefs() const { + return RendererPreferences(); +} + +WebPreferences RenderViewHostDelegate::GetWebkitPrefs() { + return WebPreferences(); +} + +bool RenderViewHostDelegate::CanBlur() const { + return true; +} + +gfx::Rect RenderViewHostDelegate::GetRootWindowResizerRect() const { + return gfx::Rect(); +} + +bool RenderViewHostDelegate::IsExternalTabContainer() const { + return false; +} diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index ec409d9..e3fe34a 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,41 +9,45 @@ #include #include "base/basictypes.h" -#include "base/file_path.h" -#include "base/gfx/rect.h" -#include "base/logging.h" -#include "chrome/common/native_web_keyboard_event.h" -#include "chrome/common/renderer_preferences.h" +#include "base/string16.h" #include "net/base/load_states.h" -#include "webkit/glue/password_form.h" -#include "webkit/glue/webpreferences.h" #include "webkit/glue/window_open_disposition.h" class AutofillForm; +struct ContextMenuParams; +class FilePath; +class GURL; +struct NativeWebKeyboardEvent; class NavigationEntry; class Profile; +struct RendererPreferences; class RenderProcessHost; class RenderViewHost; class ResourceRequestDetails; class SkBitmap; class TabContents; -class WebKeyboardEvent; struct ThumbnailScore; -struct ContextMenuParams; struct ViewHostMsg_DidPrintPage_Params; struct ViewHostMsg_FrameNavigate_Params; struct WebDropData; +class WebKeyboardEvent; +struct WebPreferences; namespace base { class WaitableEvent; } +namespace gfx { +class Rect; +} + namespace IPC { class Message; } namespace webkit_glue { class AutofillForm; +struct PasswordForm; struct WebApplicationInfo; } @@ -153,74 +157,76 @@ class RenderViewHostDelegate { int32 status) = 0; }; - // Returns the current delegate associated with a feature. May be NULL. - virtual View* GetViewDelegate() const { return NULL; } - virtual Save* GetSaveDelegate() const { return NULL; } + // Returns the current delegate associated with a feature. May return NULL if + // there is no corresponding delegate. + virtual View* GetViewDelegate() const; + virtual Save* GetSaveDelegate() const; // Gets the URL that is currently being displayed, if there is one. - virtual const GURL& GetURL() const = 0; + virtual const GURL& GetURL() const; - // Return this object cast to a TabContents, if it is one. - virtual TabContents* GetAsTabContents() { return NULL; } + // Return this object cast to a TabContents, if it is one. If the object is + // not a TabContents, returns NULL. + virtual TabContents* GetAsTabContents(); // The RenderView is being constructed (message sent to the renderer process // to construct a RenderView). Now is a good time to send other setup events // to the RenderView. This precedes any other commands to the RenderView. - virtual void RenderViewCreated(RenderViewHost* render_view_host) { } + virtual void RenderViewCreated(RenderViewHost* render_view_host) {} // The RenderView has been constructed. - virtual void RenderViewReady(RenderViewHost* render_view_host) { } + virtual void RenderViewReady(RenderViewHost* render_view_host) {} // The RenderView died somehow (crashed or was killed by the user). - virtual void RenderViewGone(RenderViewHost* render_view_host) { } + virtual void RenderViewGone(RenderViewHost* render_view_host) {} // The RenderView was navigated to a different page. virtual void DidNavigate(RenderViewHost* render_view_host, - const ViewHostMsg_FrameNavigate_Params& params) { } + const ViewHostMsg_FrameNavigate_Params& params) {} // The state for the page changed and should be updated. virtual void UpdateState(RenderViewHost* render_view_host, int32 page_id, - const std::string& state) { } + const std::string& state) {} // The page's title was changed and should be updated. virtual void UpdateTitle(RenderViewHost* render_view_host, int32 page_id, - const std::wstring& title) { } + const std::wstring& title) {} // The page's encoding was changed and should be updated. virtual void UpdateEncoding(RenderViewHost* render_view_host, - const std::wstring& encoding) { } + const std::wstring& encoding) {} // The destination URL has changed should be updated - virtual void UpdateTargetURL(int32 page_id, const GURL& url) { } + virtual void UpdateTargetURL(int32 page_id, const GURL& url) {} // The thumbnail representation of the page changed and should be updated. virtual void UpdateThumbnail(const GURL& url, const SkBitmap& bitmap, - const ThumbnailScore& score) { } + const ThumbnailScore& score) {} // Inspector settings were changes and should be persisted. - virtual void UpdateInspectorSettings(const std::wstring& raw_settings) { } + virtual void UpdateInspectorSettings(const std::wstring& raw_settings) {} // The page is trying to close the RenderView's representation in the client. - virtual void Close(RenderViewHost* render_view_host) { } + virtual void Close(RenderViewHost* render_view_host) {} // The page is trying to move the RenderView's representation in the client. - virtual void RequestMove(const gfx::Rect& new_bounds) { } + virtual void RequestMove(const gfx::Rect& new_bounds) {} // The RenderView began loading a new page. This corresponds to WebKit's // notion of the throbber starting. - virtual void DidStartLoading(RenderViewHost* render_view_host) { } + virtual void DidStartLoading(RenderViewHost* render_view_host) {} // The RenderView stopped loading a page. This corresponds to WebKit's // notion of the throbber stopping. - virtual void DidStopLoading(RenderViewHost* render_view_host) { } + virtual void DidStopLoading(RenderViewHost* render_view_host) {} // The RenderView is starting a provisional load. virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host, bool is_main_frame, - const GURL& url) { } + const GURL& url) {} // Notification by the resource loading system (not the renderer) that it has // started receiving a resource response. This is different than @@ -235,7 +241,7 @@ class RenderViewHostDelegate { // Sent when a provisional load is redirected. virtual void DidRedirectProvisionalLoad(int32 page_id, const GURL& source_url, - const GURL& target_url) { } + const GURL& target_url) {} // Notification by the resource loading system (not the renderer) that a // resource was redirected. This is different than DidRedirectProvisionalLoad @@ -253,7 +259,7 @@ class RenderViewHostDelegate { const GURL& url, const std::string& frame_origin, const std::string& main_frame_origin, - const std::string& security_info) { } + const std::string& security_info) {} // The RenderView failed a provisional load with an error. virtual void DidFailProvisionalLoadWithError( @@ -261,11 +267,11 @@ class RenderViewHostDelegate { bool is_main_frame, int error_code, const GURL& url, - bool showing_repost_interstitial) { } + bool showing_repost_interstitial) {} // The URL for the FavIcon of a page has changed. virtual void UpdateFavIconURL(RenderViewHost* render_view_host, - int32 page_id, const GURL& icon_url) { } + int32 page_id, const GURL& icon_url) {} // An image that was requested to be downloaded by DownloadImage has // completed. @@ -273,51 +279,49 @@ class RenderViewHostDelegate { int id, const GURL& image_url, bool errored, - const SkBitmap& image) { } + const SkBitmap& image) {} // The page wants to open a URL with the specified disposition. virtual void RequestOpenURL(const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition) { } + WindowOpenDisposition disposition) {} // A DOM automation operation completed. The result of the operation is // expressed in a json string. virtual void DomOperationResponse(const std::string& json_string, - int automation_id) { } + int automation_id) {} // A message was sent from HTML-based UI. // By default we ignore such messages. virtual void ProcessDOMUIMessage(const std::string& message, const std::string& content, int request_id, - bool has_callback) { } + bool has_callback) {} // A message for external host. By default we ignore such messages. // |receiver| can be a receiving script and |message| is any // arbitrary string that makes sense to the receiver. virtual void ProcessExternalHostMessage(const std::string& message, const std::string& origin, - const std::string& target) { - } + const std::string& target) {} - // A document has been loaded in a frame. - virtual void DocumentLoadedInFrame() { - } + // Notification that a document has been loaded in a frame. + virtual void DocumentLoadedInFrame() {} // Navigate to the history entry for the given offset from the current // position within the NavigationController. Makes no change if offset is // not valid. - virtual void GoToEntryAtOffset(int offset) { } + virtual void GoToEntryAtOffset(int offset) {} // The page requests the size of the back and forward lists // within the NavigationController. virtual void GetHistoryListCount(int* back_list_count, - int* forward_list_count) { } + int* forward_list_count) {} // A file chooser should be shown. virtual void RunFileChooser(bool multiple_files, const string16& title, - const FilePath& default_file) { } + const FilePath& default_file) {} // A javascript message, confirmation or prompt should be shown. virtual void RunJavaScriptMessage(const std::wstring& message, @@ -325,24 +329,21 @@ class RenderViewHostDelegate { const GURL& frame_url, const int flags, IPC::Message* reply_msg, - bool* did_suppress_message) { } + bool* did_suppress_message) {} virtual void RunBeforeUnloadConfirm(const std::wstring& message, - IPC::Message* reply_msg) { } - - // Display this RenderViewHost in a modal fashion. - virtual void RunModal(IPC::Message* reply_msg) { } + IPC::Message* reply_msg) {} virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, - IPC::Message* reply_msg) { } + IPC::Message* reply_msg) {} // Password forms have been detected in the page. virtual void PasswordFormsSeen( - const std::vector& forms) { } + const std::vector& forms) {} // Forms fillable by autofill have been detected in the page. - virtual void AutofillFormSubmitted(const webkit_glue::AutofillForm& form) { } + virtual void AutofillFormSubmitted(const webkit_glue::AutofillForm& form) {} // Called to retrieve a list of suggestions from the web database given // the name of the field |field_name| and what the user has already typed in @@ -353,118 +354,112 @@ class RenderViewHostDelegate { virtual void GetAutofillSuggestions(const std::wstring& field_name, const std::wstring& user_text, int64 node_id, - int request_id) { } + int request_id) {} // Called when the user has indicated that she wants to remove the specified // autofill suggestion from the database. virtual void RemoveAutofillEntry(const std::wstring& field_name, - const std::wstring& value) { } + const std::wstring& value) {} // Notification that the page has an OpenSearch description document. virtual void PageHasOSDD(RenderViewHost* render_view_host, int32 page_id, const GURL& doc_url, - bool autodetected) { } + bool autodetected) {} // Notification that the render view has calculated the number of printed // pages. - virtual void DidGetPrintedPagesCount(int cookie, int number_pages) { - NOTREACHED(); - } + virtual void DidGetPrintedPagesCount(int cookie, int number_pages) {} // Notification that the render view is done rendering one printed page. This // call is synchronous, the renderer is waiting on us because of the EMF // memory mapped data. - virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params) { - NOTREACHED(); - } + virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params) {} // |url| is assigned to a server that can provide alternate error pages. If - // unchanged, just use the error pages built into our webkit. - virtual GURL GetAlternateErrorPageURL() const { - return GURL(); - } + // the returned URL is empty, the default error page built into WebKit will + // be used. + virtual GURL GetAlternateErrorPageURL() const; // Return a dummy RendererPreferences object that will be used by the renderer // associated with the owning RenderViewHost. - virtual RendererPreferences GetRendererPrefs() const { - return RendererPreferences(); - } + virtual RendererPreferences GetRendererPrefs() const; // Returns a WebPreferences object that will be used by the renderer // associated with the owning render view host. - virtual WebPreferences GetWebkitPrefs() { - NOTREACHED(); - return WebPreferences(); - } + virtual WebPreferences GetWebkitPrefs(); // Notification when default plugin updates status of the missing plugin. - virtual void OnMissingPluginStatus(int status) { } + virtual void OnMissingPluginStatus(int status) {} // Notification from the renderer that a plugin instance has crashed. - virtual void OnCrashedPlugin(const FilePath& plugin_path) { } + virtual void OnCrashedPlugin(const FilePath& plugin_path) {} // Notification that a worker process has crashed. - virtual void OnCrashedWorker() { } + virtual void OnCrashedWorker() {} // Notification from the renderer that JS runs out of memory. - virtual void OnJSOutOfMemory() { } + virtual void OnJSOutOfMemory() {} // Notification whether we should close the page, after an explicit call to // AttemptToClosePage. This is called before a cross-site request or before // a tab/window is closed, to allow the appropriate renderer to approve or // deny the request. |proceed| indicates whether the user chose to proceed. - virtual void ShouldClosePage(bool proceed) { } + virtual void ShouldClosePage(bool proceed) {} // Called by ResourceDispatcherHost when a response for a pending cross-site // request is received. The ResourceDispatcherHost will pause the response // until the onunload handler of the previous renderer is run. virtual void OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id) { } + int new_request_id) {} + + // Called the ResourceDispatcherHost's associate CrossSiteRequestHandler + // when a cross-site navigation has been canceled. + virtual void OnCrossSiteNavigationCanceled() {} - // Whether this object can be blurred through a javascript - // obj.blur() call. ConstrainedWindows shouldn't be able to be - // blurred. - virtual bool CanBlur() const { return true; } + // Returns true if this this object can be blurred through a javascript + // obj.blur() call. ConstrainedWindows shouldn't be able to be blurred, but + // generally most other windows will be. + virtual bool CanBlur() const; // Return the rect where to display the resize corner, if any, otherwise // an empty rect. - virtual gfx::Rect GetRootWindowResizerRect() const { return gfx::Rect(); } + virtual gfx::Rect GetRootWindowResizerRect() const; // Notification that the renderer has become unresponsive. The // delegate can use this notification to show a warning to the user. virtual void RendererUnresponsive(RenderViewHost* render_view_host, - bool is_during_unload) { } + bool is_during_unload) {} // Notification that a previously unresponsive renderer has become // responsive again. The delegate can use this notification to end the // warning shown to the user. - virtual void RendererResponsive(RenderViewHost* render_view_host) { } + virtual void RendererResponsive(RenderViewHost* render_view_host) {} // Notification that the RenderViewHost's load state changed. - virtual void LoadStateChanged(const GURL& url, net::LoadState load_state) { } + virtual void LoadStateChanged(const GURL& url, net::LoadState load_state) {} // Notification that a request for install info has completed. virtual void OnDidGetApplicationInfo( int32 page_id, - const webkit_glue::WebApplicationInfo& app_info) { } + const webkit_glue::WebApplicationInfo& app_info) {} // Notification the user has made a gesture while focus was on the // page. This is used to avoid uninitiated user downloads (aka carpet // bombing), see DownloadRequestManager for details. - virtual void OnUserGesture() { } + virtual void OnUserGesture() {} - // If this view is used to host an external tab container. - virtual bool IsExternalTabContainer() const { return false; } + // Returns true if this view is used to host an external tab container. + virtual bool IsExternalTabContainer() const; // A find operation in the current page completed. virtual void OnFindReply(int request_id, int number_of_matches, const gfx::Rect& selection_rect, int active_match_ordinal, - bool final_update) { } + bool final_update) {} // The RenderView has inserted one css file into page. - virtual void DidInsertCSS() { } + virtual void DidInsertCSS() {} }; #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_DELEGATE_H_ diff --git a/chrome/browser/renderer_host/render_view_host_manager_browsertest.cc b/chrome/browser/renderer_host/render_view_host_manager_browsertest.cc deleted file mode 100755 index 7d2ff82..0000000 --- a/chrome/browser/renderer_host/render_view_host_manager_browsertest.cc +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/browser.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/download/download_manager.h" -#include "chrome/browser/profile.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/notification_details.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/notification_service.h" -#include "chrome/common/notification_type.h" -#include "chrome/common/extensions/extension_error_reporter.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" -#include "net/base/net_util.h" - -class RenderViewHostManagerTest : public InProcessBrowserTest { - public: - RenderViewHostManagerTest() { - EnableDOMAutomation(); - } - virtual void SetUpCommandLine(CommandLine* command_line) { - command_line->AppendSwitch(switches::kEnableExtensions); - } -}; - -// Test for crbug.com/14505. This tests that chrome:// urls are still functional -// after download of a file while viewing another chrome://. -IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, - DISABLED_ChromeURLAfterDownload) { - GURL downloads_url("chrome://downloads"); - GURL extensions_url("chrome://extensions"); - FilePath zip_download; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); - zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); - GURL zip_url = net::FilePathToFileURL(zip_download); - - ui_test_utils::NavigateToURL(browser(), downloads_url); - ui_test_utils::NavigateToURL(browser(), zip_url); - ui_test_utils::WaitForDownloadCount( - browser()->profile()->GetDownloadManager(), 1); - ui_test_utils::NavigateToURL(browser(), extensions_url); - - TabContents *contents = browser()->GetSelectedTabContents(); - ASSERT_TRUE(contents); - bool domui_responded = false; - EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( - contents->render_view_host(), - L"", - L"window.domAutomationController.send(window.domui_responded_);", - &domui_responded)); - EXPECT_TRUE(domui_responded); -} - -class BrowserClosedObserver : public NotificationObserver { - public: - explicit BrowserClosedObserver(Browser* browser) { - registrar_.Add(this, NotificationType::BROWSER_CLOSED, - Source(browser)); - ui_test_utils::RunMessageLoop(); - } - - // NotificationObserver - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - switch (type.value) { - case NotificationType::BROWSER_CLOSED: - MessageLoopForUI::current()->Quit(); - break; - } - } - - private: - NotificationRegistrar registrar_; -}; - -// Test for crbug.com/12745. This tests that if a download is initiated from -// a chrome:// page that has registered and onunload handler, the browser -// will be able to close. -IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, - DISABLED_BrowserCloseAfterDownload) { - GURL downloads_url("chrome://downloads"); - FilePath zip_download; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); - zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); - ASSERT_TRUE(file_util::PathExists(zip_download)); - GURL zip_url = net::FilePathToFileURL(zip_download); - - ui_test_utils::NavigateToURL(browser(), downloads_url); - TabContents *contents = browser()->GetSelectedTabContents(); - ASSERT_TRUE(contents); - bool result = false; - EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( - contents->render_view_host(), - L"", - L"window.onunload = function() { var do_nothing = 0; }; " - L"window.domAutomationController.send(true);", - &result)); - EXPECT_TRUE(result); - ui_test_utils::NavigateToURL(browser(), zip_url); - - ui_test_utils::WaitForDownloadCount( - browser()->profile()->GetDownloadManager(), 1); - - browser()->CloseWindow(); - BrowserClosedObserver wait_for_close(browser()); -} diff --git a/chrome/browser/renderer_host/render_view_host_unittest.cc b/chrome/browser/renderer_host/render_view_host_unittest.cc deleted file mode 100644 index b70293a..0000000 --- a/chrome/browser/renderer_host/render_view_host_unittest.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/renderer_host/test_render_view_host.h" -#include "chrome/browser/tab_contents/navigation_entry.h" - -class RenderViewHostTest : public RenderViewHostTestHarness { -}; - -// All about URLs reported by the renderer should get rewritten to about:blank. -// See RenderViewHost::OnMsgNavigate for a discussion. -TEST_F(RenderViewHostTest, FilterAbout) { - rvh()->SendNavigate(1, GURL("about:cache")); - ASSERT_TRUE(controller().GetActiveEntry()); - EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->url()); -} diff --git a/chrome/browser/renderer_host/render_widget_host_unittest.cc b/chrome/browser/renderer_host/render_widget_host_unittest.cc index f41aa29..1b05260 100644 --- a/chrome/browser/renderer_host/render_widget_host_unittest.cc +++ b/chrome/browser/renderer_host/render_widget_host_unittest.cc @@ -9,7 +9,7 @@ #include "base/shared_memory.h" #include "build/build_config.h" #include "chrome/browser/renderer_host/backing_store.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/common/render_messages.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 4a6fc9c..28a64a3 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -37,7 +37,6 @@ #include "chrome/browser/renderer_host/sync_resource_handler.h" #include "chrome/browser/ssl/ssl_client_auth_handler.h" #include "chrome/browser/ssl/ssl_manager.h" -#include "chrome/browser/tab_contents/tab_util.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/render_messages.h" @@ -85,7 +84,8 @@ bool ResourceDispatcherHost::g_is_http_prioritization_enabled = true; class ResourceDispatcherHost::ShutdownTask : public Task { public: explicit ShutdownTask(ResourceDispatcherHost* resource_dispatcher_host) - : rdh_(resource_dispatcher_host) { } + : rdh_(resource_dispatcher_host) { + } void Run() { rdh_->OnShutdown(); @@ -255,7 +255,7 @@ void ResourceDispatcherHost::OnShutdown() { bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, int process_id, - int tab_contents_id, + int route_id, const GURL& url, ResourceType::Type type, ResourceHandler* handler) { @@ -263,7 +263,7 @@ bool ResourceDispatcherHost::HandleExternalProtocol(int request_id, return false; ui_loop_->PostTask(FROM_HERE, NewRunnableFunction( - &ExternalProtocolHandler::LaunchUrl, url, process_id, tab_contents_id)); + &ExternalProtocolHandler::LaunchUrl, url, process_id, route_id)); handler->OnResponseCompleted(request_id, URLRequestStatus( URLRequestStatus::FAILED, diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index fa37454..333791e 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -66,8 +66,8 @@ class ResourceDispatcherHost : public URLRequest::Delegate { protected: explicit Receiver(ChildProcessInfo::ProcessType type) - : ChildProcessInfo(type) { } - virtual ~Receiver() { } + : ChildProcessInfo(type) {} + virtual ~Receiver() {} }; // Holds the data we would like to associate with each request @@ -183,7 +183,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate { class Observer { public: - virtual ~Observer() { } + virtual ~Observer() {} virtual void OnRequestStarted(ResourceDispatcherHost* resource_dispatcher, URLRequest* request) = 0; virtual void OnResponseCompleted( @@ -199,7 +199,8 @@ class ResourceDispatcherHost : public URLRequest::Delegate { GlobalRequestID() : process_id(-1), request_id(-1) { } GlobalRequestID(int process_id, int request_id) - : process_id(process_id), request_id(request_id) { } + : process_id(process_id), request_id(request_id) { + } int process_id; int request_id; @@ -418,7 +419,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate { // Internal function to finish an async IO which has completed. Returns // true if there is more data to read (e.g. we haven't read EOF yet and // no errors have occurred). - bool CompleteRead(URLRequest *, int* bytes_read); + bool CompleteRead(URLRequest*, int* bytes_read); // Internal function to finish handling the ResponseStarted message. Returns // true on success. @@ -473,7 +474,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate { // handled, the function returns true. False otherwise. bool HandleExternalProtocol(int request_id, int process_id, - int tab_contents_id, + int route_id, const GURL& url, ResourceType::Type resource_type, ResourceHandler* handler); diff --git a/chrome/browser/renderer_host/site_instance_unittest.cc b/chrome/browser/renderer_host/site_instance_unittest.cc deleted file mode 100644 index 12bb9f9..0000000 --- a/chrome/browser/renderer_host/site_instance_unittest.cc +++ /dev/null @@ -1,458 +0,0 @@ -// Copyright (c) 2006-2008 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/string16.h" -#include "chrome/browser/child_process_security_policy.h" -#include "chrome/browser/renderer_host/browser_render_process_host.h" -#include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/render_messages.h" -#include "chrome/test/testing_profile.h" -#include "testing/gtest/include/gtest/gtest.h" - -class SiteInstanceTest : public testing::Test { - private: - MessageLoopForUI message_loop_; -}; - -namespace { - -class TestBrowsingInstance : public BrowsingInstance { - public: - TestBrowsingInstance(Profile* profile, int* deleteCounter) - : BrowsingInstance(profile), - use_process_per_site(false), - deleteCounter_(deleteCounter) { - } - - ~TestBrowsingInstance() { - (*deleteCounter_)++; - } - - // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test - // both alternatives without using command-line switches. - bool ShouldUseProcessPerSite(const GURL& url) { - return use_process_per_site; - } - - // Set by individual tests. - bool use_process_per_site; - - private: - int* deleteCounter_; -}; - - -class TestSiteInstance : public SiteInstance { - public: - static TestSiteInstance* CreateTestSiteInstance(Profile* profile, - int* siteDeleteCounter, - int* browsingDeleteCounter) { - TestBrowsingInstance* browsing_instance = - new TestBrowsingInstance(profile, browsingDeleteCounter); - return new TestSiteInstance(browsing_instance, siteDeleteCounter); - } - - private: - TestSiteInstance(BrowsingInstance* browsing_instance, int* deleteCounter) - : SiteInstance(browsing_instance), deleteCounter_(deleteCounter) {} - ~TestSiteInstance() { - (*deleteCounter_)++; - } - - int* deleteCounter_; -}; - -} // namespace - -// Test to ensure no memory leaks for SiteInstance objects. -TEST_F(SiteInstanceTest, SiteInstanceDestructor) { - // The existance of these factories will cause TabContents to create our test - // one instead of the real one. - MockRenderProcessHostFactory rph_factory; - TestRenderViewHostFactory rvh_factory(&rph_factory); - int siteDeleteCounter = 0; - int browsingDeleteCounter = 0; - const GURL url("test:foo"); - - // Ensure that instances are deleted when their NavigationEntries are gone. - TestSiteInstance* instance = - TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter, - &browsingDeleteCounter); - EXPECT_EQ(0, siteDeleteCounter); - - NavigationEntry* e1 = new NavigationEntry(instance, 0, url, GURL(), - string16(), - PageTransition::LINK); - - // Redundantly setting e1's SiteInstance shouldn't affect the ref count. - e1->set_site_instance(instance); - EXPECT_EQ(0, siteDeleteCounter); - - // Add a second reference - NavigationEntry* e2 = new NavigationEntry(instance, 0, url, - GURL(), string16(), - PageTransition::LINK); - - // Now delete both entries and be sure the SiteInstance goes away. - delete e1; - EXPECT_EQ(0, siteDeleteCounter); - EXPECT_EQ(0, browsingDeleteCounter); - delete e2; - EXPECT_EQ(1, siteDeleteCounter); - // instance is now deleted - EXPECT_EQ(1, browsingDeleteCounter); - // browsing_instance is now deleted - - // Ensure that instances are deleted when their RenderViewHosts are gone. - scoped_ptr profile(new TestingProfile()); - instance = - TestSiteInstance::CreateTestSiteInstance(profile.get(), - &siteDeleteCounter, - &browsingDeleteCounter); - { - TabContents contents(profile.get(), instance, MSG_ROUTING_NONE, NULL); - EXPECT_EQ(1, siteDeleteCounter); - EXPECT_EQ(1, browsingDeleteCounter); - } - - // Make sure that we flush any messages related to the above TabContents - // destruction. - MessageLoop::current()->RunAllPending(); - - EXPECT_EQ(2, siteDeleteCounter); - EXPECT_EQ(2, browsingDeleteCounter); - // contents is now deleted, along with instance and browsing_instance -} - -// Test that NavigationEntries with SiteInstances can be cloned, but that their -// SiteInstances can be changed afterwards. Also tests that the ref counts are -// updated properly after the change. -TEST_F(SiteInstanceTest, CloneNavigationEntry) { - int siteDeleteCounter1 = 0; - int siteDeleteCounter2 = 0; - int browsingDeleteCounter = 0; - const GURL url("test:foo"); - - SiteInstance* instance1 = - TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter1, - &browsingDeleteCounter); - SiteInstance* instance2 = - TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter2, - &browsingDeleteCounter); - - NavigationEntry* e1 = new NavigationEntry(instance1, 0, url, GURL(), - string16(), - PageTransition::LINK); - // Clone the entry - NavigationEntry* e2 = new NavigationEntry(*e1); - - // Should be able to change the SiteInstance of the cloned entry. - e2->set_site_instance(instance2); - - // The first SiteInstance should go away after deleting e1, since e2 should - // no longer be referencing it. - delete e1; - EXPECT_EQ(1, siteDeleteCounter1); - EXPECT_EQ(0, siteDeleteCounter2); - - // The second SiteInstance should go away after deleting e2. - delete e2; - EXPECT_EQ(1, siteDeleteCounter1); - EXPECT_EQ(1, siteDeleteCounter2); - - // Both BrowsingInstances are also now deleted - EXPECT_EQ(2, browsingDeleteCounter); -} - -// Test to ensure UpdateMaxPageID is working properly. -TEST_F(SiteInstanceTest, UpdateMaxPageID) { - scoped_refptr instance(SiteInstance::CreateSiteInstance(NULL)); - EXPECT_EQ(-1, instance->max_page_id()); - - // Make sure max_page_id_ is monotonically increasing. - instance->UpdateMaxPageID(3); - instance->UpdateMaxPageID(1); - EXPECT_EQ(3, instance->max_page_id()); -} - -// Test to ensure GetProcess returns and creates processes correctly. -TEST_F(SiteInstanceTest, GetProcess) { - // Ensure that GetProcess returns a process. - scoped_ptr profile(new TestingProfile()); - scoped_ptr host1; - scoped_refptr instance( - SiteInstance::CreateSiteInstance(profile.get())); - host1.reset(instance->GetProcess()); - EXPECT_TRUE(host1.get() != NULL); - - // Ensure that GetProcess creates a new process. - scoped_refptr instance2( - SiteInstance::CreateSiteInstance(profile.get())); - scoped_ptr host2(instance2->GetProcess()); - EXPECT_TRUE(host2.get() != NULL); - EXPECT_NE(host1.get(), host2.get()); -} - -// Test to ensure SetSite and site() work properly. -TEST_F(SiteInstanceTest, SetSite) { - scoped_refptr instance(SiteInstance::CreateSiteInstance(NULL)); - EXPECT_FALSE(instance->has_site()); - EXPECT_TRUE(instance->site().is_empty()); - - instance->SetSite(GURL("http://www.google.com/index.html")); - EXPECT_EQ(GURL("http://google.com"), instance->site()); - - EXPECT_TRUE(instance->has_site()); -} - -// Test to ensure GetSiteForURL properly returns sites for URLs. -TEST_F(SiteInstanceTest, GetSiteForURL) { - // Pages are irrelevant. - GURL test_url = GURL("http://www.google.com/index.html"); - EXPECT_EQ(GURL("http://google.com"), SiteInstance::GetSiteForURL(test_url)); - - // Ports are irrlevant. - test_url = GURL("https://www.google.com:8080"); - EXPECT_EQ(GURL("https://google.com"), SiteInstance::GetSiteForURL(test_url)); - - // Javascript URLs have no site. - test_url = GURL("javascript:foo();"); - EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); - - test_url = GURL("http://foo/a.html"); - EXPECT_EQ(GURL("http://foo"), SiteInstance::GetSiteForURL(test_url)); - - test_url = GURL("file:///C:/Downloads/"); - EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); - - // TODO(creis): Do we want to special case file URLs to ensure they have - // either no site or a special "file://" site? We currently return - // "file://home/" as the site, which seems broken. - // test_url = GURL("file://home/"); - // EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); -} - -// Test of distinguishing URLs from different sites. Most of this logic is -// tested in RegistryControlledDomainTest. This test focuses on URLs with -// different schemes or ports. -TEST_F(SiteInstanceTest, IsSameWebSite) { - GURL url_foo = GURL("http://foo/a.html"); - GURL url_foo2 = GURL("http://foo/b.html"); - GURL url_foo_https = GURL("https://foo/a.html"); - GURL url_foo_port = GURL("http://foo:8080/a.html"); - GURL url_javascript = GURL("javascript:alert(1);"); - GURL url_crash = GURL("about:crash"); - GURL url_hang = GURL("about:hang"); - GURL url_shorthang = GURL("about:shorthang"); - - // Same scheme and port -> same site. - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_foo, url_foo2)); - - // Different scheme -> different site. - EXPECT_FALSE(SiteInstance::IsSameWebSite(url_foo, url_foo_https)); - - // Different port -> same site. - // (Changes to document.domain make renderer ignore the port.) - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_foo, url_foo_port)); - - // JavaScript links should be considered same site for anything. - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo)); - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_https)); - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_port)); - - // The crash/hang URLs should also be treated as same site. (Bug 1143809.) - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_crash, url_foo)); - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_hang, url_foo)); - EXPECT_TRUE(SiteInstance::IsSameWebSite(url_shorthang, url_foo)); -} - -// Test to ensure that there is only one SiteInstance per site in a given -// BrowsingInstance, when process-per-site is not in use. -TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { - int deleteCounter = 0; - TestBrowsingInstance* browsing_instance = - new TestBrowsingInstance(NULL, &deleteCounter); - browsing_instance->use_process_per_site = false; - - const GURL url_a1("http://www.google.com/1.html"); - scoped_refptr site_instance_a1( - browsing_instance->GetSiteInstanceForURL(url_a1)); - EXPECT_TRUE(site_instance_a1.get() != NULL); - - // A separate site should create a separate SiteInstance. - const GURL url_b1("http://www.yahoo.com/"); - scoped_refptr site_instance_b1( - browsing_instance->GetSiteInstanceForURL(url_b1)); - EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); - - // Getting the new SiteInstance from the BrowsingInstance and from another - // SiteInstance in the BrowsingInstance should give the same result. - EXPECT_EQ(site_instance_b1.get(), - site_instance_a1->GetRelatedSiteInstance(url_b1)); - - // A second visit to the original site should return the same SiteInstance. - const GURL url_a2("http://www.google.com/2.html"); - EXPECT_EQ(site_instance_a1.get(), - browsing_instance->GetSiteInstanceForURL(url_a2)); - EXPECT_EQ(site_instance_a1.get(), - site_instance_a1->GetRelatedSiteInstance(url_a2)); - - // A visit to the original site in a new BrowsingInstance (same or different - // profile) should return a different SiteInstance. - TestBrowsingInstance* browsing_instance2 = - new TestBrowsingInstance(NULL, &deleteCounter); - browsing_instance2->use_process_per_site = false; - // Ensure the new SiteInstance is ref counted so that it gets deleted. - scoped_refptr site_instance_a2_2( - browsing_instance2->GetSiteInstanceForURL(url_a2)); - EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); - - // Should be able to see that we do have SiteInstances. - EXPECT_TRUE(browsing_instance->HasSiteInstance( - GURL("http://mail.google.com"))); - EXPECT_TRUE(browsing_instance2->HasSiteInstance( - GURL("http://mail.google.com"))); - EXPECT_TRUE(browsing_instance->HasSiteInstance( - GURL("http://mail.yahoo.com"))); - - // Should be able to see that we don't have SiteInstances. - EXPECT_FALSE(browsing_instance->HasSiteInstance( - GURL("https://www.google.com"))); - EXPECT_FALSE(browsing_instance2->HasSiteInstance( - GURL("http://www.yahoo.com"))); - - // browsing_instances will be deleted when their SiteInstances are deleted -} - -// Test to ensure that there is only one SiteInstance per site for an entire -// Profile, if process-per-site is in use. -TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInProfile) { - int deleteCounter = 0; - TestBrowsingInstance* browsing_instance = - new TestBrowsingInstance(NULL, &deleteCounter); - browsing_instance->use_process_per_site = true; - - const GURL url_a1("http://www.google.com/1.html"); - scoped_refptr site_instance_a1( - browsing_instance->GetSiteInstanceForURL(url_a1)); - EXPECT_TRUE(site_instance_a1.get() != NULL); - - // A separate site should create a separate SiteInstance. - const GURL url_b1("http://www.yahoo.com/"); - scoped_refptr site_instance_b1( - browsing_instance->GetSiteInstanceForURL(url_b1)); - EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); - - // Getting the new SiteInstance from the BrowsingInstance and from another - // SiteInstance in the BrowsingInstance should give the same result. - EXPECT_EQ(site_instance_b1.get(), - site_instance_a1->GetRelatedSiteInstance(url_b1)); - - // A second visit to the original site should return the same SiteInstance. - const GURL url_a2("http://www.google.com/2.html"); - EXPECT_EQ(site_instance_a1.get(), - browsing_instance->GetSiteInstanceForURL(url_a2)); - EXPECT_EQ(site_instance_a1.get(), - site_instance_a1->GetRelatedSiteInstance(url_a2)); - - // A visit to the original site in a new BrowsingInstance (same profile) - // should also return the same SiteInstance. - // This BrowsingInstance doesn't get its own SiteInstance within the test, so - // it won't be deleted by its children. Thus, we'll keep a ref count to it - // to make sure it gets deleted. - scoped_refptr browsing_instance2( - new TestBrowsingInstance(NULL, &deleteCounter)); - browsing_instance2->use_process_per_site = true; - EXPECT_EQ(site_instance_a1.get(), - browsing_instance2->GetSiteInstanceForURL(url_a2)); - - // A visit to the original site in a new BrowsingInstance (different profile) - // should return a different SiteInstance. - scoped_ptr profile(new TestingProfile()); - TestBrowsingInstance* browsing_instance3 = - new TestBrowsingInstance(profile.get(), &deleteCounter); - browsing_instance3->use_process_per_site = true; - // Ensure the new SiteInstance is ref counted so that it gets deleted. - scoped_refptr site_instance_a2_3( - browsing_instance3->GetSiteInstanceForURL(url_a2)); - EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); - - // Should be able to see that we do have SiteInstances. - EXPECT_TRUE(browsing_instance->HasSiteInstance( - GURL("http://mail.google.com"))); // visited before - EXPECT_TRUE(browsing_instance2->HasSiteInstance( - GURL("http://mail.google.com"))); // visited before - EXPECT_TRUE(browsing_instance->HasSiteInstance( - GURL("http://mail.yahoo.com"))); // visited before - EXPECT_TRUE(browsing_instance2->HasSiteInstance( - GURL("http://www.yahoo.com"))); // different BI, but same profile - - // Should be able to see that we don't have SiteInstances. - EXPECT_FALSE(browsing_instance->HasSiteInstance( - GURL("https://www.google.com"))); // not visited before - EXPECT_FALSE(browsing_instance3->HasSiteInstance( - GURL("http://www.yahoo.com"))); // different BI, different profile - - // browsing_instances will be deleted when their SiteInstances are deleted -} - -static SiteInstance* CreateSiteInstance(RenderProcessHostFactory* factory, - const GURL& url) { - SiteInstance* instance = SiteInstance::CreateSiteInstanceForURL(NULL, url); - instance->set_render_process_host_factory(factory); - return instance; -} - -// Test to ensure that pages that require certain privileges are grouped -// in processes with similar pages. -TEST_F(SiteInstanceTest, ProcessSharingByType) { - MockRenderProcessHostFactory rph_factory; - ChildProcessSecurityPolicy* policy = - ChildProcessSecurityPolicy::GetInstance(); - - // Make a bunch of mock renderers so that we hit the limit. - std::vector hosts; - for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) - hosts.push_back(new MockRenderProcessHost(NULL)); - - // Create some extension instances and make sure they share a process. - scoped_refptr extension1_instance( - CreateSiteInstance(&rph_factory, GURL("chrome-extension://foo/bar"))); - policy->Add(extension1_instance->GetProcess()->pid()); - policy->GrantExtensionBindings(extension1_instance->GetProcess()->pid()); - - scoped_refptr extension2_instance( - CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); - - scoped_ptr extension_host( - extension1_instance->GetProcess()); - EXPECT_EQ(extension1_instance->GetProcess(), - extension2_instance->GetProcess()); - - // Create some DOMUI instances and make sure they share a process. - scoped_refptr dom1_instance( - CreateSiteInstance(&rph_factory, GURL("chrome://newtab"))); - policy->Add(dom1_instance->GetProcess()->pid()); - policy->GrantDOMUIBindings(dom1_instance->GetProcess()->pid()); - - scoped_refptr dom2_instance( - CreateSiteInstance(&rph_factory, GURL("chrome://history"))); - - scoped_ptr dom_host(dom1_instance->GetProcess()); - EXPECT_EQ(dom1_instance->GetProcess(), dom2_instance->GetProcess()); - - // Make sure none of differing privilege processes are mixed. - EXPECT_NE(extension1_instance->GetProcess(), dom1_instance->GetProcess()); - - for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { - EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); - EXPECT_NE(dom1_instance->GetProcess(), hosts[i]); - } - - STLDeleteContainerPointers(hosts.begin(), hosts.end()); -} diff --git a/chrome/browser/renderer_host/test/DEPS b/chrome/browser/renderer_host/test/DEPS new file mode 100644 index 0000000..f433b7d --- /dev/null +++ b/chrome/browser/renderer_host/test/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + # See README.txt in this directory for why we do this. + "+chrome/browser/tab_contents", +] diff --git a/chrome/browser/renderer_host/test/README.txt b/chrome/browser/renderer_host/test/README.txt new file mode 100644 index 0000000..bf230e5 --- /dev/null +++ b/chrome/browser/renderer_host/test/README.txt @@ -0,0 +1,4 @@ +These test files would normally go in the parent directory next to the +corresponding implementation files. However, they depend on the tab_contents +directory which we don't want the normal code to use. So we put them in this +separate directory with the tab_contents includes allowed by DEPS from here only. diff --git a/chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc b/chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc new file mode 100755 index 0000000..7d2ff82 --- /dev/null +++ b/chrome/browser/renderer_host/test/render_view_host_manager_browsertest.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/browser.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/download/download_manager.h" +#include "chrome/browser/profile.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/notification_details.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" +#include "chrome/common/extensions/extension_error_reporter.h" +#include "chrome/test/in_process_browser_test.h" +#include "chrome/test/ui_test_utils.h" +#include "net/base/net_util.h" + +class RenderViewHostManagerTest : public InProcessBrowserTest { + public: + RenderViewHostManagerTest() { + EnableDOMAutomation(); + } + virtual void SetUpCommandLine(CommandLine* command_line) { + command_line->AppendSwitch(switches::kEnableExtensions); + } +}; + +// Test for crbug.com/14505. This tests that chrome:// urls are still functional +// after download of a file while viewing another chrome://. +IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, + DISABLED_ChromeURLAfterDownload) { + GURL downloads_url("chrome://downloads"); + GURL extensions_url("chrome://extensions"); + FilePath zip_download; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); + zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); + GURL zip_url = net::FilePathToFileURL(zip_download); + + ui_test_utils::NavigateToURL(browser(), downloads_url); + ui_test_utils::NavigateToURL(browser(), zip_url); + ui_test_utils::WaitForDownloadCount( + browser()->profile()->GetDownloadManager(), 1); + ui_test_utils::NavigateToURL(browser(), extensions_url); + + TabContents *contents = browser()->GetSelectedTabContents(); + ASSERT_TRUE(contents); + bool domui_responded = false; + EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( + contents->render_view_host(), + L"", + L"window.domAutomationController.send(window.domui_responded_);", + &domui_responded)); + EXPECT_TRUE(domui_responded); +} + +class BrowserClosedObserver : public NotificationObserver { + public: + explicit BrowserClosedObserver(Browser* browser) { + registrar_.Add(this, NotificationType::BROWSER_CLOSED, + Source(browser)); + ui_test_utils::RunMessageLoop(); + } + + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::BROWSER_CLOSED: + MessageLoopForUI::current()->Quit(); + break; + } + } + + private: + NotificationRegistrar registrar_; +}; + +// Test for crbug.com/12745. This tests that if a download is initiated from +// a chrome:// page that has registered and onunload handler, the browser +// will be able to close. +IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, + DISABLED_BrowserCloseAfterDownload) { + GURL downloads_url("chrome://downloads"); + FilePath zip_download; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &zip_download)); + zip_download = zip_download.AppendASCII("zip").AppendASCII("test.zip"); + ASSERT_TRUE(file_util::PathExists(zip_download)); + GURL zip_url = net::FilePathToFileURL(zip_download); + + ui_test_utils::NavigateToURL(browser(), downloads_url); + TabContents *contents = browser()->GetSelectedTabContents(); + ASSERT_TRUE(contents); + bool result = false; + EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( + contents->render_view_host(), + L"", + L"window.onunload = function() { var do_nothing = 0; }; " + L"window.domAutomationController.send(true);", + &result)); + EXPECT_TRUE(result); + ui_test_utils::NavigateToURL(browser(), zip_url); + + ui_test_utils::WaitForDownloadCount( + browser()->profile()->GetDownloadManager(), 1); + + browser()->CloseWindow(); + BrowserClosedObserver wait_for_close(browser()); +} diff --git a/chrome/browser/renderer_host/test/render_view_host_unittest.cc b/chrome/browser/renderer_host/test/render_view_host_unittest.cc new file mode 100644 index 0000000..f1f84a7 --- /dev/null +++ b/chrome/browser/renderer_host/test/render_view_host_unittest.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/renderer_host/test/test_render_view_host.h" +#include "chrome/browser/tab_contents/navigation_entry.h" + +class RenderViewHostTest : public RenderViewHostTestHarness { +}; + +// All about URLs reported by the renderer should get rewritten to about:blank. +// See RenderViewHost::OnMsgNavigate for a discussion. +TEST_F(RenderViewHostTest, FilterAbout) { + rvh()->SendNavigate(1, GURL("about:cache")); + ASSERT_TRUE(controller().GetActiveEntry()); + EXPECT_EQ(GURL("about:blank"), controller().GetActiveEntry()->url()); +} diff --git a/chrome/browser/renderer_host/test/site_instance_unittest.cc b/chrome/browser/renderer_host/test/site_instance_unittest.cc new file mode 100644 index 0000000..818ca8e --- /dev/null +++ b/chrome/browser/renderer_host/test/site_instance_unittest.cc @@ -0,0 +1,458 @@ +// Copyright (c) 2006-2008 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/string16.h" +#include "chrome/browser/child_process_security_policy.h" +#include "chrome/browser/renderer_host/browser_render_process_host.h" +#include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" +#include "chrome/browser/tab_contents/navigation_entry.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/common/render_messages.h" +#include "chrome/test/testing_profile.h" +#include "testing/gtest/include/gtest/gtest.h" + +class SiteInstanceTest : public testing::Test { + private: + MessageLoopForUI message_loop_; +}; + +namespace { + +class TestBrowsingInstance : public BrowsingInstance { + public: + TestBrowsingInstance(Profile* profile, int* deleteCounter) + : BrowsingInstance(profile), + use_process_per_site(false), + deleteCounter_(deleteCounter) { + } + + ~TestBrowsingInstance() { + (*deleteCounter_)++; + } + + // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test + // both alternatives without using command-line switches. + bool ShouldUseProcessPerSite(const GURL& url) { + return use_process_per_site; + } + + // Set by individual tests. + bool use_process_per_site; + + private: + int* deleteCounter_; +}; + + +class TestSiteInstance : public SiteInstance { + public: + static TestSiteInstance* CreateTestSiteInstance(Profile* profile, + int* siteDeleteCounter, + int* browsingDeleteCounter) { + TestBrowsingInstance* browsing_instance = + new TestBrowsingInstance(profile, browsingDeleteCounter); + return new TestSiteInstance(browsing_instance, siteDeleteCounter); + } + + private: + TestSiteInstance(BrowsingInstance* browsing_instance, int* deleteCounter) + : SiteInstance(browsing_instance), deleteCounter_(deleteCounter) {} + ~TestSiteInstance() { + (*deleteCounter_)++; + } + + int* deleteCounter_; +}; + +} // namespace + +// Test to ensure no memory leaks for SiteInstance objects. +TEST_F(SiteInstanceTest, SiteInstanceDestructor) { + // The existance of these factories will cause TabContents to create our test + // one instead of the real one. + MockRenderProcessHostFactory rph_factory; + TestRenderViewHostFactory rvh_factory(&rph_factory); + int siteDeleteCounter = 0; + int browsingDeleteCounter = 0; + const GURL url("test:foo"); + + // Ensure that instances are deleted when their NavigationEntries are gone. + TestSiteInstance* instance = + TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter, + &browsingDeleteCounter); + EXPECT_EQ(0, siteDeleteCounter); + + NavigationEntry* e1 = new NavigationEntry(instance, 0, url, GURL(), + string16(), + PageTransition::LINK); + + // Redundantly setting e1's SiteInstance shouldn't affect the ref count. + e1->set_site_instance(instance); + EXPECT_EQ(0, siteDeleteCounter); + + // Add a second reference + NavigationEntry* e2 = new NavigationEntry(instance, 0, url, + GURL(), string16(), + PageTransition::LINK); + + // Now delete both entries and be sure the SiteInstance goes away. + delete e1; + EXPECT_EQ(0, siteDeleteCounter); + EXPECT_EQ(0, browsingDeleteCounter); + delete e2; + EXPECT_EQ(1, siteDeleteCounter); + // instance is now deleted + EXPECT_EQ(1, browsingDeleteCounter); + // browsing_instance is now deleted + + // Ensure that instances are deleted when their RenderViewHosts are gone. + scoped_ptr profile(new TestingProfile()); + instance = + TestSiteInstance::CreateTestSiteInstance(profile.get(), + &siteDeleteCounter, + &browsingDeleteCounter); + { + TabContents contents(profile.get(), instance, MSG_ROUTING_NONE, NULL); + EXPECT_EQ(1, siteDeleteCounter); + EXPECT_EQ(1, browsingDeleteCounter); + } + + // Make sure that we flush any messages related to the above TabContents + // destruction. + MessageLoop::current()->RunAllPending(); + + EXPECT_EQ(2, siteDeleteCounter); + EXPECT_EQ(2, browsingDeleteCounter); + // contents is now deleted, along with instance and browsing_instance +} + +// Test that NavigationEntries with SiteInstances can be cloned, but that their +// SiteInstances can be changed afterwards. Also tests that the ref counts are +// updated properly after the change. +TEST_F(SiteInstanceTest, CloneNavigationEntry) { + int siteDeleteCounter1 = 0; + int siteDeleteCounter2 = 0; + int browsingDeleteCounter = 0; + const GURL url("test:foo"); + + SiteInstance* instance1 = + TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter1, + &browsingDeleteCounter); + SiteInstance* instance2 = + TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter2, + &browsingDeleteCounter); + + NavigationEntry* e1 = new NavigationEntry(instance1, 0, url, GURL(), + string16(), + PageTransition::LINK); + // Clone the entry + NavigationEntry* e2 = new NavigationEntry(*e1); + + // Should be able to change the SiteInstance of the cloned entry. + e2->set_site_instance(instance2); + + // The first SiteInstance should go away after deleting e1, since e2 should + // no longer be referencing it. + delete e1; + EXPECT_EQ(1, siteDeleteCounter1); + EXPECT_EQ(0, siteDeleteCounter2); + + // The second SiteInstance should go away after deleting e2. + delete e2; + EXPECT_EQ(1, siteDeleteCounter1); + EXPECT_EQ(1, siteDeleteCounter2); + + // Both BrowsingInstances are also now deleted + EXPECT_EQ(2, browsingDeleteCounter); +} + +// Test to ensure UpdateMaxPageID is working properly. +TEST_F(SiteInstanceTest, UpdateMaxPageID) { + scoped_refptr instance(SiteInstance::CreateSiteInstance(NULL)); + EXPECT_EQ(-1, instance->max_page_id()); + + // Make sure max_page_id_ is monotonically increasing. + instance->UpdateMaxPageID(3); + instance->UpdateMaxPageID(1); + EXPECT_EQ(3, instance->max_page_id()); +} + +// Test to ensure GetProcess returns and creates processes correctly. +TEST_F(SiteInstanceTest, GetProcess) { + // Ensure that GetProcess returns a process. + scoped_ptr profile(new TestingProfile()); + scoped_ptr host1; + scoped_refptr instance( + SiteInstance::CreateSiteInstance(profile.get())); + host1.reset(instance->GetProcess()); + EXPECT_TRUE(host1.get() != NULL); + + // Ensure that GetProcess creates a new process. + scoped_refptr instance2( + SiteInstance::CreateSiteInstance(profile.get())); + scoped_ptr host2(instance2->GetProcess()); + EXPECT_TRUE(host2.get() != NULL); + EXPECT_NE(host1.get(), host2.get()); +} + +// Test to ensure SetSite and site() work properly. +TEST_F(SiteInstanceTest, SetSite) { + scoped_refptr instance(SiteInstance::CreateSiteInstance(NULL)); + EXPECT_FALSE(instance->has_site()); + EXPECT_TRUE(instance->site().is_empty()); + + instance->SetSite(GURL("http://www.google.com/index.html")); + EXPECT_EQ(GURL("http://google.com"), instance->site()); + + EXPECT_TRUE(instance->has_site()); +} + +// Test to ensure GetSiteForURL properly returns sites for URLs. +TEST_F(SiteInstanceTest, GetSiteForURL) { + // Pages are irrelevant. + GURL test_url = GURL("http://www.google.com/index.html"); + EXPECT_EQ(GURL("http://google.com"), SiteInstance::GetSiteForURL(test_url)); + + // Ports are irrlevant. + test_url = GURL("https://www.google.com:8080"); + EXPECT_EQ(GURL("https://google.com"), SiteInstance::GetSiteForURL(test_url)); + + // Javascript URLs have no site. + test_url = GURL("javascript:foo();"); + EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); + + test_url = GURL("http://foo/a.html"); + EXPECT_EQ(GURL("http://foo"), SiteInstance::GetSiteForURL(test_url)); + + test_url = GURL("file:///C:/Downloads/"); + EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); + + // TODO(creis): Do we want to special case file URLs to ensure they have + // either no site or a special "file://" site? We currently return + // "file://home/" as the site, which seems broken. + // test_url = GURL("file://home/"); + // EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); +} + +// Test of distinguishing URLs from different sites. Most of this logic is +// tested in RegistryControlledDomainTest. This test focuses on URLs with +// different schemes or ports. +TEST_F(SiteInstanceTest, IsSameWebSite) { + GURL url_foo = GURL("http://foo/a.html"); + GURL url_foo2 = GURL("http://foo/b.html"); + GURL url_foo_https = GURL("https://foo/a.html"); + GURL url_foo_port = GURL("http://foo:8080/a.html"); + GURL url_javascript = GURL("javascript:alert(1);"); + GURL url_crash = GURL("about:crash"); + GURL url_hang = GURL("about:hang"); + GURL url_shorthang = GURL("about:shorthang"); + + // Same scheme and port -> same site. + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_foo, url_foo2)); + + // Different scheme -> different site. + EXPECT_FALSE(SiteInstance::IsSameWebSite(url_foo, url_foo_https)); + + // Different port -> same site. + // (Changes to document.domain make renderer ignore the port.) + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_foo, url_foo_port)); + + // JavaScript links should be considered same site for anything. + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo)); + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_https)); + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_port)); + + // The crash/hang URLs should also be treated as same site. (Bug 1143809.) + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_crash, url_foo)); + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_hang, url_foo)); + EXPECT_TRUE(SiteInstance::IsSameWebSite(url_shorthang, url_foo)); +} + +// Test to ensure that there is only one SiteInstance per site in a given +// BrowsingInstance, when process-per-site is not in use. +TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { + int deleteCounter = 0; + TestBrowsingInstance* browsing_instance = + new TestBrowsingInstance(NULL, &deleteCounter); + browsing_instance->use_process_per_site = false; + + const GURL url_a1("http://www.google.com/1.html"); + scoped_refptr site_instance_a1( + browsing_instance->GetSiteInstanceForURL(url_a1)); + EXPECT_TRUE(site_instance_a1.get() != NULL); + + // A separate site should create a separate SiteInstance. + const GURL url_b1("http://www.yahoo.com/"); + scoped_refptr site_instance_b1( + browsing_instance->GetSiteInstanceForURL(url_b1)); + EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); + + // Getting the new SiteInstance from the BrowsingInstance and from another + // SiteInstance in the BrowsingInstance should give the same result. + EXPECT_EQ(site_instance_b1.get(), + site_instance_a1->GetRelatedSiteInstance(url_b1)); + + // A second visit to the original site should return the same SiteInstance. + const GURL url_a2("http://www.google.com/2.html"); + EXPECT_EQ(site_instance_a1.get(), + browsing_instance->GetSiteInstanceForURL(url_a2)); + EXPECT_EQ(site_instance_a1.get(), + site_instance_a1->GetRelatedSiteInstance(url_a2)); + + // A visit to the original site in a new BrowsingInstance (same or different + // profile) should return a different SiteInstance. + TestBrowsingInstance* browsing_instance2 = + new TestBrowsingInstance(NULL, &deleteCounter); + browsing_instance2->use_process_per_site = false; + // Ensure the new SiteInstance is ref counted so that it gets deleted. + scoped_refptr site_instance_a2_2( + browsing_instance2->GetSiteInstanceForURL(url_a2)); + EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); + + // Should be able to see that we do have SiteInstances. + EXPECT_TRUE(browsing_instance->HasSiteInstance( + GURL("http://mail.google.com"))); + EXPECT_TRUE(browsing_instance2->HasSiteInstance( + GURL("http://mail.google.com"))); + EXPECT_TRUE(browsing_instance->HasSiteInstance( + GURL("http://mail.yahoo.com"))); + + // Should be able to see that we don't have SiteInstances. + EXPECT_FALSE(browsing_instance->HasSiteInstance( + GURL("https://www.google.com"))); + EXPECT_FALSE(browsing_instance2->HasSiteInstance( + GURL("http://www.yahoo.com"))); + + // browsing_instances will be deleted when their SiteInstances are deleted +} + +// Test to ensure that there is only one SiteInstance per site for an entire +// Profile, if process-per-site is in use. +TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInProfile) { + int deleteCounter = 0; + TestBrowsingInstance* browsing_instance = + new TestBrowsingInstance(NULL, &deleteCounter); + browsing_instance->use_process_per_site = true; + + const GURL url_a1("http://www.google.com/1.html"); + scoped_refptr site_instance_a1( + browsing_instance->GetSiteInstanceForURL(url_a1)); + EXPECT_TRUE(site_instance_a1.get() != NULL); + + // A separate site should create a separate SiteInstance. + const GURL url_b1("http://www.yahoo.com/"); + scoped_refptr site_instance_b1( + browsing_instance->GetSiteInstanceForURL(url_b1)); + EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); + + // Getting the new SiteInstance from the BrowsingInstance and from another + // SiteInstance in the BrowsingInstance should give the same result. + EXPECT_EQ(site_instance_b1.get(), + site_instance_a1->GetRelatedSiteInstance(url_b1)); + + // A second visit to the original site should return the same SiteInstance. + const GURL url_a2("http://www.google.com/2.html"); + EXPECT_EQ(site_instance_a1.get(), + browsing_instance->GetSiteInstanceForURL(url_a2)); + EXPECT_EQ(site_instance_a1.get(), + site_instance_a1->GetRelatedSiteInstance(url_a2)); + + // A visit to the original site in a new BrowsingInstance (same profile) + // should also return the same SiteInstance. + // This BrowsingInstance doesn't get its own SiteInstance within the test, so + // it won't be deleted by its children. Thus, we'll keep a ref count to it + // to make sure it gets deleted. + scoped_refptr browsing_instance2( + new TestBrowsingInstance(NULL, &deleteCounter)); + browsing_instance2->use_process_per_site = true; + EXPECT_EQ(site_instance_a1.get(), + browsing_instance2->GetSiteInstanceForURL(url_a2)); + + // A visit to the original site in a new BrowsingInstance (different profile) + // should return a different SiteInstance. + scoped_ptr profile(new TestingProfile()); + TestBrowsingInstance* browsing_instance3 = + new TestBrowsingInstance(profile.get(), &deleteCounter); + browsing_instance3->use_process_per_site = true; + // Ensure the new SiteInstance is ref counted so that it gets deleted. + scoped_refptr site_instance_a2_3( + browsing_instance3->GetSiteInstanceForURL(url_a2)); + EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); + + // Should be able to see that we do have SiteInstances. + EXPECT_TRUE(browsing_instance->HasSiteInstance( + GURL("http://mail.google.com"))); // visited before + EXPECT_TRUE(browsing_instance2->HasSiteInstance( + GURL("http://mail.google.com"))); // visited before + EXPECT_TRUE(browsing_instance->HasSiteInstance( + GURL("http://mail.yahoo.com"))); // visited before + EXPECT_TRUE(browsing_instance2->HasSiteInstance( + GURL("http://www.yahoo.com"))); // different BI, but same profile + + // Should be able to see that we don't have SiteInstances. + EXPECT_FALSE(browsing_instance->HasSiteInstance( + GURL("https://www.google.com"))); // not visited before + EXPECT_FALSE(browsing_instance3->HasSiteInstance( + GURL("http://www.yahoo.com"))); // different BI, different profile + + // browsing_instances will be deleted when their SiteInstances are deleted +} + +static SiteInstance* CreateSiteInstance(RenderProcessHostFactory* factory, + const GURL& url) { + SiteInstance* instance = SiteInstance::CreateSiteInstanceForURL(NULL, url); + instance->set_render_process_host_factory(factory); + return instance; +} + +// Test to ensure that pages that require certain privileges are grouped +// in processes with similar pages. +TEST_F(SiteInstanceTest, ProcessSharingByType) { + MockRenderProcessHostFactory rph_factory; + ChildProcessSecurityPolicy* policy = + ChildProcessSecurityPolicy::GetInstance(); + + // Make a bunch of mock renderers so that we hit the limit. + std::vector hosts; + for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) + hosts.push_back(new MockRenderProcessHost(NULL)); + + // Create some extension instances and make sure they share a process. + scoped_refptr extension1_instance( + CreateSiteInstance(&rph_factory, GURL("chrome-extension://foo/bar"))); + policy->Add(extension1_instance->GetProcess()->pid()); + policy->GrantExtensionBindings(extension1_instance->GetProcess()->pid()); + + scoped_refptr extension2_instance( + CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); + + scoped_ptr extension_host( + extension1_instance->GetProcess()); + EXPECT_EQ(extension1_instance->GetProcess(), + extension2_instance->GetProcess()); + + // Create some DOMUI instances and make sure they share a process. + scoped_refptr dom1_instance( + CreateSiteInstance(&rph_factory, GURL("chrome://newtab"))); + policy->Add(dom1_instance->GetProcess()->pid()); + policy->GrantDOMUIBindings(dom1_instance->GetProcess()->pid()); + + scoped_refptr dom2_instance( + CreateSiteInstance(&rph_factory, GURL("chrome://history"))); + + scoped_ptr dom_host(dom1_instance->GetProcess()); + EXPECT_EQ(dom1_instance->GetProcess(), dom2_instance->GetProcess()); + + // Make sure none of differing privilege processes are mixed. + EXPECT_NE(extension1_instance->GetProcess(), dom1_instance->GetProcess()); + + for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { + EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); + EXPECT_NE(dom1_instance->GetProcess(), hosts[i]); + } + + STLDeleteContainerPointers(hosts.begin(), hosts.end()); +} diff --git a/chrome/browser/renderer_host/test/test_render_view_host.cc b/chrome/browser/renderer_host/test/test_render_view_host.cc new file mode 100644 index 0000000..17b91e3 --- /dev/null +++ b/chrome/browser/renderer_host/test/test_render_view_host.cc @@ -0,0 +1,101 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/renderer_host/test/test_render_view_host.h" + +#include "chrome/browser/renderer_host/backing_store.h" +#include "chrome/browser/tab_contents/test_web_contents.h" +#include "chrome/common/render_messages.h" + +using webkit_glue::PasswordForm; + +TestRenderViewHost::TestRenderViewHost(SiteInstance* instance, + RenderViewHostDelegate* delegate, + int routing_id, + base::WaitableEvent* modal_dialog_event) + : RenderViewHost(instance, delegate, routing_id, modal_dialog_event), + render_view_created_(false), + delete_counter_(NULL) { + set_view(new TestRenderWidgetHostView(this)); +} + +TestRenderViewHost::~TestRenderViewHost() { + if (delete_counter_) + ++*delete_counter_; + + // Since this isn't a traditional view, we have to delete it. + delete view(); +} + +bool TestRenderViewHost::CreateRenderView() { + DCHECK(!render_view_created_); + render_view_created_ = true; + return true; +} + +bool TestRenderViewHost::IsRenderViewLive() const { + return render_view_created_; +} + +void TestRenderViewHost::TestOnMessageReceived(const IPC::Message& msg) { + OnMessageReceived(msg); +} + +void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) { + ViewHostMsg_FrameNavigate_Params params; + + params.page_id = page_id; + params.url = url; + params.referrer = GURL::EmptyGURL(); + params.transition = PageTransition::LINK; + params.redirects = std::vector(); + params.should_update_history = true; + params.searchable_form_url = GURL::EmptyGURL(); + params.searchable_form_element_name = std::wstring(); + params.searchable_form_encoding = std::string(); + params.password_form = PasswordForm(); + params.security_info = std::string(); + params.gesture = NavigationGestureUser; + params.contents_mime_type = std::string(); + params.is_post = false; + params.is_content_filtered = false; + params.http_status_code = 0; + + ViewHostMsg_FrameNavigate msg(1, params); + OnMsgNavigate(msg); +} + +TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh) + : rwh_(rwh), + is_showing_(false) { +} + +BackingStore* TestRenderWidgetHostView::AllocBackingStore( + const gfx::Size& size) { + return new BackingStore(rwh_, size); +} + +void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { + controller().LoadURL(url, GURL(), 0); + rvh()->SendNavigate(process()->max_page_id() + 1, url); +} + +void RenderViewHostTestHarness::SetUp() { + // See comment above profile_ decl for why we check for NULL here. + if (!profile_.get()) + profile_.reset(new TestingProfile()); + + // This will be deleted when the TabContents goes away. + SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); + + contents_.reset(new TestTabContents(profile_.get(), instance)); +} + +void RenderViewHostTestHarness::TearDown() { + contents_.reset(); + + // Make sure that we flush any messages related to TabContents destruction + // before we destroy the profile. + MessageLoop::current()->RunAllPending(); +} diff --git a/chrome/browser/renderer_host/test/test_render_view_host.h b/chrome/browser/renderer_host/test/test_render_view_host.h new file mode 100644 index 0000000..d87ce14 --- /dev/null +++ b/chrome/browser/renderer_host/test/test_render_view_host.h @@ -0,0 +1,257 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_RENDERER_HOST_TEST_TEST_RENDER_VIEW_HOST_H_ +#define CHROME_BROWSER_RENDERER_HOST_TEST_TEST_RENDER_VIEW_HOST_H_ + +#include "base/basictypes.h" +#include "base/message_loop.h" +#include "build/build_config.h" +#include "chrome/browser/renderer_host/mock_render_process_host.h" +#include "chrome/browser/renderer_host/render_widget_host_view.h" +#include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/renderer_host/render_view_host_factory.h" +#include "chrome/browser/renderer_host/site_instance.h" +#include "chrome/browser/tab_contents/test_web_contents.h" +#include "chrome/test/testing_profile.h" +#include "testing/gtest/include/gtest/gtest.h" + +#if defined(OS_WIN) +#include "chrome/browser/tab_contents/navigation_controller.h" +#elif defined(OS_POSIX) +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + +class TestTabContents; + +// This file provides a testing framework for mocking out the RenderProcessHost +// layer. It allows you to test RenderViewHost, TabContents, +// NavigationController, and other layers above that without running an actual +// renderer process. +// +// To use, derive your test base class from RenderViewHostTestHarness. + +// TestRenderViewHostView ------------------------------------------------------ + +// Subclass the RenderViewHost's view so that we can call Show(), etc., +// without having side-effects. +class TestRenderWidgetHostView : public RenderWidgetHostView { + public: + explicit TestRenderWidgetHostView(RenderWidgetHost* rwh); + + virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, + const gfx::Rect& pos) {} + virtual RenderWidgetHost* GetRenderWidgetHost() const { return NULL; } + virtual void DidBecomeSelected() {} + virtual void WasHidden() {} + virtual void SetSize(const gfx::Size& size) {} + virtual gfx::NativeView GetNativeView() { return NULL; } + virtual void MovePluginWindows( + const std::vector& plugin_window_moves) {} +#if defined(OS_WIN) + virtual void ForwardMouseEventToRenderer(UINT message, + WPARAM wparam, + LPARAM lparam) {} +#endif + virtual void Focus() {} + virtual void Blur() {} + virtual bool HasFocus() { return true; } + virtual void AdvanceFocus(bool reverse) {} + virtual void Show() { is_showing_ = true; } + virtual void Hide() { is_showing_ = false; } + virtual gfx::Rect GetViewBounds() const { return gfx::Rect(); } + virtual void SetIsLoading(bool is_loading) {} + virtual void UpdateCursor(const WebCursor& cursor) {} + virtual void UpdateCursorIfOverSelf() {} + virtual void IMEUpdateStatus(int control, const gfx::Rect& caret_rect) {} + virtual void DidPaintRect(const gfx::Rect& rect) {} + virtual void DidScrollRect(const gfx::Rect& rect, int dx, int dy) {} + virtual void RenderViewGone() { delete this; } + virtual void Destroy() {} + virtual void PrepareToDestroy() {} + virtual void SetTooltipText(const std::wstring& tooltip_text) {} + virtual BackingStore* AllocBackingStore(const gfx::Size& size); +#if defined(OS_MACOSX) + virtual void ShowPopupWithItems(gfx::Rect bounds, + int item_height, + int selected_item, + const std::vector& items) {} +#endif + + bool is_showing() const { return is_showing_; } + + private: + RenderWidgetHost* rwh_; + bool is_showing_; +}; + +// TestRenderViewHost ---------------------------------------------------------- + +// TODO(brettw) this should use a TestTabContents which should be generalized +// from the TabContents test. We will probably also need that class' version of +// CreateRenderViewForRenderManager when more complicate tests start using this. +class TestRenderViewHost : public RenderViewHost { + public: + TestRenderViewHost(SiteInstance* instance, + RenderViewHostDelegate* delegate, + int routing_id, + base::WaitableEvent* modal_dialog_event); + virtual ~TestRenderViewHost(); + + // Testing functions --------------------------------------------------------- + + // Calls the RenderViewHosts' private OnMessageReceived function with the + // given message. + void TestOnMessageReceived(const IPC::Message& msg); + + // Calls OnMsgNavigate on the RenderViewHost with the given information, + // setting the rest of the parameters in the message to the "typical" values. + // This is a helper function for simulating the most common types of loads. + void SendNavigate(int page_id, const GURL& url); + + // If set, *delete_counter is incremented when this object destructs. + void set_delete_counter(int* delete_counter) { + delete_counter_ = delete_counter; + } + + // Sets whether the RenderView currently exists or not. This controls the + // return value from IsRenderViewLive, which the rest of the system uses to + // check whether the RenderView has crashed or not. + void set_render_view_created(bool created) { + render_view_created_ = created; + } + + // RenderViewHost overrides -------------------------------------------------- + + virtual bool CreateRenderView(); + virtual bool IsRenderViewLive() const; + + private: + FRIEND_TEST(RenderViewHostTest, FilterNavigate); + + // Tracks if the caller thinks if it created the RenderView. This is so we can + // respond to IsRenderViewLive appropriately. + bool render_view_created_; + + // See set_delete_counter() above. May be NULL. + int* delete_counter_; + + DISALLOW_COPY_AND_ASSIGN(TestRenderViewHost); +}; + +// TestRenderViewHostFactory --------------------------------------------------- + +// Manages creation of the RenderViewHosts using our special subclass. This +// automatically registers itself when it goes in scope, and unregisters itself +// when it goes out of scope. Since you can't have more than one factory +// registered at a time, you can only have one of these objects at a time. +class TestRenderViewHostFactory : public RenderViewHostFactory { + public: + TestRenderViewHostFactory(RenderProcessHostFactory* rph_factory) + : render_process_host_factory_(rph_factory) { + RenderViewHostFactory::RegisterFactory(this); + } + virtual ~TestRenderViewHostFactory() { + RenderViewHostFactory::UnregisterFactory(); + } + + virtual void set_render_process_host_factory( + RenderProcessHostFactory* rph_factory) { + render_process_host_factory_ = rph_factory; + } + + virtual RenderViewHost* CreateRenderViewHost( + SiteInstance* instance, + RenderViewHostDelegate* delegate, + int routing_id, + base::WaitableEvent* modal_dialog_event) { + // See declaration of render_process_host_factory_ below. + instance->set_render_process_host_factory(render_process_host_factory_); + return new TestRenderViewHost(instance, delegate, routing_id, + modal_dialog_event); + } + + private: + // This is a bit of a hack. With the current design of the site instances / + // browsing instances, it's difficult to pass a RenderProcessHostFactory + // around properly. + // + // Instead, we set it right before we create a new RenderViewHost, which + // happens before the RenderProcessHost is created. This way, the instance + // has the correct factory and creates our special RenderProcessHosts. + RenderProcessHostFactory* render_process_host_factory_; + + DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostFactory); +}; + +// RenderViewHostTestHarness --------------------------------------------------- + +class RenderViewHostTestHarness : public testing::Test { + public: + RenderViewHostTestHarness() + : rph_factory_(), + rvh_factory_(&rph_factory_), + contents_(NULL) {} + virtual ~RenderViewHostTestHarness() {} + + NavigationController& controller() { + return contents_->controller(); + } + + TestTabContents* contents() { + return contents_.get(); + } + + TestRenderViewHost* rvh() { + return static_cast(contents_->render_view_host()); + } + + TestRenderViewHost* pending_rvh() { + return static_cast( + contents_->render_manager()->pending_render_view_host()); + } + + TestRenderViewHost* active_rvh() { + return pending_rvh() ? pending_rvh() : rvh(); + } + + TestingProfile* profile() { + return profile_.get(); + } + + MockRenderProcessHost* process() { + return static_cast(rvh()->process()); + } + + // Frees the current tab contents for tests that want to test destruction. + void DeleteContents() { + contents_.reset(); + } + + // Creates a pending navigation to the given oURL with the default parameters + // and the commits the load with a page ID one larger than any seen. This + // emulates what happens on a new navigation. + void NavigateAndCommit(const GURL& url); + + protected: + // testing::Test + virtual void SetUp(); + virtual void TearDown(); + + // This profile will be created in SetUp if it has not already been created. + // This allows tests to override the profile if they so choose in their own + // SetUp function before calling the base class's (us) SetUp(). + scoped_ptr profile_; + + MessageLoopForUI message_loop_; + + MockRenderProcessHostFactory rph_factory_; + TestRenderViewHostFactory rvh_factory_; + + scoped_ptr contents_; + + DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness); +}; + +#endif // CHROME_BROWSER_RENDERER_HOST_TEST_TEST_RENDER_VIEW_HOST_H_ diff --git a/chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc b/chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc new file mode 100644 index 0000000..bd4069e --- /dev/null +++ b/chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc @@ -0,0 +1,61 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include + +#include "base/message_loop.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/renderer_host/render_process_host.h" +#include "chrome/browser/renderer_host/web_cache_manager.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/test/in_process_browser_test.h" +#include "chrome/test/ui_test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" + +class WebCacheManagerBrowserTest : public InProcessBrowserTest { +}; + +// Regression test for http://crbug.com/12362. If a renderer crashes and the +// user navigates to another tab and back, the browser doesn't crash. +// TODO(jam): http://crbug.com/15288 disabled because it fails on the build bot. +IN_PROC_BROWSER_TEST_F(WebCacheManagerBrowserTest, DISABLED_CrashOnceOnly) { + GURL url(ui_test_utils::GetTestUrl(L"google", L"google.html")); + + ui_test_utils::NavigateToURL(browser(), url); + + browser()->NewTab(); + ui_test_utils::NavigateToURL(browser(), url); + + TabContents* tab = browser()->GetTabContentsAt(0); + ASSERT_TRUE(tab != NULL); + base::KillProcess( + tab->process()->process().handle(), base::PROCESS_END_KILLED_BY_USER, + true); + + browser()->SelectTabContentsAt(0, true); + browser()->NewTab(); + ui_test_utils::NavigateToURL(browser(), url); + + browser()->SelectTabContentsAt(0, true); + browser()->NewTab(); + ui_test_utils::NavigateToURL(browser(), url); + + // We would have crashed at the above line with the bug. + + browser()->SelectTabContentsAt(0, true); + browser()->CloseTab(); + browser()->SelectTabContentsAt(0, true); + browser()->CloseTab(); + browser()->SelectTabContentsAt(0, true); + browser()->CloseTab(); + + ui_test_utils::NavigateToURL(browser(), url); + + EXPECT_EQ( + WebCacheManager::GetInstance()->active_renderers_.size(), 1U); + EXPECT_EQ( + WebCacheManager::GetInstance()->inactive_renderers_.size(), 0U); + EXPECT_EQ( + WebCacheManager::GetInstance()->stats_.size(), 1U); +} diff --git a/chrome/browser/renderer_host/test_render_view_host.cc b/chrome/browser/renderer_host/test_render_view_host.cc deleted file mode 100644 index 982beb6..0000000 --- a/chrome/browser/renderer_host/test_render_view_host.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/renderer_host/test_render_view_host.h" - -#include "chrome/browser/renderer_host/backing_store.h" -#include "chrome/browser/tab_contents/test_web_contents.h" -#include "chrome/common/render_messages.h" - -using webkit_glue::PasswordForm; - -TestRenderViewHost::TestRenderViewHost(SiteInstance* instance, - RenderViewHostDelegate* delegate, - int routing_id, - base::WaitableEvent* modal_dialog_event) - : RenderViewHost(instance, delegate, routing_id, modal_dialog_event), - render_view_created_(false), - delete_counter_(NULL) { - set_view(new TestRenderWidgetHostView(this)); -} - -TestRenderViewHost::~TestRenderViewHost() { - if (delete_counter_) - ++*delete_counter_; - - // Since this isn't a traditional view, we have to delete it. - delete view(); -} - -bool TestRenderViewHost::CreateRenderView() { - DCHECK(!render_view_created_); - render_view_created_ = true; - return true; -} - -bool TestRenderViewHost::IsRenderViewLive() const { - return render_view_created_; -} - -void TestRenderViewHost::TestOnMessageReceived(const IPC::Message& msg) { - OnMessageReceived(msg); -} - -void TestRenderViewHost::SendNavigate(int page_id, const GURL& url) { - ViewHostMsg_FrameNavigate_Params params; - - params.page_id = page_id; - params.url = url; - params.referrer = GURL::EmptyGURL(); - params.transition = PageTransition::LINK; - params.redirects = std::vector(); - params.should_update_history = true; - params.searchable_form_url = GURL::EmptyGURL(); - params.searchable_form_element_name = std::wstring(); - params.searchable_form_encoding = std::string(); - params.password_form = PasswordForm(); - params.security_info = std::string(); - params.gesture = NavigationGestureUser; - params.contents_mime_type = std::string(); - params.is_post = false; - params.is_content_filtered = false; - params.http_status_code = 0; - - ViewHostMsg_FrameNavigate msg(1, params); - OnMsgNavigate(msg); -} - -TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh) - : rwh_(rwh), - is_showing_(false) { -} - -BackingStore* TestRenderWidgetHostView::AllocBackingStore( - const gfx::Size& size) { - return new BackingStore(rwh_, size); -} - -void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { - controller().LoadURL(url, GURL(), 0); - rvh()->SendNavigate(process()->max_page_id() + 1, url); -} - -void RenderViewHostTestHarness::SetUp() { - // See comment above profile_ decl for why we check for NULL here. - if (!profile_.get()) - profile_.reset(new TestingProfile()); - - // This will be deleted when the TabContents goes away. - SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); - - contents_.reset(new TestTabContents(profile_.get(), instance)); -} - -void RenderViewHostTestHarness::TearDown() { - contents_.reset(); - - // Make sure that we flush any messages related to TabContents destruction - // before we destroy the profile. - MessageLoop::current()->RunAllPending(); -} diff --git a/chrome/browser/renderer_host/test_render_view_host.h b/chrome/browser/renderer_host/test_render_view_host.h deleted file mode 100644 index 39bfce6..0000000 --- a/chrome/browser/renderer_host/test_render_view_host.h +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_ -#define CHROME_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_ - -#include "base/basictypes.h" -#include "base/message_loop.h" -#include "build/build_config.h" -#include "chrome/browser/renderer_host/mock_render_process_host.h" -#include "chrome/browser/renderer_host/render_widget_host_view.h" -#include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/renderer_host/render_view_host_factory.h" -#include "chrome/browser/renderer_host/site_instance.h" -#include "chrome/browser/tab_contents/test_web_contents.h" -#include "chrome/test/testing_profile.h" -#include "testing/gtest/include/gtest/gtest.h" - -#if defined(OS_WIN) -#include "chrome/browser/tab_contents/navigation_controller.h" -#elif defined(OS_POSIX) -#include "chrome/common/temp_scaffolding_stubs.h" -#endif - -class TestTabContents; - -// This file provides a testing framework for mocking out the RenderProcessHost -// layer. It allows you to test RenderViewHost, TabContents, -// NavigationController, and other layers above that without running an actual -// renderer process. -// -// To use, derive your test base class from RenderViewHostTestHarness. - -// TestRenderViewHostView ------------------------------------------------------ - -// Subclass the RenderViewHost's view so that we can call Show(), etc., -// without having side-effects. -class TestRenderWidgetHostView : public RenderWidgetHostView { - public: - explicit TestRenderWidgetHostView(RenderWidgetHost* rwh); - - virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, - const gfx::Rect& pos) {} - virtual RenderWidgetHost* GetRenderWidgetHost() const { return NULL; } - virtual void DidBecomeSelected() {} - virtual void WasHidden() {} - virtual void SetSize(const gfx::Size& size) {} - virtual gfx::NativeView GetNativeView() { return NULL; } - virtual void MovePluginWindows( - const std::vector& plugin_window_moves) {} -#if defined(OS_WIN) - virtual void ForwardMouseEventToRenderer(UINT message, - WPARAM wparam, - LPARAM lparam) {} -#endif - virtual void Focus() {} - virtual void Blur() {} - virtual bool HasFocus() { return true; } - virtual void AdvanceFocus(bool reverse) {} - virtual void Show() { is_showing_ = true; } - virtual void Hide() { is_showing_ = false; } - virtual gfx::Rect GetViewBounds() const { return gfx::Rect(); } - virtual void SetIsLoading(bool is_loading) {} - virtual void UpdateCursor(const WebCursor& cursor) {} - virtual void UpdateCursorIfOverSelf() {} - virtual void IMEUpdateStatus(int control, const gfx::Rect& caret_rect) {} - virtual void DidPaintRect(const gfx::Rect& rect) {} - virtual void DidScrollRect(const gfx::Rect& rect, int dx, int dy) {} - virtual void RenderViewGone() { delete this; } - virtual void Destroy() {} - virtual void PrepareToDestroy() {} - virtual void SetTooltipText(const std::wstring& tooltip_text) {} - virtual BackingStore* AllocBackingStore(const gfx::Size& size); -#if defined(OS_MACOSX) - virtual void ShowPopupWithItems(gfx::Rect bounds, - int item_height, - int selected_item, - const std::vector& items) {} -#endif - - bool is_showing() const { return is_showing_; } - - private: - RenderWidgetHost* rwh_; - bool is_showing_; -}; - -// TestRenderViewHost ---------------------------------------------------------- - -// TODO(brettw) this should use a TestTabContents which should be generalized -// from the TabContents test. We will probably also need that class' version of -// CreateRenderViewForRenderManager when more complicate tests start using this. -class TestRenderViewHost : public RenderViewHost { - public: - TestRenderViewHost(SiteInstance* instance, - RenderViewHostDelegate* delegate, - int routing_id, - base::WaitableEvent* modal_dialog_event); - virtual ~TestRenderViewHost(); - - // Testing functions --------------------------------------------------------- - - // Calls the RenderViewHosts' private OnMessageReceived function with the - // given message. - void TestOnMessageReceived(const IPC::Message& msg); - - // Calls OnMsgNavigate on the RenderViewHost with the given information, - // setting the rest of the parameters in the message to the "typical" values. - // This is a helper function for simulating the most common types of loads. - void SendNavigate(int page_id, const GURL& url); - - // If set, *delete_counter is incremented when this object destructs. - void set_delete_counter(int* delete_counter) { - delete_counter_ = delete_counter; - } - - // Sets whether the RenderView currently exists or not. This controls the - // return value from IsRenderViewLive, which the rest of the system uses to - // check whether the RenderView has crashed or not. - void set_render_view_created(bool created) { - render_view_created_ = created; - } - - // RenderViewHost overrides -------------------------------------------------- - - virtual bool CreateRenderView(); - virtual bool IsRenderViewLive() const; - - private: - FRIEND_TEST(RenderViewHostTest, FilterNavigate); - - // Tracks if the caller thinks if it created the RenderView. This is so we can - // respond to IsRenderViewLive appropriately. - bool render_view_created_; - - // See set_delete_counter() above. May be NULL. - int* delete_counter_; - - DISALLOW_COPY_AND_ASSIGN(TestRenderViewHost); -}; - -// TestRenderViewHostFactory --------------------------------------------------- - -// Manages creation of the RenderViewHosts using our special subclass. This -// automatically registers itself when it goes in scope, and unregisters itself -// when it goes out of scope. Since you can't have more than one factory -// registered at a time, you can only have one of these objects at a time. -class TestRenderViewHostFactory : public RenderViewHostFactory { - public: - TestRenderViewHostFactory(RenderProcessHostFactory* rph_factory) - : render_process_host_factory_(rph_factory) { - RenderViewHostFactory::RegisterFactory(this); - } - virtual ~TestRenderViewHostFactory() { - RenderViewHostFactory::UnregisterFactory(); - } - - virtual void set_render_process_host_factory( - RenderProcessHostFactory* rph_factory) { - render_process_host_factory_ = rph_factory; - } - - virtual RenderViewHost* CreateRenderViewHost( - SiteInstance* instance, - RenderViewHostDelegate* delegate, - int routing_id, - base::WaitableEvent* modal_dialog_event) { - // See declaration of render_process_host_factory_ below. - instance->set_render_process_host_factory(render_process_host_factory_); - return new TestRenderViewHost(instance, delegate, routing_id, - modal_dialog_event); - } - - private: - // This is a bit of a hack. With the current design of the site instances / - // browsing instances, it's difficult to pass a RenderProcessHostFactory - // around properly. - // - // Instead, we set it right before we create a new RenderViewHost, which - // happens before the RenderProcessHost is created. This way, the instance - // has the correct factory and creates our special RenderProcessHosts. - RenderProcessHostFactory* render_process_host_factory_; - - DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostFactory); -}; - -// RenderViewHostTestHarness --------------------------------------------------- - -class RenderViewHostTestHarness : public testing::Test { - public: - RenderViewHostTestHarness() - : rph_factory_(), - rvh_factory_(&rph_factory_), - contents_(NULL) {} - virtual ~RenderViewHostTestHarness() {} - - NavigationController& controller() { - return contents_->controller(); - } - - TestTabContents* contents() { - return contents_.get(); - } - - TestRenderViewHost* rvh() { - return static_cast(contents_->render_view_host()); - } - - TestRenderViewHost* pending_rvh() { - return static_cast( - contents_->render_manager()->pending_render_view_host()); - } - - TestRenderViewHost* active_rvh() { - return pending_rvh() ? pending_rvh() : rvh(); - } - - TestingProfile* profile() { - return profile_.get(); - } - - MockRenderProcessHost* process() { - return static_cast(rvh()->process()); - } - - // Frees the current tab contents for tests that want to test destruction. - void DeleteContents() { - contents_.reset(); - } - - // Creates a pending navigation to the given oURL with the default parameters - // and the commits the load with a page ID one larger than any seen. This - // emulates what happens on a new navigation. - void NavigateAndCommit(const GURL& url); - - protected: - // testing::Test - virtual void SetUp(); - virtual void TearDown(); - - // This profile will be created in SetUp if it has not already been created. - // This allows tests to override the profile if they so choose in their own - // SetUp function before calling the base class's (us) SetUp(). - scoped_ptr profile_; - - MessageLoopForUI message_loop_; - - MockRenderProcessHostFactory rph_factory_; - TestRenderViewHostFactory rvh_factory_; - - scoped_ptr contents_; - - DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness); -}; - -#endif // CHROME_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_ diff --git a/chrome/browser/renderer_host/web_cache_manager_browser_test.cc b/chrome/browser/renderer_host/web_cache_manager_browser_test.cc deleted file mode 100644 index bd4069e..0000000 --- a/chrome/browser/renderer_host/web_cache_manager_browser_test.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include - -#include "base/message_loop.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/renderer_host/render_process_host.h" -#include "chrome/browser/renderer_host/web_cache_manager.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" -#include "testing/gtest/include/gtest/gtest.h" - -class WebCacheManagerBrowserTest : public InProcessBrowserTest { -}; - -// Regression test for http://crbug.com/12362. If a renderer crashes and the -// user navigates to another tab and back, the browser doesn't crash. -// TODO(jam): http://crbug.com/15288 disabled because it fails on the build bot. -IN_PROC_BROWSER_TEST_F(WebCacheManagerBrowserTest, DISABLED_CrashOnceOnly) { - GURL url(ui_test_utils::GetTestUrl(L"google", L"google.html")); - - ui_test_utils::NavigateToURL(browser(), url); - - browser()->NewTab(); - ui_test_utils::NavigateToURL(browser(), url); - - TabContents* tab = browser()->GetTabContentsAt(0); - ASSERT_TRUE(tab != NULL); - base::KillProcess( - tab->process()->process().handle(), base::PROCESS_END_KILLED_BY_USER, - true); - - browser()->SelectTabContentsAt(0, true); - browser()->NewTab(); - ui_test_utils::NavigateToURL(browser(), url); - - browser()->SelectTabContentsAt(0, true); - browser()->NewTab(); - ui_test_utils::NavigateToURL(browser(), url); - - // We would have crashed at the above line with the bug. - - browser()->SelectTabContentsAt(0, true); - browser()->CloseTab(); - browser()->SelectTabContentsAt(0, true); - browser()->CloseTab(); - browser()->SelectTabContentsAt(0, true); - browser()->CloseTab(); - - ui_test_utils::NavigateToURL(browser(), url); - - EXPECT_EQ( - WebCacheManager::GetInstance()->active_renderers_.size(), 1U); - EXPECT_EQ( - WebCacheManager::GetInstance()->inactive_renderers_.size(), 0U); - EXPECT_EQ( - WebCacheManager::GetInstance()->stats_.size(), 1U); -} diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc index 7e70e08..43e77a8 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.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/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" #include "chrome/browser/tab_contents/navigation_entry.h" diff --git a/chrome/browser/sessions/tab_restore_service_unittest.cc b/chrome/browser/sessions/tab_restore_service_unittest.cc index c1ad7b1..97fceff 100644 --- a/chrome/browser/sessions/tab_restore_service_unittest.cc +++ b/chrome/browser/sessions/tab_restore_service_unittest.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/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/sessions/session_types.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/tab_contents/navigation_entry.h" diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 4683259..1986171 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -281,6 +281,76 @@ void InterstitialPage::Observe(NotificationType type, } } +RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() const { + return rvh_view_delegate_.get(); +} + +const GURL& InterstitialPage::GetURL() const { + return url_; +} + +void InterstitialPage::RenderViewGone(RenderViewHost* render_view_host) { + // Our renderer died. This should not happen in normal cases. + // Just dismiss the interstitial. + DontProceed(); +} + +void InterstitialPage::DidNavigate( + RenderViewHost* render_view_host, + const ViewHostMsg_FrameNavigate_Params& params) { + // A fast user could have navigated away from the page that triggered the + // interstitial while the interstitial was loading, that would have disabled + // us. In that case we can dismiss ourselves. + if (!enabled_){ + DontProceed(); + return; + } + + // The RenderViewHost has loaded its contents, we can show it now. + render_view_host_->view()->Show(); + tab_->set_interstitial_page(this); + + RenderWidgetHostView* rwh_view = tab_->render_view_host()->view(); + + // The RenderViewHost may already have crashed before we even get here. + if (rwh_view) { + // If the page has focus, focus the interstitial. + if (rwh_view->HasFocus()) + Focus(); + + // Hide the original RVH since we're showing the interstitial instead. + rwh_view->Hide(); + } + + // Notify the tab we are not loading so the throbber is stopped. It also + // causes a NOTIFY_LOAD_STOP notification, that the AutomationProvider (used + // by the UI tests) expects to consider a navigation as complete. Without + // this, navigating in a UI test to a URL that triggers an interstitial would + // hang. + tab_->SetIsLoading(false, NULL); +} + +void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host, + int32 page_id, + const std::wstring& title) { + DCHECK(render_view_host == render_view_host_); + NavigationEntry* entry = tab_->controller().GetActiveEntry(); + // If this interstitial is shown on an existing navigation entry, we'll need + // to remember its title so we can revert to it when hidden. + if (!new_navigation_ && !should_revert_tab_title_) { + original_tab_title_ = UTF16ToWideHack(entry->title()); + should_revert_tab_title_ = true; + } + entry->set_title(WideToUTF16Hack(title)); + tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); +} + +void InterstitialPage::DomOperationResponse(const std::string& json_string, + int automation_id) { + if (enabled_) + CommandReceived(json_string); +} + RenderViewHost* InterstitialPage::CreateRenderViewHost() { RenderViewHost* render_view_host = new RenderViewHost( SiteInstance::CreateSiteInstance(tab()->profile()), @@ -380,72 +450,6 @@ void InterstitialPage::FocusThroughTabTraversal(bool reverse) { render_view_host_->SetInitialFocus(reverse); } -void InterstitialPage::DidNavigate( - RenderViewHost* render_view_host, - const ViewHostMsg_FrameNavigate_Params& params) { - // A fast user could have navigated away from the page that triggered the - // interstitial while the interstitial was loading, that would have disabled - // us. In that case we can dismiss ourselves. - if (!enabled_){ - DontProceed(); - return; - } - - // The RenderViewHost has loaded its contents, we can show it now. - render_view_host_->view()->Show(); - tab_->set_interstitial_page(this); - - RenderWidgetHostView* rwh_view = tab_->render_view_host()->view(); - - // The RenderViewHost may already have crashed before we even get here. - if (rwh_view) { - // If the page has focus, focus the interstitial. - if (rwh_view->HasFocus()) - Focus(); - - // Hide the original RVH since we're showing the interstitial instead. - rwh_view->Hide(); - } - - // Notify the tab we are not loading so the throbber is stopped. It also - // causes a NOTIFY_LOAD_STOP notification, that the AutomationProvider (used - // by the UI tests) expects to consider a navigation as complete. Without - // this, navigating in a UI test to a URL that triggers an interstitial would - // hang. - tab_->SetIsLoading(false, NULL); -} - -void InterstitialPage::RenderViewGone(RenderViewHost* render_view_host) { - // Our renderer died. This should not happen in normal cases. - // Just dismiss the interstitial. - DontProceed(); -} - -void InterstitialPage::DomOperationResponse(const std::string& json_string, - int automation_id) { - if (enabled_) - CommandReceived(json_string); -} - -void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host, - int32 page_id, - const std::wstring& title) { - DCHECK(render_view_host == render_view_host_); - NavigationEntry* entry = tab_->controller().GetActiveEntry(); - // If this interstitial is shown on an existing navigation entry, we'll need - // to remember its title so we can revert to it when hidden. - if (!new_navigation_ && !should_revert_tab_title_) { - original_tab_title_ = UTF16ToWideHack(entry->title()); - should_revert_tab_title_ = true; - } - entry->set_title(WideToUTF16Hack(title)); - tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); -} - -RenderViewHostDelegate::View* InterstitialPage::GetViewDelegate() const { - return rvh_view_delegate_.get(); -} - void InterstitialPage::Disable() { enabled_ = false; } diff --git a/chrome/browser/tab_contents/interstitial_page.h b/chrome/browser/tab_contents/interstitial_page.h index 821171d..8ebfb51 100644 --- a/chrome/browser/tab_contents/interstitial_page.h +++ b/chrome/browser/tab_contents/interstitial_page.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ #define CHROME_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ +#include #include #include "base/gfx/size.h" @@ -91,29 +92,26 @@ class InterstitialPage : public NotificationObserver, const NotificationDetails& details); // RenderViewHostDelegate implementation: - virtual const GURL& GetURL() const { return url_; } - virtual WebPreferences GetWebkitPrefs() { - return WebPreferences(); - } + virtual View* GetViewDelegate() const; + virtual const GURL& GetURL() const; + virtual void RenderViewGone(RenderViewHost* render_view_host); virtual void DidNavigate(RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params); - virtual void RenderViewGone(RenderViewHost* render_view_host); - virtual void DomOperationResponse(const std::string& json_string, - int automation_id); virtual void UpdateTitle(RenderViewHost* render_view_host, int32 page_id, const std::wstring& title); - virtual View* GetViewDelegate() const; + virtual void DomOperationResponse(const std::string& json_string, + int automation_id); // Invoked when the page sent a command through DOMAutomation. - virtual void CommandReceived(const std::string& command) { } + virtual void CommandReceived(const std::string& command) {} // Invoked with the NavigationEntry that is going to be added to the // navigation controller. // Gives an opportunity to sub-classes to set states on the |entry|. // Note that this is only called if the InterstitialPage was constructed with // |create_navigation_entry| set to true. - virtual void UpdateEntry(NavigationEntry* entry) { } + virtual void UpdateEntry(NavigationEntry* entry) {} TabContents* tab() const { return tab_; } const GURL& url() const { return url_; } diff --git a/chrome/browser/tab_contents/navigation_controller_unittest.cc b/chrome/browser/tab_contents/navigation_controller_unittest.cc index 50964c7..8047216 100644 --- a/chrome/browser/tab_contents/navigation_controller_unittest.cc +++ b/chrome/browser/tab_contents/navigation_controller_unittest.cc @@ -8,7 +8,7 @@ #include "base/string_util.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/history/history.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/session_service_test_helper.h" #include "chrome/browser/sessions/session_types.h" diff --git a/chrome/browser/tab_contents/render_view_host_manager_unittest.cc b/chrome/browser/tab_contents/render_view_host_manager_unittest.cc index 01fb323..6cf549e 100644 --- a/chrome/browser/tab_contents/render_view_host_manager_unittest.cc +++ b/chrome/browser/tab_contents/render_view_host_manager_unittest.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/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/render_view_host_manager.h" diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 3b46d99..8141c42 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -50,6 +50,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" +#include "chrome/common/renderer_preferences.h" #include "chrome/common/url_constants.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -57,6 +58,8 @@ #include "net/base/net_errors.h" #include "net/base/net_util.h" #include "net/base/registry_controlled_domain.h" +#include "webkit/glue/password_form.h" +#include "webkit/glue/webpreferences.h" #if defined(OS_WIN) // For CRect @@ -1862,6 +1865,10 @@ void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer, } } +void TabContents::DomOperationResponse(const std::string& json_string, + int automation_id) { +} + void TabContents::ProcessDOMUIMessage(const std::string& message, const std::string& content, int request_id, @@ -2133,6 +2140,10 @@ void TabContents::OnCrossSiteResponse(int new_render_process_host_id, new_request_id); } +void TabContents::OnCrossSiteNavigationCanceled() { + render_manager_.CrossSiteNavigationCanceled(); +} + bool TabContents::CanBlur() const { return delegate() ? delegate()->CanBlur() : true; } @@ -2205,6 +2216,13 @@ void TabContents::OnUserGesture() { controller_.OnUserGesture(); } +bool TabContents::IsExternalTabContainer() const { + if (!delegate()) + return false; + + return delegate()->IsExternalTabContainer(); +} + void TabContents::OnFindReply(int request_id, int number_of_matches, const gfx::Rect& selection_rect, @@ -2236,11 +2254,8 @@ void TabContents::OnFindReply(int request_id, Details(&last_search_result_)); } -bool TabContents::IsExternalTabContainer() const { - if (!delegate()) - return false; - - return delegate()->IsExternalTabContainer(); +void TabContents::DidInsertCSS() { + // This RVHDelegate function is used for extensions and not us. } void TabContents::FileSelected(const FilePath& path, diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index f7d8f69..759c70a 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -34,7 +34,6 @@ #include "chrome/common/notification_registrar.h" #include "chrome/common/page_action.h" #include "chrome/common/property_bag.h" -#include "chrome/common/renderer_preferences.h" #include "net/base/load_states.h" #include "webkit/glue/password_form.h" #include "webkit/glue/webpreferences.h" @@ -78,6 +77,7 @@ class PageAction; class PasswordManager; class PluginInstaller; class Profile; +struct RendererPreferences; class RenderViewHost; class TabContentsDelegate; class TabContentsFactory; @@ -562,10 +562,6 @@ class TabContents : public PageNavigator, render_view_host()->SetPageEncoding(encoding); } - void CrossSiteNavigationCanceled() { - render_manager_.CrossSiteNavigationCanceled(); - } - void WindowMoveOrResizeStarted() { render_view_host()->WindowMoveOrResizeStarted(); } @@ -739,7 +735,6 @@ class TabContents : public PageNavigator, // RenderViewHostDelegate ---------------------------------------------------- - virtual RendererPreferences GetRendererPrefs() const; virtual RenderViewHostDelegate::View* GetViewDelegate() const; virtual RenderViewHostDelegate::Save* GetSaveDelegate() const; virtual TabContents* GetAsTabContents(); @@ -794,6 +789,8 @@ class TabContents : public PageNavigator, const SkBitmap& image); virtual void RequestOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition); + virtual void DomOperationResponse(const std::string& json_string, + int automation_id); virtual void ProcessDOMUIMessage(const std::string& message, const std::string& content, int request_id, @@ -831,14 +828,16 @@ class TabContents : public PageNavigator, virtual void DidGetPrintedPagesCount(int cookie, int number_pages); virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params); virtual GURL GetAlternateErrorPageURL() const; + virtual RendererPreferences GetRendererPrefs() const; virtual WebPreferences GetWebkitPrefs(); virtual void OnMissingPluginStatus(int status); virtual void OnCrashedPlugin(const FilePath& plugin_path); virtual void OnCrashedWorker(); virtual void OnJSOutOfMemory(); virtual void ShouldClosePage(bool proceed); - void OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id); + virtual void OnCrossSiteResponse(int new_render_process_host_id, + int new_request_id); + virtual void OnCrossSiteNavigationCanceled(); virtual bool CanBlur() const; virtual gfx::Rect GetRootWindowResizerRect() const; virtual void RendererUnresponsive(RenderViewHost* render_view_host, @@ -849,12 +848,13 @@ class TabContents : public PageNavigator, int32 page_id, const webkit_glue::WebApplicationInfo& info); virtual void OnUserGesture(); + virtual bool IsExternalTabContainer() const; virtual void OnFindReply(int request_id, int number_of_matches, const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update); - virtual bool IsExternalTabContainer() const; + virtual void DidInsertCSS(); // SelectFileDialog::Listener ------------------------------------------------ diff --git a/chrome/browser/tab_contents/test_web_contents.cc b/chrome/browser/tab_contents/test_web_contents.cc index bb5f4d06..f27aa9b 100644 --- a/chrome/browser/tab_contents/test_web_contents.cc +++ b/chrome/browser/tab_contents/test_web_contents.cc @@ -4,7 +4,7 @@ #include "chrome/browser/tab_contents/test_web_contents.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" TestTabContents::TestTabContents(Profile* profile, SiteInstance* instance) : TabContents(profile, instance, MSG_ROUTING_NONE, NULL), diff --git a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc index 591fdd0..160a377 100755 --- a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc +++ b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc @@ -5,7 +5,7 @@ #include "base/basictypes.h" #include "chrome/browser/renderer_host/backing_store_manager.h" #include "chrome/browser/renderer_host/mock_render_process_host.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/common/notification_service.h" #include "chrome/common/render_messages.h" diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc index 3b1c43e..bbdc7ef 100644 --- a/chrome/browser/tab_contents/web_contents_unittest.cc +++ b/chrome/browser/tab_contents/web_contents_unittest.cc @@ -5,7 +5,7 @@ #include "base/logging.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/tab_contents/interstitial_page.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc index 2db6626..0f74cc0 100644 --- a/chrome/browser/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_model_unittest.cc @@ -8,7 +8,7 @@ #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/profile.h" #include "chrome/browser/profile_manager.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" diff --git a/chrome/browser/visitedlink_unittest.cc b/chrome/browser/visitedlink_unittest.cc index 43be8e8..16ee644 100644 --- a/chrome/browser/visitedlink_unittest.cc +++ b/chrome/browser/visitedlink_unittest.cc @@ -15,7 +15,7 @@ #include "chrome/browser/visitedlink_master.h" #include "chrome/browser/visitedlink_event_listener.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/common/render_messages.h" #include "chrome/renderer/visitedlink_slave.h" #include "googleurl/src/gurl.h" diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index d60b966..9154f64 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -31,8 +31,8 @@ 'browser/views/find_bar_win_browsertest.cc', # TODO(jam): http://crbug.com/15101 These tests fail on Linux and Mac. 'browser/child_process_security_policy_browser_test.cc', - 'browser/renderer_host/web_cache_manager_browser_test.cc', - 'browser/renderer_host/render_view_host_manager_browsertest.cc', + 'browser/renderer_host/test/web_cache_manager_browsertest.cc', + 'browser/renderer_host/test/render_view_host_manager_browsertest.cc', # TODO(jcampan): once the task manager works on Mac, move this test to the # non win specific section. 'browser/task_manager_browsertest.cc', @@ -1333,6 +1333,7 @@ 'browser/renderer_host/render_sandbox_host_linux.cc', 'browser/renderer_host/render_view_host.cc', 'browser/renderer_host/render_view_host.h', + 'browser/renderer_host/render_view_host_delegate.cc', 'browser/renderer_host/render_view_host_delegate.h', 'browser/renderer_host/render_view_host_factory.cc', 'browser/renderer_host/render_view_host_factory.h', @@ -3039,8 +3040,8 @@ 'browser/automation/url_request_mock_net_error_job.h', 'browser/renderer_host/mock_render_process_host.cc', 'browser/renderer_host/mock_render_process_host.h', - 'browser/renderer_host/test_render_view_host.cc', - 'browser/renderer_host/test_render_view_host.h', + 'browser/renderer_host/test/test_render_view_host.cc', + 'browser/renderer_host/test/test_render_view_host.h', 'browser/tab_contents/test_web_contents.cc', 'browser/tab_contents/test_web_contents.h', 'common/ipc_test_sink.cc', @@ -3547,10 +3548,10 @@ 'browser/profile_manager_unittest.cc', 'browser/renderer_host/audio_renderer_host_unittest.cc', 'browser/renderer_host/file_system_accessor_unittest.cc', - 'browser/renderer_host/render_view_host_unittest.cc', 'browser/renderer_host/render_widget_host_unittest.cc', 'browser/renderer_host/resource_dispatcher_host_unittest.cc', - 'browser/renderer_host/site_instance_unittest.cc', + 'browser/renderer_host/test/render_view_host_unittest.cc', + 'browser/renderer_host/test/site_instance_unittest.cc', 'browser/renderer_host/web_cache_manager_unittest.cc', 'browser/rlz/rlz_unittest.cc', 'browser/safe_browsing/bloom_filter_unittest.cc', diff --git a/chrome/test/browser_with_test_window_test.h b/chrome/test/browser_with_test_window_test.h index 3e63685..835bdeb 100644 --- a/chrome/test/browser_with_test_window_test.h +++ b/chrome/test/browser_with_test_window_test.h @@ -8,7 +8,7 @@ #include #include "base/message_loop.h" -#include "chrome/browser/renderer_host/test_render_view_host.h" +#include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/test/test_browser_window.h" #include "testing/gtest/include/gtest/gtest.h" -- cgit v1.1