diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-30 22:27:04 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-30 22:27:04 +0000 |
commit | 74830f079e4a4417c3a8c87cfd993b1cfaefadf8 (patch) | |
tree | ced0f3613c7e2449f8a32deaa6db3d763f69eb24 /content | |
parent | 130f02d464be38e03c259fc9f06be9c78596f9c5 (diff) | |
download | chromium_src-74830f079e4a4417c3a8c87cfd993b1cfaefadf8.zip chromium_src-74830f079e4a4417c3a8c87cfd993b1cfaefadf8.tar.gz chromium_src-74830f079e4a4417c3a8c87cfd993b1cfaefadf8.tar.bz2 |
First version of the layoutTestController for content_shell
This version supports dumpAsText, dumpChildFramesAsText, waitUntilDone, and
notifyDone
BUG=111316
TEST=run content_shell --dump-render-tree <some layout test that only uses above functions>
Review URL: http://codereview.chromium.org/9121074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/content_shell.gypi | 4 | ||||
-rw-r--r-- | content/shell/layout_test_controller.js | 19 | ||||
-rw-r--r-- | content/shell/layout_test_controller_bindings.cc | 107 | ||||
-rw-r--r-- | content/shell/layout_test_controller_bindings.h | 30 | ||||
-rw-r--r-- | content/shell/shell.cc | 13 | ||||
-rw-r--r-- | content/shell/shell.h | 9 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 4 | ||||
-rw-r--r-- | content/shell/shell_content_renderer_client.cc | 5 | ||||
-rw-r--r-- | content/shell/shell_content_renderer_client.h | 7 | ||||
-rw-r--r-- | content/shell/shell_main_delegate.cc | 1 | ||||
-rw-r--r-- | content/shell/shell_messages.h | 6 | ||||
-rw-r--r-- | content/shell/shell_render_process_observer.cc | 26 | ||||
-rw-r--r-- | content/shell/shell_render_process_observer.h | 29 | ||||
-rw-r--r-- | content/shell/shell_render_view_host_observer.cc | 30 | ||||
-rw-r--r-- | content/shell/shell_render_view_host_observer.h | 8 | ||||
-rw-r--r-- | content/shell/shell_resources.grd | 1 |
16 files changed, 297 insertions, 2 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 687bdf3..b8cdead 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -44,6 +44,8 @@ 'sources': [ 'browser/tab_contents/tab_contents_view_win.cc', 'browser/tab_contents/tab_contents_view_win.h', + 'shell/layout_test_controller_bindings.cc', + 'shell/layout_test_controller_bindings.h', 'shell/shell.cc', 'shell/shell.h', 'shell/shell_gtk.cc', @@ -71,6 +73,8 @@ 'shell/shell_main_delegate.h', 'shell/shell_messages.cc', 'shell/shell_messages.h', + 'shell/shell_render_process_observer.cc', + 'shell/shell_render_process_observer.h', 'shell/shell_render_view_host_observer.cc', 'shell/shell_render_view_host_observer.h', 'shell/shell_render_view_observer.cc', diff --git a/content/shell/layout_test_controller.js b/content/shell/layout_test_controller.js new file mode 100644 index 0000000..41cc8d4 --- /dev/null +++ b/content/shell/layout_test_controller.js @@ -0,0 +1,19 @@ +// Copyright (c) 2012 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. + +var layoutTestController = layoutTestController || {}; + +(function() { + native function NotifyDone(); + native function SetDumpAsText(); + native function SetDumpChildFramesAsText(); + native function SetWaitUntilDone(); + + layoutTestController = new function() { + this.notifyDone = NotifyDone; + this.dumpAsText = SetDumpAsText; + this.dumpChildFramesAsText = SetDumpChildFramesAsText; + this.waitUntilDone = SetWaitUntilDone; + }(); +})(); diff --git a/content/shell/layout_test_controller_bindings.cc b/content/shell/layout_test_controller_bindings.cc new file mode 100644 index 0000000..fae7b48 --- /dev/null +++ b/content/shell/layout_test_controller_bindings.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/shell/layout_test_controller_bindings.h" + +#include "base/string_piece.h" +#include "content/public/renderer/render_view.h" +#include "content/shell/shell_messages.h" +#include "grit/shell_resources.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" +#include "ui/base/resource/resource_bundle.h" + +using WebKit::WebFrame; +using WebKit::WebView; + +namespace content { + +namespace { + +base::StringPiece GetStringResource(int resource_id) { + return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); +} + +RenderView* GetCurrentRenderView() { + WebFrame* frame = WebFrame::frameForCurrentContext(); + DCHECK(frame); + if (!frame) + return NULL; + + WebView* view = frame->view(); + if (!view) + return NULL; // can happen during closing. + + RenderView* render_view = RenderView::FromWebView(view); + DCHECK(render_view); + return render_view; +} + +v8::Handle<v8::Value> NotifyDone(const v8::Arguments& args) { + RenderView* view = GetCurrentRenderView(); + if (!view) + return v8::Undefined(); + + view->Send(new ShellViewHostMsg_NotifyDone(view->GetRoutingId())); + return v8::Undefined(); +} + +v8::Handle<v8::Value> SetDumpAsText(const v8::Arguments& args) { + RenderView* view = GetCurrentRenderView(); + if (!view) + return v8::Undefined(); + + view->Send(new ShellViewHostMsg_DumpAsText(view->GetRoutingId())); + return v8::Undefined(); +} + +v8::Handle<v8::Value> SetDumpChildFramesAsText(const v8::Arguments& args) { + RenderView* view = GetCurrentRenderView(); + if (!view) + return v8::Undefined(); + + view->Send(new ShellViewHostMsg_DumpChildFramesAsText(view->GetRoutingId())); + return v8::Undefined(); +} + +v8::Handle<v8::Value> SetWaitUntilDone(const v8::Arguments& args) { + RenderView* view = GetCurrentRenderView(); + if (!view) + return v8::Undefined(); + + view->Send(new ShellViewHostMsg_WaitUntilDone(view->GetRoutingId())); + return v8::Undefined(); +} + +} // namespace + +LayoutTestControllerBindings::LayoutTestControllerBindings() + : v8::Extension("layout_test_controller.js", + GetStringResource( + IDR_CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_JS).data(), + 0, // num dependencies. + NULL, // dependencies array. + GetStringResource( + IDR_CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_JS).size()) { +} + +LayoutTestControllerBindings::~LayoutTestControllerBindings() { +} + +v8::Handle<v8::FunctionTemplate> +LayoutTestControllerBindings::GetNativeFunction(v8::Handle<v8::String> name) { + if (name->Equals(v8::String::New("NotifyDone"))) + return v8::FunctionTemplate::New(NotifyDone); + if (name->Equals(v8::String::New("SetDumpAsText"))) + return v8::FunctionTemplate::New(SetDumpAsText); + if (name->Equals(v8::String::New("SetDumpChildFramesAsText"))) + return v8::FunctionTemplate::New(SetDumpChildFramesAsText); + if (name->Equals(v8::String::New("SetWaitUntilDone"))) + return v8::FunctionTemplate::New(SetWaitUntilDone); + + NOTREACHED(); + return v8::FunctionTemplate::New(); +} + +} // namespace content diff --git a/content/shell/layout_test_controller_bindings.h b/content/shell/layout_test_controller_bindings.h new file mode 100644 index 0000000..9264ea1 --- /dev/null +++ b/content/shell/layout_test_controller_bindings.h @@ -0,0 +1,30 @@ +// Copyright (c) 2012 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 CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_BINDINGS_H_ +#define CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_BINDINGS_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "v8/include/v8.h" + +namespace content { + +class LayoutTestControllerBindings : public v8::Extension { + public: + LayoutTestControllerBindings(); + virtual ~LayoutTestControllerBindings(); + + // v8::Extension implementation. + virtual v8::Handle<v8::FunctionTemplate> + GetNativeFunction(v8::Handle<v8::String> name) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(LayoutTestControllerBindings); +}; + +} // namespace content + +#endif // CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_BINDINGS_H_ diff --git a/content/shell/shell.cc b/content/shell/shell.cc index 34e0e44..50e8c2b 100644 --- a/content/shell/shell.cc +++ b/content/shell/shell.cc @@ -25,6 +25,7 @@ std::vector<Shell*> Shell::windows_; Shell::Shell(TabContents* tab_contents) : WebContentsObserver(tab_contents), + wait_until_done_(false), window_(NULL), url_edit_view_(NULL) #if defined(OS_WIN) @@ -58,6 +59,16 @@ Shell* Shell::CreateShell(TabContents* tab_contents) { return shell; } +Shell* Shell::FromRenderViewHost(RenderViewHost* rvh) { + for (size_t i = 0; i < windows_.size(); ++i) { + if (windows_[i]->tab_contents() && + windows_[i]->tab_contents()->GetRenderViewHost() == rvh) { + return windows_[i]; + } + } + return NULL; +} + Shell* Shell::CreateNewWindow(content::BrowserContext* browser_context, const GURL& url, SiteInstance* site_instance, @@ -138,7 +149,7 @@ void Shell::UpdatePreferredSize(WebContents* source, void Shell::DidFinishLoad(int64 frame_id, const GURL& validated_url, bool is_main_frame) { - if (!is_main_frame) + if (!is_main_frame || wait_until_done_) return; if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) return; diff --git a/content/shell/shell.h b/content/shell/shell.h index bae8ef2..df1e8f7 100644 --- a/content/shell/shell.h +++ b/content/shell/shell.h @@ -55,11 +55,17 @@ class Shell : public WebContentsDelegate, int routing_id, TabContents* base_tab_contents); + // Returns the Shell object corresponding to the given RenderViewHost. + static Shell* FromRenderViewHost(RenderViewHost* rvh); + // Closes all windows and exits. static void PlatformExit(); TabContents* tab_contents() const { return tab_contents_.get(); } + // layoutTestController related methods. + void set_wait_until_done() { wait_until_done_ = true; } + #if defined(OS_MACOSX) // Public to be called by an ObjC bridge object. void ActionPerformed(int control); @@ -134,6 +140,9 @@ class Shell : public WebContentsDelegate, scoped_ptr<TabContents> tab_contents_; + // layoutTestController related variables. + bool wait_until_done_; + gfx::NativeWindow window_; gfx::NativeEditView url_edit_view_; diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 01296bb..98301f1 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -4,11 +4,13 @@ #include "content/shell/shell_content_browser_client.h" +#include "base/command_line.h" #include "base/file_path.h" #include "content/shell/shell.h" #include "content/shell/shell_browser_main.h" #include "content/shell/shell_devtools_delegate.h" #include "content/shell/shell_render_view_host_observer.h" +#include "content/shell/shell_switches.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" #include "webkit/glue/webpreferences.h" @@ -109,6 +111,8 @@ std::string ShellContentBrowserClient::GetCanonicalEncodingNameByAliasName( void ShellContentBrowserClient::AppendExtraCommandLineSwitches( CommandLine* command_line, int child_process_id) { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + command_line->AppendSwitch(switches::kDumpRenderTree); } std::string ShellContentBrowserClient::GetApplicationLocale() { diff --git a/content/shell/shell_content_renderer_client.cc b/content/shell/shell_content_renderer_client.cc index 0ec2adb..eeac11a 100644 --- a/content/shell/shell_content_renderer_client.cc +++ b/content/shell/shell_content_renderer_client.cc @@ -4,15 +4,20 @@ #include "content/shell/shell_content_renderer_client.h" +#include "content/shell/shell_render_process_observer.h" #include "content/shell/shell_render_view_observer.h" #include "v8/include/v8.h" namespace content { +ShellContentRendererClient::ShellContentRendererClient() { +} + ShellContentRendererClient::~ShellContentRendererClient() { } void ShellContentRendererClient::RenderThreadStarted() { + shell_observer_.reset(new ShellRenderProcessObserver()); } void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) { diff --git a/content/shell/shell_content_renderer_client.h b/content/shell/shell_content_renderer_client.h index eed6d0b..e34a4b4 100644 --- a/content/shell/shell_content_renderer_client.h +++ b/content/shell/shell_content_renderer_client.h @@ -7,12 +7,16 @@ #pragma once #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "content/public/renderer/content_renderer_client.h" namespace content { +class ShellRenderProcessObserver; + class ShellContentRendererClient : public ContentRendererClient { public: + ShellContentRendererClient(); virtual ~ShellContentRendererClient(); virtual void RenderThreadStarted() OVERRIDE; virtual void RenderViewCreated(RenderView* render_view) OVERRIDE; @@ -76,6 +80,9 @@ class ShellContentRendererClient : public ContentRendererClient { virtual void RegisterPPAPIInterfaceFactories( webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) OVERRIDE; virtual bool AllowSocketAPI(const GURL& url) OVERRIDE; + + private: + scoped_ptr<ShellRenderProcessObserver> shell_observer_; }; } // namespace content diff --git a/content/shell/shell_main_delegate.cc b/content/shell/shell_main_delegate.cc index 0544007..f914e8d 100644 --- a/content/shell/shell_main_delegate.cc +++ b/content/shell/shell_main_delegate.cc @@ -12,6 +12,7 @@ #include "content/shell/shell_content_plugin_client.h" #include "content/shell/shell_content_renderer_client.h" #include "content/shell/shell_content_utility_client.h" +#include "content/shell/shell_render_process_observer.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" diff --git a/content/shell/shell_messages.h b/content/shell/shell_messages.h index 5e3c741..3d86a47 100644 --- a/content/shell/shell_messages.h +++ b/content/shell/shell_messages.h @@ -17,3 +17,9 @@ IPC_MESSAGE_ROUTED1(ShellViewMsg_CaptureTextDump, // Send a text dump of the tab contents to the render host. IPC_MESSAGE_ROUTED1(ShellViewHostMsg_TextDump, std::string /* dump */) + +// The following messages correspond to methods of the layoutTestController. +IPC_MESSAGE_ROUTED0(ShellViewHostMsg_NotifyDone) +IPC_MESSAGE_ROUTED0(ShellViewHostMsg_DumpAsText) +IPC_MESSAGE_ROUTED0(ShellViewHostMsg_DumpChildFramesAsText) +IPC_MESSAGE_ROUTED0(ShellViewHostMsg_WaitUntilDone) diff --git a/content/shell/shell_render_process_observer.cc b/content/shell/shell_render_process_observer.cc new file mode 100644 index 0000000..a46f6f9 --- /dev/null +++ b/content/shell/shell_render_process_observer.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/shell/shell_render_process_observer.h" + +#include "base/command_line.h" +#include "content/public/renderer/render_thread.h" +#include "content/shell/layout_test_controller_bindings.h" +#include "content/shell/shell_switches.h" + +namespace content { + +ShellRenderProcessObserver::ShellRenderProcessObserver() { + RenderThread::Get()->AddObserver(this); +} + +ShellRenderProcessObserver::~ShellRenderProcessObserver() { +} + +void ShellRenderProcessObserver::WebKitInitialized() { + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) + RenderThread::Get()->RegisterExtension(new LayoutTestControllerBindings()); +} + +} // namespace content diff --git a/content/shell/shell_render_process_observer.h b/content/shell/shell_render_process_observer.h new file mode 100644 index 0000000..28e8d59 --- /dev/null +++ b/content/shell/shell_render_process_observer.h @@ -0,0 +1,29 @@ +// Copyright (c) 2012 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 CONTENT_SHELL_SHELL_RENDER_PROCESS_OBSERVER_H_ +#define CONTENT_SHELL_SHELL_RENDER_PROCESS_OBSERVER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/public/renderer/render_process_observer.h" + +namespace content { + +class ShellRenderProcessObserver : public RenderProcessObserver { + public: + ShellRenderProcessObserver(); + virtual ~ShellRenderProcessObserver(); + + // RenderProcessObserver implementation. + virtual void WebKitInitialized() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(ShellRenderProcessObserver); +}; + +} // namespace content + +#endif // CONTENT_SHELL_SHELL_RENDER_PROCESS_OBSERVER_H_ diff --git a/content/shell/shell_render_view_host_observer.cc b/content/shell/shell_render_view_host_observer.cc index f613851..ff92aab 100644 --- a/content/shell/shell_render_view_host_observer.cc +++ b/content/shell/shell_render_view_host_observer.cc @@ -6,13 +6,17 @@ #include <iostream> +#include "base/message_loop.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/shell/shell.h" #include "content/shell/shell_messages.h" namespace content { ShellRenderViewHostObserver::ShellRenderViewHostObserver( RenderViewHost* render_view_host) - : RenderViewHostObserver(render_view_host) { + : RenderViewHostObserver(render_view_host), + dump_child_frames_(false) { } ShellRenderViewHostObserver::~ShellRenderViewHostObserver() { @@ -23,6 +27,11 @@ bool ShellRenderViewHostObserver::OnMessageReceived( bool handled = true; IPC_BEGIN_MESSAGE_MAP(ShellRenderViewHostObserver, message) IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_NotifyDone, OnNotifyDone) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpAsText, OnDumpAsText) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_DumpChildFramesAsText, + OnDumpChildFramesAsText) + IPC_MESSAGE_HANDLER(ShellViewHostMsg_WaitUntilDone, OnWaitUntilDone) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -30,6 +39,25 @@ bool ShellRenderViewHostObserver::OnMessageReceived( void ShellRenderViewHostObserver::OnTextDump(const std::string& dump) { std::cout << dump; + MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); +} + +void ShellRenderViewHostObserver::OnNotifyDone() { + render_view_host()->Send( + new ShellViewMsg_CaptureTextDump(render_view_host()->routing_id(), + dump_child_frames_)); +} + +void ShellRenderViewHostObserver::OnDumpAsText() { +} + +void ShellRenderViewHostObserver::OnDumpChildFramesAsText() { + dump_child_frames_ = true; +} + +void ShellRenderViewHostObserver::OnWaitUntilDone() { + Shell* shell = Shell::FromRenderViewHost(render_view_host()); + shell->set_wait_until_done(); } } // namespace content diff --git a/content/shell/shell_render_view_host_observer.h b/content/shell/shell_render_view_host_observer.h index f1ba449..c234a1d 100644 --- a/content/shell/shell_render_view_host_observer.h +++ b/content/shell/shell_render_view_host_observer.h @@ -24,6 +24,14 @@ class ShellRenderViewHostObserver : public RenderViewHostObserver { // Message handlers. void OnTextDump(const std::string& dump); + // layoutTestController handlers. + void OnNotifyDone(); + void OnDumpAsText(); + void OnDumpChildFramesAsText(); + void OnWaitUntilDone(); + + bool dump_child_frames_; + DISALLOW_COPY_AND_ASSIGN(ShellRenderViewHostObserver); }; diff --git a/content/shell/shell_resources.grd b/content/shell/shell_resources.grd index e7ee1e9..dac1d66 100644 --- a/content/shell/shell_resources.grd +++ b/content/shell/shell_resources.grd @@ -11,6 +11,7 @@ <release seq="1"> <includes> <include name="IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE" file="shell_devtools_discovery_page.html" type="BINDATA" /> + <include name="IDR_CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_JS" file="layout_test_controller.js" type="BINDATA" /> </includes> </release> </grit> |