diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-30 14:42:55 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-30 14:42:55 +0000 |
commit | 2244953ad06709674663e182abf61f17d94698b1 (patch) | |
tree | bd8d2f1bc8c2645a1df43b12958d3484e3e832f6 | |
parent | 18d2fd4eaf00e7f09bcce4c2b96c07e624e736ee (diff) | |
download | chromium_src-2244953ad06709674663e182abf61f17d94698b1.zip chromium_src-2244953ad06709674663e182abf61f17d94698b1.tar.gz chromium_src-2244953ad06709674663e182abf61f17d94698b1.tar.bz2 |
[content shell] add support for testRunner.canOpenWindows and disallow opening windows per default for layout tests
BUG=111316
R=marja@chromium.org
Review URL: https://codereview.chromium.org/11411282
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170451 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 13 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.h | 7 | ||||
-rw-r--r-- | content/shell/shell_messages.h | 1 | ||||
-rw-r--r-- | content/shell/webkit_test_runner.js | 4 | ||||
-rw-r--r-- | content/shell/webkit_test_runner_bindings.cc | 11 | ||||
-rw-r--r-- | content/shell/webkit_test_runner_host.cc | 6 | ||||
-rw-r--r-- | content/shell/webkit_test_runner_host.h | 6 |
7 files changed, 48 insertions, 0 deletions
diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 4019199..e806f36 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -121,6 +121,19 @@ WebContentsViewDelegate* ShellContentBrowserClient::GetWebContentsViewDelegate( return NULL; } +bool ShellContentBrowserClient::CanCreateWindow( + const GURL& opener_url, + const GURL& origin, + WindowContainerType container_type, + ResourceContext* context, + int render_process_id, + bool* no_javascript_access) { + *no_javascript_access = false; + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + return true; + return WebKitTestController::Get()->can_open_windows(); +} + #if defined(OS_ANDROID) void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( const CommandLine& command_line, diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index 06f6516..7d72e75 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -39,6 +39,13 @@ class ShellContentBrowserClient : public ContentBrowserClient { virtual std::string GetDefaultDownloadName() OVERRIDE; virtual WebContentsViewDelegate* GetWebContentsViewDelegate( WebContents* web_contents) OVERRIDE; + virtual bool CanCreateWindow( + const GURL& opener_url, + const GURL& source_origin, + WindowContainerType container_type, + ResourceContext* context, + int render_process_id, + bool* no_javascript_access) OVERRIDE; #if defined(OS_ANDROID) virtual void GetAdditionalMappedFilesForChildProcess( diff --git a/content/shell/shell_messages.h b/content/shell/shell_messages.h index d9df4bc..49d2738 100644 --- a/content/shell/shell_messages.h +++ b/content/shell/shell_messages.h @@ -69,6 +69,7 @@ IPC_MESSAGE_ROUTED1( IPC_MESSAGE_ROUTED0(ShellViewHostMsg_WaitUntilDone) IPC_MESSAGE_ROUTED1(ShellViewHostMsg_OverridePreferences, content::ShellWebPreferences /* preferences */) +IPC_MESSAGE_ROUTED0(ShellViewHostMsg_CanOpenWindows) IPC_MESSAGE_ROUTED2(ShellViewHostMsg_NotImplemented, std::string /* object_name */, diff --git a/content/shell/webkit_test_runner.js b/content/shell/webkit_test_runner.js index 1cfe81d..7665a90 100644 --- a/content/shell/webkit_test_runner.js +++ b/content/shell/webkit_test_runner.js @@ -8,6 +8,7 @@ var testRunner = testRunner || {}; native function Display(); native function GetWorkerThreadCount(); native function NotifyDone(); + native function SetCanOpenWindows(); native function SetDumpAsText(); native function SetDumpChildFramesAsText(); native function SetPrinting(); @@ -41,6 +42,9 @@ var testRunner = testRunner || {}; Object.defineProperty(this, "dumpChildFramesAsText", {value: SetDumpChildFramesAsText}); + Object.defineProperty(this, + "setCanOpenWindows", + {value: SetCanOpenWindows}); Object.defineProperty(this, "setPrinting", {value: SetPrinting}); Object.defineProperty( this, diff --git a/content/shell/webkit_test_runner_bindings.cc b/content/shell/webkit_test_runner_bindings.cc index 4e4f597..3e1878f9 100644 --- a/content/shell/webkit_test_runner_bindings.cc +++ b/content/shell/webkit_test_runner_bindings.cc @@ -62,6 +62,15 @@ v8::Handle<v8::Value> NotifyDone(const v8::Arguments& args) { return v8::Undefined(); } +v8::Handle<v8::Value> SetCanOpenWindows(const v8::Arguments& args) { + RenderView* view = GetCurrentRenderView(); + if (!view) + return v8::Undefined(); + + view->Send(new ShellViewHostMsg_CanOpenWindows(view->GetRoutingID())); + return v8::Undefined(); +} + v8::Handle<v8::Value> SetDumpAsText(const v8::Arguments& args) { RenderView* view = GetCurrentRenderView(); if (!view) @@ -173,6 +182,8 @@ WebKitTestRunnerBindings::GetNativeFunction(v8::Handle<v8::String> name) { return v8::FunctionTemplate::New(Display); if (name->Equals(v8::String::New("NotifyDone"))) return v8::FunctionTemplate::New(NotifyDone); + if (name->Equals(v8::String::New("SetCanOpenWindows"))) + return v8::FunctionTemplate::New(SetCanOpenWindows); if (name->Equals(v8::String::New("SetDumpAsText"))) return v8::FunctionTemplate::New(SetDumpAsText); if (name->Equals(v8::String::New("SetDumpChildFramesAsText"))) diff --git a/content/shell/webkit_test_runner_host.cc b/content/shell/webkit_test_runner_host.cc index 5eef32d..6935f69 100644 --- a/content/shell/webkit_test_runner_host.cc +++ b/content/shell/webkit_test_runner_host.cc @@ -181,6 +181,7 @@ bool WebKitTestController::ResetAfterLayoutTest() { should_stay_on_page_after_handling_before_unload_ = false; wait_until_done_ = false; prefs_ = ShellWebPreferences(); + can_open_windows_ = false; watchdog_.Cancel(); if (main_window_) { Observe(NULL); @@ -380,6 +381,7 @@ bool WebKitTestRunnerHost::OnMessageReceived( OnSetShouldStayOnPageAfterHandlingBeforeUnload) IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone) IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotImplemented, OnNotImplemented) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_CanOpenWindows, OnCanOpenWindows) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -419,4 +421,8 @@ void WebKitTestRunnerHost::OnNotImplemented( WebKitTestController::Get()->NotImplemented(object_name, property_name); } +void WebKitTestRunnerHost::OnCanOpenWindows() { + WebKitTestController::Get()->set_can_open_windows(true); +} + } // namespace content diff --git a/content/shell/webkit_test_runner_host.h b/content/shell/webkit_test_runner_host.h index 596a910..ed48439 100644 --- a/content/shell/webkit_test_runner_host.h +++ b/content/shell/webkit_test_runner_host.h @@ -109,6 +109,10 @@ class WebKitTestController : public base::NonThreadSafe, } bool is_printing() const { return is_printing_; } void set_is_printing(bool is_printing) { is_printing_ = is_printing; } + bool can_open_windows() const { return can_open_windows_; } + void set_can_open_windows(bool can_open_windows) { + can_open_windows_ = can_open_windows; + } // WebContentsObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; @@ -146,6 +150,7 @@ class WebKitTestController : public base::NonThreadSafe, bool is_printing_; bool should_stay_on_page_after_handling_before_unload_; bool wait_until_done_; + bool can_open_windows_; ShellWebPreferences prefs_; base::CancelableClosure watchdog_; @@ -169,6 +174,7 @@ class WebKitTestRunnerHost : public RenderViewHostObserver { void OnSetPrinting(); void OnSetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page); void OnWaitUntilDone(); + void OnCanOpenWindows(); void OnNotImplemented(const std::string& object_name, const std::string& method_name); |