diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-15 10:51:23 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-15 10:51:23 +0000 |
commit | ac863a026dcce485a87698d0489c05e4c2baf889 (patch) | |
tree | 07b87bc3392dd64ce64dff9fef890b20c0d713f8 | |
parent | 060d4d8b30d19a4b5113ee4ceeefd49df0407967 (diff) | |
download | chromium_src-ac863a026dcce485a87698d0489c05e4c2baf889.zip chromium_src-ac863a026dcce485a87698d0489c05e4c2baf889.tar.gz chromium_src-ac863a026dcce485a87698d0489c05e4c2baf889.tar.bz2 |
DevTools: Add support for inspector layout tests. Step 3.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34544 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/devtools/js/devtools.js | 4 | ||||
-rw-r--r-- | webkit/tools/layout_tests/test_expectations.txt | 11 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.cc | 21 | ||||
-rw-r--r-- | webkit/tools/test_shell/layout_test_controller.h | 7 | ||||
-rw-r--r-- | webkit/tools/test_shell/resource.h | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/resources/test_shell.rc | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 39 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gyp | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.h | 22 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_devtools_agent.cc | 125 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_devtools_agent.h | 58 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_devtools_callargs.cc | 9 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_devtools_callargs.h | 43 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_devtools_client.cc | 97 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_devtools_client.h | 54 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_win.cc | 23 |
16 files changed, 512 insertions, 9 deletions
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index 5c80640..fea0a63 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -489,8 +489,8 @@ WebInspector.ElementsPanel.prototype._nodeSearchButtonClicked = function( WebInspector.runAfterPendingDispatchesQueue = []; -WebInspector.runAfterPendingDispatches = function(callback) { - this.runAfterPendingDispatchesQueue.push(callback); +WebInspector.TestController.prototype.runAfterPendingDispatches = function(callback) { + WebInspector.runAfterPendingDispatchesQueue.push(callback); }; WebInspector.queuesAreEmpty = function() { diff --git a/webkit/tools/layout_tests/test_expectations.txt b/webkit/tools/layout_tests/test_expectations.txt index b777fe3..da40d35 100644 --- a/webkit/tools/layout_tests/test_expectations.txt +++ b/webkit/tools/layout_tests/test_expectations.txt @@ -708,7 +708,16 @@ BUG20292 : LayoutTests/fast/forms/input-list.html = FAIL BUG20292 : LayoutTests/fast/forms/input-selectedoption.html = FAIL // Add support for inspector layout tests. -BUG26734 SKIP : LayoutTests/inspector = FAIL +BUG26734 LINUX MAC SKIP : LayoutTests/inspector = FAIL +BUG26734 SKIP : LayoutTests/inspector/console-dir.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/console-dirxml.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/console-format-collections.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/console-format.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/settings-set-get.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/styles-iframe.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/timeline-layout.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/timeline-paint.html = TEXT +BUG26734 SKIP : LayoutTests/inspector/timeline-recalculate-styles.html = TEXT // Fails due to storage APIs not implemented. Might be worth re-baselining // temporarily so the rest of the conditions are still tested. diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc index bdac11f..9ca297e 100644 --- a/webkit/tools/test_shell/layout_test_controller.cc +++ b/webkit/tools/test_shell/layout_test_controller.cc @@ -28,6 +28,7 @@ #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell.h" +#include "webkit/tools/test_shell/test_shell_devtools_agent.h" using std::string; using std::wstring; @@ -143,6 +144,8 @@ LayoutTestController::LayoutTestController(TestShell* shell) : BindMethod("evaluateScriptInIsolatedWorld", &LayoutTestController::evaluateScriptInIsolatedWorld); BindMethod("overridePreference", &LayoutTestController::overridePreference); BindMethod("setAllowUniversalAccessFromFileURLs", &LayoutTestController::setAllowUniversalAccessFromFileURLs); + BindMethod("setTimelineProfilingEnabled", &LayoutTestController::setTimelineProfilingEnabled); + BindMethod("evaluateInWebInspector", &LayoutTestController::evaluateInWebInspector); // The fallback method is called when an unknown method is invoked. BindFallbackMethod(&LayoutTestController::fallbackMethod); @@ -1030,3 +1033,21 @@ void LayoutTestController::LogErrorToConsole(const std::string& text) { WebString::fromUTF8(text)), WebString(), 0); } + +void LayoutTestController::setTimelineProfilingEnabled( + const CppArgumentList& args, CppVariant* result) { + result->SetNull(); + if (args.size() < 1 || !args[0].isBool()) + return; + shell_->dev_tools_agent()->setTimelineProfilingEnabled(args[0].ToBoolean()); +} + +void LayoutTestController::evaluateInWebInspector(const CppArgumentList& args, + CppVariant* result) { + result->SetNull(); + if (args.size() < 2 || !args[0].isInt32() || !args[1].isString()) + return; + shell_->dev_tools_agent()->evaluateInWebInspector(args[0].ToInt32(), + args[1].ToString()); +} + diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h index 8f5eedd..398a8e6 100644 --- a/webkit/tools/test_shell/layout_test_controller.h +++ b/webkit/tools/test_shell/layout_test_controller.h @@ -210,6 +210,13 @@ class LayoutTestController : public CppBoundClass { void counterValueForElementById( const CppArgumentList& args, CppVariant* result); + // Allows layout tests to start Timeline profiling. + void setTimelineProfilingEnabled(const CppArgumentList& args, + CppVariant* result); + + // Allows layout tests to exec scripts at WebInspector side. + void evaluateInWebInspector(const CppArgumentList& args, CppVariant* result); + public: // The following methods are not exposed to JavaScript. void SetWorkQueueFrozen(bool frozen) { work_queue_.set_frozen(frozen); } diff --git a/webkit/tools/test_shell/resource.h b/webkit/tools/test_shell/resource.h index 68dab93d..ca853dd 100644 --- a/webkit/tools/test_shell/resource.h +++ b/webkit/tools/test_shell/resource.h @@ -12,6 +12,7 @@ #define IDM_EXIT 105 #define IDM_DUMP_BODY_TEXT 110 #define IDM_DUMP_RENDER_TREE 111 +#define IDM_SHOW_DEV_TOOLS 112 #define IDI_TESTSHELL 107 #define IDI_SMALL 108 #define IDC_TESTSHELL 109 diff --git a/webkit/tools/test_shell/resources/test_shell.rc b/webkit/tools/test_shell/resources/test_shell.rc index 844c59b..68c2acc 100644 --- a/webkit/tools/test_shell/resources/test_shell.rc +++ b/webkit/tools/test_shell/resources/test_shell.rc @@ -46,6 +46,7 @@ BEGIN BEGIN MENUITEM "Dump body text...", IDM_DUMP_BODY_TEXT MENUITEM "Dump render tree...", IDM_DUMP_RENDER_TREE + MENUITEM "Show Developer Tools", IDM_SHOW_DEV_TOOLS END POPUP "&Help" BEGIN diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 74113d3..9793381 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -48,6 +48,8 @@ #include "webkit/tools/test_shell/accessibility_controller.h" #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" #include "webkit/tools/test_shell/test_navigation_controller.h" +#include "webkit/tools/test_shell/test_shell_devtools_agent.h" +#include "webkit/tools/test_shell/test_shell_devtools_client.h" #include "webkit/tools/test_shell/test_shell_switches.h" using WebKit::WebCanvas; @@ -100,6 +102,7 @@ class URLRequestTestShellFileJob : public URLRequestFileJob { // Initialize static member variable WindowList* TestShell::window_list_; WebPreferences* TestShell::web_prefs_ = NULL; +bool TestShell::inspector_test_mode_ = false; bool TestShell::layout_test_mode_ = false; int TestShell::file_test_timeout_ms_ = kDefaultFileTestTimeoutMillisecs; bool TestShell::test_is_preparing_ = false; @@ -146,6 +149,8 @@ TestShell::~TestShell() { // Destroy the WebView before the TestWebViewDelegate. m_webViewHost.reset(); + CloseDevTools(); + PlatformCleanUp(); StatsTable *table = StatsTable::current(); @@ -430,7 +435,8 @@ void TestShell::ResetWebPreferences() { web_prefs_->minimum_logical_font_size = 9; web_prefs_->javascript_can_open_windows_automatically = true; web_prefs_->dom_paste_enabled = true; - web_prefs_->developer_extras_enabled = !layout_test_mode_; + web_prefs_->developer_extras_enabled = !layout_test_mode_ || + inspector_test_mode_; web_prefs_->site_specific_quirks_enabled = true; web_prefs_->shrinks_standalone_images_to_fit = false; web_prefs_->uses_universal_detector = false; @@ -530,6 +536,37 @@ WebView* TestShell::CreateWebView() { return new_win->webView(); } +void TestShell::InitializeDevToolsAgent(WebView* webView) { + DCHECK(!dev_tools_agent_.get()); + dev_tools_agent_.reset(new TestShellDevToolsAgent(webView)); +} + +void TestShell::ShowDevTools() { + if (!devtools_shell_) { + FilePath dir_exe; + PathService::Get(base::DIR_EXE, &dir_exe); + FilePath devtools_path = + dir_exe.AppendASCII("resources/inspector/devtools.html"); + TestShell* devtools_shell; + TestShell::CreateNewWindow(GURL(devtools_path.value()), + &devtools_shell); + devtools_shell_ = devtools_shell->AsWeakPtr(); + devtools_shell_->CreateDevToolsClient(dev_tools_agent_.get()); + } + DCHECK(devtools_shell_); + devtools_shell_->Show(WebKit::WebNavigationPolicyNewWindow); +} + +void TestShell::CloseDevTools() { + if (devtools_shell_) + devtools_shell_->DestroyWindow(devtools_shell_->mainWnd()); +} + +void TestShell::CreateDevToolsClient(TestShellDevToolsAgent *agent) { + dev_tools_client_.reset(new TestShellDevToolsClient(agent, + webView())); +} + bool TestShell::IsSVGTestURL(const GURL& url) { return url.is_valid() && url.spec().find("W3C-SVG-1.1") != std::string::npos; } diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp index 532da24..9eeebd8 100644 --- a/webkit/tools/test_shell/test_shell.gyp +++ b/webkit/tools/test_shell/test_shell.gyp @@ -83,6 +83,12 @@ 'test_navigation_controller.h', 'test_shell.cc', 'test_shell.h', + 'test_shell_devtools_agent.cc', + 'test_shell_devtools_agent.h', + 'test_shell_devtools_callargs.cc', + 'test_shell_devtools_callargs.h', + 'test_shell_devtools_client.cc', + 'test_shell_devtools_client.h', 'test_shell_gtk.cc', 'test_shell_x11.cc', 'test_shell_mac.mm', diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index 9f5c124..3a8e4d7f 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -37,6 +37,7 @@ #include "base/lazy_instance.h" #endif #include "base/ref_counted.h" +#include "base/weak_ptr.h" #include "webkit/tools/test_shell/event_sending_controller.h" #include "webkit/tools/test_shell/layout_test_controller.h" #include "webkit/tools/test_shell/plain_text_controller.h" @@ -52,12 +53,14 @@ class AccessibilityController; class FilePath; class TestNavigationEntry; class TestNavigationController; +class TestShellDevToolsAgent; +class TestShellDevToolsClient; namespace base { class StringPiece; } -class TestShell { +class TestShell : public base::SupportsWeakPtr<TestShell> { public: struct TestParams { // Load the test defaults. @@ -104,6 +107,12 @@ public: } WebWidgetHost* popupHost() { return m_popupHost; } + // A new TestShell window will be opened with devtools url. + // DevTools window can be opened manually via menu or automatically when + // inspector's layout test url is passed from command line or console. + void ShowDevTools(); + void CloseDevTools(); + // Called by the LayoutTestController to signal test completion. void TestFinished(); @@ -286,8 +295,14 @@ public: // This is called indirectly by the network layer to access resources. static base::StringPiece NetResourceProvider(int key); + TestShellDevToolsAgent* dev_tools_agent() { + return dev_tools_agent_.get(); + } + protected: + void CreateDevToolsClient(TestShellDevToolsAgent* agent); bool Initialize(const GURL& starting_url); + void InitializeDevToolsAgent(WebKit::WebView* webView); bool IsSVGTestURL(const GURL& url); void SizeToSVG(); void SizeToDefault(); @@ -329,6 +344,7 @@ private: #endif // True when the app is being run using the --layout-tests switch. + static bool inspector_test_mode_; static bool layout_test_mode_; // Default timeout in ms for file page loads when in layout test mode. @@ -344,6 +360,10 @@ private: scoped_ptr<TestWebViewDelegate> delegate_; scoped_ptr<TestWebViewDelegate> popup_delegate_; + base::WeakPtr<TestShell> devtools_shell_; + scoped_ptr<TestShellDevToolsAgent> dev_tools_agent_; + scoped_ptr<TestShellDevToolsClient> dev_tools_client_; + const TestParams* test_params_; // True while a test is preparing to run diff --git a/webkit/tools/test_shell/test_shell_devtools_agent.cc b/webkit/tools/test_shell/test_shell_devtools_agent.cc new file mode 100644 index 0000000..75e2b3c --- /dev/null +++ b/webkit/tools/test_shell/test_shell_devtools_agent.cc @@ -0,0 +1,125 @@ +// 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 "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" +#include "third_party/WebKit/WebKit/chromium/src/WebViewImpl.h" + +#undef LOG +#include "webkit/tools/test_shell/test_shell_devtools_agent.h" +#include "webkit/tools/test_shell/test_shell_devtools_callargs.h" +#include "webkit/tools/test_shell/test_shell_devtools_client.h" + +#include "base/message_loop.h" +#include "webkit/glue/glue_util.h" + +using WebKit::WebDevToolsAgent; +using WebKit::WebDevToolsMessageData; +using WebKit::WebString; +using WebKit::WebView; +using WebKit::WebViewImpl; + +// static +void TestShellDevToolsAgent::DispatchMessageLoop() { + MessageLoop* current = MessageLoop::current(); + bool old_state = current->NestableTasksAllowed(); + current->SetNestableTasksAllowed(true); + current->RunAllPending(); + current->SetNestableTasksAllowed(old_state); +} + +// Warning at call_method_factory_(this) treated as error is switched off. + +#if defined(OS_WIN) +#pragma warning(disable : 4355) +#endif // defined(OS_WIN) + +TestShellDevToolsAgent::TestShellDevToolsAgent(WebView* web_view) + : call_method_factory_(this), + dev_tools_client_(NULL), + web_view_(static_cast<WebViewImpl*>(web_view)) { + static int dev_tools_agent_counter; + routing_id_ = ++dev_tools_agent_counter; + if (routing_id_ == 1) + WebDevToolsAgent::setMessageLoopDispatchHandler( + &TestShellDevToolsAgent::DispatchMessageLoop); + web_dev_tools_agent_ = WebDevToolsAgent::create(web_view_, this); + web_view_->setDevToolsAgent(web_dev_tools_agent_); +} + +void TestShellDevToolsAgent::sendMessageToFrontend( + const WebDevToolsMessageData& data) { + if (dev_tools_client_) + dev_tools_client_->AsyncCall(TestShellDevToolsCallArgs(data)); +} + +void TestShellDevToolsAgent::forceRepaint() { +} + +void TestShellDevToolsAgent::runtimeFeatureStateChanged( + const WebKit::WebString& feature, bool enabled) { + // TODO(loislo): implement this. +} + +void TestShellDevToolsAgent::AsyncCall(const TestShellDevToolsCallArgs &args) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + call_method_factory_.NewRunnableMethod(&TestShellDevToolsAgent::Call, + args), + 0); +} + +void TestShellDevToolsAgent::Call(const TestShellDevToolsCallArgs &args) { + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) + web_agent->dispatchMessageFromFrontend(args.data_); + if (TestShellDevToolsCallArgs::calls_count() == 1 && dev_tools_client_) + dev_tools_client_->all_messages_processed(); +} + +WebDevToolsAgent* TestShellDevToolsAgent::GetWebAgent() { + if (!web_view_) + return NULL; + return web_view_->devToolsAgent(); +} + +void TestShellDevToolsAgent::attach(TestShellDevToolsClient* client) { + DCHECK(!dev_tools_client_); + dev_tools_client_ = client; + WebDevToolsAgent *web_agent = GetWebAgent(); + if (web_agent) + web_agent->attach(); +} + +void TestShellDevToolsAgent::detach(TestShellDevToolsClient* client) { + DCHECK(dev_tools_client_); + WebDevToolsAgent* web_agent = GetWebAgent(); + if (web_agent) + web_agent->detach(); + dev_tools_client_ = NULL; +} + +bool TestShellDevToolsAgent::setTimelineProfilingEnabled(bool enabled) { + WebDevToolsAgent* agent = GetWebAgent(); + if (!agent) + return false; + agent->setTimelineProfilingEnabled(enabled); + return true; +} + +bool TestShellDevToolsAgent::evaluateInWebInspector( + long call_id, + const std::string& script) { + WebDevToolsAgent* agent = GetWebAgent(); + if (!agent) + return false; + agent->evaluateInWebInspector(call_id, + webkit_glue::StdStringToWebString(script)); + return true; +} + +// static +void WebKit::WebDevToolsAgentClient::sendMessageToFrontendOnIOThread( + WebKit::WebDevToolsMessageData const &) { + NOTIMPLEMENTED(); +} diff --git a/webkit/tools/test_shell/test_shell_devtools_agent.h b/webkit/tools/test_shell/test_shell_devtools_agent.h new file mode 100644 index 0000000..516ba14 --- /dev/null +++ b/webkit/tools/test_shell/test_shell_devtools_agent.h @@ -0,0 +1,58 @@ +// 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 TEST_SHELL_DEVTOOLS_AGENT_H_ +#define TEST_SHELL_DEVTOOLS_AGENT_H_ + +#include "base/task.h" + +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgentClient.h" + +namespace WebKit { + +class WebViewImpl; +struct WebDevToolsMessageData; + +} // namespace WebKit + +class TestShellDevToolsCallArgs; +class TestShellDevToolsClient; + +class TestShellDevToolsAgent : public WebKit::WebDevToolsAgentClient { + + public: + TestShellDevToolsAgent(WebKit::WebView* web_view); + virtual ~TestShellDevToolsAgent() {} + + // WebDevToolsAgentClient implementation. + virtual void sendMessageToFrontend( + const WebKit::WebDevToolsMessageData& data); + virtual int hostIdentifier() { return routing_id_; } + virtual void forceRepaint(); + virtual void runtimeFeatureStateChanged(const WebKit::WebString& feature, + bool enabled); + + void AsyncCall(const TestShellDevToolsCallArgs& args); + + void attach(TestShellDevToolsClient* client); + void detach(TestShellDevToolsClient* client); + + bool evaluateInWebInspector(long call_id, const std::string& script); + bool setTimelineProfilingEnabled(bool enable); + + private: + void Call(const TestShellDevToolsCallArgs& args); + static void DispatchMessageLoop(); + WebKit::WebDevToolsAgent* GetWebAgent(); + + ScopedRunnableMethodFactory<TestShellDevToolsAgent> call_method_factory_; + TestShellDevToolsClient* dev_tools_client_; + int routing_id_; + WebKit::WebDevToolsAgent* web_dev_tools_agent_; + WebKit::WebViewImpl* web_view_; + + DISALLOW_COPY_AND_ASSIGN(TestShellDevToolsAgent); +}; + +#endif // TEST_SHELL_DEVTOOLS_AGENT_H_ diff --git a/webkit/tools/test_shell/test_shell_devtools_callargs.cc b/webkit/tools/test_shell/test_shell_devtools_callargs.cc new file mode 100644 index 0000000..7c8e8b2 --- /dev/null +++ b/webkit/tools/test_shell/test_shell_devtools_callargs.cc @@ -0,0 +1,9 @@ +// 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 "webkit/tools/test_shell/test_shell_devtools_callargs.h" + +// static +int TestShellDevToolsCallArgs::calls_count_ = 0; + diff --git a/webkit/tools/test_shell/test_shell_devtools_callargs.h b/webkit/tools/test_shell/test_shell_devtools_callargs.h new file mode 100644 index 0000000..3fd7632 --- /dev/null +++ b/webkit/tools/test_shell/test_shell_devtools_callargs.h @@ -0,0 +1,43 @@ +// 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 TEST_SHELL_DEVTOOLS_CALLARGS_H_ +#define TEST_SHELL_DEVTOOLS_CALLARGS_H_ + +#include "base/logging.h" + +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsMessageData.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" + +class TestShellDevToolsCallArgs { + public: + TestShellDevToolsCallArgs(const WebKit::WebDevToolsMessageData& data) + : data_(data) { + ++calls_count_; + + // The same behaiviour as we have in case of IPC. + for (size_t i = 0; i < data_.arguments.size(); ++i) + if (data_.arguments[i].isNull()) + data_.arguments[i] = WebKit::WebString::fromUTF8(""); + } + + TestShellDevToolsCallArgs(const TestShellDevToolsCallArgs& args) + : data_(args.data_) { + ++calls_count_; + } + + ~TestShellDevToolsCallArgs() { + --calls_count_; + DCHECK(calls_count_ >= 0); + } + + static int calls_count() { return calls_count_; } + + WebKit::WebDevToolsMessageData data_; + + private: + static int calls_count_; +}; + +#endif // TEST_SHELL_DEVTOOLS_CALLARGS_H_ diff --git a/webkit/tools/test_shell/test_shell_devtools_client.cc b/webkit/tools/test_shell/test_shell_devtools_client.cc new file mode 100644 index 0000000..f1caaf7 --- /dev/null +++ b/webkit/tools/test_shell/test_shell_devtools_client.cc @@ -0,0 +1,97 @@ +// 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 "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsFrontend.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" +#include "third_party/WebKit/WebKit/chromium/public/WebView.h" + +#undef LOG +#include "webkit/tools/test_shell/test_shell_devtools_agent.h" +#include "webkit/tools/test_shell/test_shell_devtools_callargs.h" +#include "webkit/tools/test_shell/test_shell_devtools_client.h" + +#include "base/command_line.h" +#include "base/message_loop.h" + +using WebKit::WebDevToolsAgent; +using WebKit::WebDevToolsFrontend; +using WebKit::WebDevToolsMessageData; +using WebKit::WebString; +using WebKit::WebView; + +// Warning at call_method_factory_(this) treated as error and is switched off. + +#if defined(OS_WIN) +#pragma warning(disable : 4355) +#endif // defined(OS_WIN) + +TestShellDevToolsClient::TestShellDevToolsClient(TestShellDevToolsAgent *agent, + WebView* web_view) + : call_method_factory_(this), + dev_tools_agent_(agent), + web_view_(web_view) { + web_tools_frontend_.reset( + WebDevToolsFrontend::create(web_view_, + this, + WebString::fromUTF8("en-US"))); + dev_tools_agent_->attach(this); +} + +TestShellDevToolsClient::~TestShellDevToolsClient() { + // It is a chance that page will be destroyed at detach step of + // dev_tools_agent_ and we should clean pending requests a bit earlier. + call_method_factory_.RevokeAll(); + if (dev_tools_agent_) + dev_tools_agent_->detach(this); +} + +void TestShellDevToolsClient::sendMessageToAgent( + const WebDevToolsMessageData& data) { + if (dev_tools_agent_) + dev_tools_agent_->AsyncCall(TestShellDevToolsCallArgs(data)); +} + +void TestShellDevToolsClient::sendDebuggerCommandToAgent( + const WebString& command) { + WebDevToolsAgent::executeDebuggerCommand(command, 1); +} + +void TestShellDevToolsClient::activateWindow() { + NOTIMPLEMENTED(); +} + +void TestShellDevToolsClient::closeWindow() { + NOTIMPLEMENTED(); +} + +void TestShellDevToolsClient::dockWindow() { + NOTIMPLEMENTED(); +} + +void TestShellDevToolsClient::undockWindow() { + NOTIMPLEMENTED(); +} + +void TestShellDevToolsClient::AsyncCall(const TestShellDevToolsCallArgs &args) { + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + call_method_factory_.NewRunnableMethod(&TestShellDevToolsClient::Call, + args), + 0); +} + +void TestShellDevToolsClient::Call(const TestShellDevToolsCallArgs &args) { + web_tools_frontend_->dispatchMessageFromAgent(args.data_); + if (TestShellDevToolsCallArgs::calls_count() == 1) + all_messages_processed(); +} + +void TestShellDevToolsClient::all_messages_processed() { + web_view_->mainFrame()->executeScript( + WebKit::WebScriptSource(WebString::fromUTF8( + "if (window.WebInspector && WebInspector.queuesAreEmpty) WebInspector.queuesAreEmpty();"))); +} diff --git a/webkit/tools/test_shell/test_shell_devtools_client.h b/webkit/tools/test_shell/test_shell_devtools_client.h new file mode 100644 index 0000000..4663bca --- /dev/null +++ b/webkit/tools/test_shell/test_shell_devtools_client.h @@ -0,0 +1,54 @@ +// 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 TEST_SHELL_DEVTOOLS_CLIENT_H_ +#define TEST_SHELL_DEVTOOLS_CLIENT_H_ + +#include "base/scoped_ptr.h" +#include "base/task.h" + +#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsFrontendClient.h" + +namespace WebKit { + +class WebDevToolsFrontend; +struct WebDevToolsMessageData; + +} // namespace WebKit + +class TestShellDevToolsCallArgs; +class TestShellDevToolsAgent; + +class TestShellDevToolsClient: public WebKit::WebDevToolsFrontendClient { + + public: + TestShellDevToolsClient(TestShellDevToolsAgent* agent, + WebKit::WebView* web_view); + virtual ~TestShellDevToolsClient(); + + // WebDevToolsFrontendClient implementation + virtual void sendMessageToAgent(const WebKit::WebDevToolsMessageData& data); + virtual void sendDebuggerCommandToAgent(const WebKit::WebString& command); + + virtual void activateWindow(); + virtual void closeWindow(); + virtual void dockWindow(); + virtual void undockWindow(); + + void AsyncCall(const TestShellDevToolsCallArgs& args); + + void all_messages_processed(); + + private: + void Call(const TestShellDevToolsCallArgs& args); + + ScopedRunnableMethodFactory<TestShellDevToolsClient> call_method_factory_; + TestShellDevToolsAgent* dev_tools_agent_; + WebKit::WebView* web_view_; + scoped_ptr<WebKit::WebDevToolsFrontend> web_tools_frontend_; + + DISALLOW_COPY_AND_ASSIGN(TestShellDevToolsClient); +}; + +#endif // TEST_SHELL_DEVTOOLS_CLIENT_H_ diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index d038757..2de1695 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -252,6 +252,10 @@ bool TestShell::RunFileTest(const TestParams& params) { shell = static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); DCHECK(shell); + if (strstr(params.test_url.c_str(), "/inspector/") || + strstr(params.test_url.c_str(), "\\inspector\\")) + inspector_test_mode_ = true; + // Clean up state between test runs. webkit_glue::ResetBeforeTestRun(shell->webView()); ResetWebPreferences(); @@ -266,6 +270,9 @@ bool TestShell::RunFileTest(const TestParams& params) { strstr(params.test_url.c_str(), "loading\\")) shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true); + if (inspector_test_mode_) + shell->ShowDevTools(); + shell->test_is_preparing_ = true; shell->set_test_params(¶ms); shell->LoadURL(GURL(params.test_url)); @@ -274,7 +281,6 @@ bool TestShell::RunFileTest(const TestParams& params) { shell->WaitTestFinished(); shell->set_test_params(NULL); - return true; } @@ -361,6 +367,8 @@ bool TestShell::Initialize(const GURL& starting_url) { WebViewHost::Create(m_mainWnd, delegate_.get(), *TestShell::web_prefs_)); delegate_->RegisterDragDrop(); + InitializeDevToolsAgent(webView()); + // Load our initial content. if (starting_url.is_valid()) LoadURL(starting_url); @@ -557,19 +565,23 @@ LRESULT CALLBACK TestShell::WndProc(HWND hwnd, UINT message, WPARAM wParam, case IDM_DUMP_RENDER_TREE: shell->DumpRenderTree(); break; + case IDM_SHOW_DEV_TOOLS: + shell->ShowDevTools(); + break; } } break; case WM_DESTROY: { - // Dump all in use memory just before shutdown if in use memory - // debugging has been enabled. - base::MemoryDebug::DumpAllMemoryInUse(); RemoveWindowFromList(hwnd); if (TestShell::windowList()->empty() || shell->is_modal()) { + // Dump all in use memory just before shutdown if in use memory + // debugging has been enabled. + base::MemoryDebug::DumpAllMemoryInUse(); + MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } @@ -725,6 +737,9 @@ base::StringPiece GetDataResource(int resource_id) { case IDR_MEDIA_SOUND_DISABLED: case IDR_MEDIA_SLIDER_THUMB: case IDR_MEDIA_VOLUME_SLIDER_THUMB: + case IDR_DEVTOOLS_INJECT_WEBKIT_JS: + case IDR_DEVTOOLS_BASE_JS: + case IDR_DEVTOOLS_INJECT_DISPATCH_JS: return NetResourceProvider(resource_id); default: |