summaryrefslogtreecommitdiffstats
path: root/webkit/support
diff options
context:
space:
mode:
authorjcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 22:16:24 +0000
committerjcivelli@google.com <jcivelli@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 22:16:24 +0000
commitbb07d7a8169743e3992e9f5f0baa82a2aa4aa2dc (patch)
tree3d311e95a01257c5c45974c589ebe3be06a39b1c /webkit/support
parent4caa7300f49f5f0d30c8880bacf14a064fed51d5 (diff)
downloadchromium_src-bb07d7a8169743e3992e9f5f0baa82a2aa4aa2dc.zip
chromium_src-bb07d7a8169743e3992e9f5f0baa82a2aa4aa2dc.tar.gz
chromium_src-bb07d7a8169743e3992e9f5f0baa82a2aa4aa2dc.tar.bz2
Making webkit_support usable in WebKit unit-tests.
Adding a way to generate custom WebURLLoader (so unit-tests can mock resource loading). BUG=None TEST=DumpRenderTree should work. Review URL: http://codereview.chromium.org/2094017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/support')
-rw-r--r--webkit/support/test_webkit_client.cc8
-rw-r--r--webkit/support/test_webkit_client.h21
-rw-r--r--webkit/support/webkit_support.cc42
-rw-r--r--webkit/support/webkit_support.h8
4 files changed, 68 insertions, 11 deletions
diff --git a/webkit/support/test_webkit_client.cc b/webkit/support/test_webkit_client.cc
index 874717c..21648f0 100644
--- a/webkit/support/test_webkit_client.cc
+++ b/webkit/support/test_webkit_client.cc
@@ -51,7 +51,7 @@
using WebKit::WebScriptController;
-TestWebKitClient::TestWebKitClient() {
+TestWebKitClient::TestWebKitClient() : url_loader_factory_(NULL) {
v8::V8::SetCounterFunction(StatsTable::FindLocation);
WebKit::initialize(this);
@@ -193,6 +193,12 @@ WebKit::WebMessagePortChannel* TestWebKitClient::createMessagePortChannel() {
void TestWebKitClient::prefetchHostName(const WebKit::WebString&) {
}
+WebKit::WebURLLoader* TestWebKitClient::createURLLoader() {
+ if (url_loader_factory_)
+ return url_loader_factory_->createURLLoader();
+ return webkit_glue::WebKitClientImpl::createURLLoader();
+}
+
WebKit::WebData TestWebKitClient::loadResource(const char* name) {
if (!strcmp(name, "deleteButton")) {
// Create a red 30x30 square.
diff --git a/webkit/support/test_webkit_client.h b/webkit/support/test_webkit_client.h
index 3e106a9..7a2a052 100644
--- a/webkit/support/test_webkit_client.h
+++ b/webkit/support/test_webkit_client.h
@@ -13,6 +13,14 @@
#include "webkit/tools/test_shell/simple_webcookiejar_impl.h"
#include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h"
+class WebURLLoaderFactory {
+ public:
+ virtual WebKit::WebURLLoader* createURLLoader() = 0;
+
+ protected:
+ virtual ~WebURLLoaderFactory() {}
+};
+
// An implementation of WebKitClient for tests.
class TestWebKitClient : public webkit_glue::WebKitClientImpl {
public:
@@ -38,6 +46,7 @@ class TestWebKitClient : public webkit_glue::WebKitClientImpl {
virtual bool isLinkVisited(unsigned long long linkHash);
virtual WebKit::WebMessagePortChannel* createMessagePortChannel();
virtual void prefetchHostName(const WebKit::WebString&);
+ virtual WebKit::WebURLLoader* createURLLoader();
virtual WebKit::WebData loadResource(const char* name);
virtual WebKit::WebString defaultLocale();
virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
@@ -56,6 +65,13 @@ class TestWebKitClient : public webkit_glue::WebKitClientImpl {
virtual WebKit::WebSharedWorkerRepository* sharedWorkerRepository();
virtual WebKit::WebGraphicsContext3D* createGraphicsContext3D();
+ // Sets the factory used to create WebURLLoader instances.
+ // The caller owns the WebURLLoaderFactory and is responsible for calling this
+ // method again with NULL when it's done.
+ void set_url_loader_factory(WebURLLoaderFactory* url_loader_factory) {
+ url_loader_factory_ = url_loader_factory;
+ }
+
private:
TestShellWebMimeRegistryImpl mime_registry_;
MockWebClipboardImpl mock_clipboard_;
@@ -65,6 +81,11 @@ class TestWebKitClient : public webkit_glue::WebKitClientImpl {
SimpleDatabaseSystem database_system_;
SimpleWebCookieJarImpl cookie_jar_;
+ // Used to create WebURLLoader.
+ // If NULL, the class defers to webkit_glue::WebKitClientImpl for creating the
+ // WebURLLoader.
+ WebURLLoaderFactory* url_loader_factory_;
+
#if defined(OS_WIN)
WebKit::WebThemeEngine* active_theme_engine_;
#endif
diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc
index cab4ffa..de338ac 100644
--- a/webkit/support/webkit_support.cc
+++ b/webkit/support/webkit_support.cc
@@ -44,19 +44,24 @@ namespace {
class TestEnvironment {
public:
- explicit TestEnvironment() {}
+ explicit TestEnvironment(bool unit_test_mode) {
+ if (!unit_test_mode)
+ at_exit_manager_.reset(new base::AtExitManager);
+ main_message_loop_.reset(new MessageLoopForUI);
+ // TestWebKitClient must be instantiated after the MessageLoopForUI.
+ webkit_client_.reset(new TestWebKitClient);
+ }
~TestEnvironment() {
SimpleResourceLoaderBridge::Shutdown();
}
- WebKit::WebKitClient* webkit_client() { return &webkit_client_; }
+ WebKit::WebKitClient* webkit_client() { return webkit_client_.get(); }
private:
- base::AtExitManager at_exit_manager_;
- MessageLoopForUI main_message_loop_;
- // TestWebKitClient must be instantiated after the MessageLoopForUI.
- TestWebKitClient webkit_client_;
+ scoped_ptr<base::AtExitManager> at_exit_manager_;
+ scoped_ptr<MessageLoopForUI> main_message_loop_;
+ scoped_ptr<TestWebKitClient> webkit_client_;
};
class WebPluginImplWithPageDelegate
@@ -80,6 +85,10 @@ namespace webkit_support {
static TestEnvironment* test_environment;
void SetUpTestEnvironment() {
+ SetUpTestEnvironment(false);
+}
+
+void SetUpTestEnvironment(bool unit_test_mode) {
base::EnableTerminationOnHeapCorruption();
// Initialize the singleton CommandLine with fixed values. Some code refer to
@@ -94,11 +103,13 @@ void SetUpTestEnvironment() {
CommandLine::Init(arraysize(kFixedArguments), kFixedArguments);
BeforeInitialize();
- test_environment = new TestEnvironment;
+ test_environment = new TestEnvironment(unit_test_mode);
AfterInitialize();
- // Load ICU data tables. This has to run after TestEnvironment is created
- // because on Linux, we need base::AtExitManager.
- icu_util::Initialize();
+ if (!unit_test_mode) {
+ // Load ICU data tables. This has to run after TestEnvironment is created
+ // because on Linux, we need base::AtExitManager.
+ icu_util::Initialize();
+ }
}
void TearDownTestEnvironment() {
@@ -161,6 +172,17 @@ WebKit::WebApplicationCacheHost* CreateApplicationCacheHost(
return SimpleAppCacheSystem::CreateApplicationCacheHost(client);
}
+WebKit::WebString GetWebKitRootDir() {
+ FilePath sourcePath;
+ PathService::Get(base::DIR_SOURCE_ROOT, &sourcePath);
+ FilePath path = sourcePath.Append(FILE_PATH_LITERAL("third_party/WebKit"));
+ if (!file_util::PathExists(path)) {
+ path = sourcePath.Append(FILE_PATH_LITERAL("../.."));
+ DCHECK(file_util::PathExists(path));
+ }
+ return WebKit::WebString::fromUTF8(WideToUTF8(path.ToWStringHack()).c_str());
+}
+
// Wrapper for debug_util
bool BeingDebugged() {
return DebugUtil::BeingDebugged();
diff --git a/webkit/support/webkit_support.h b/webkit/support/webkit_support.h
index 16b0065..bfc87f0 100644
--- a/webkit/support/webkit_support.h
+++ b/webkit/support/webkit_support.h
@@ -31,9 +31,15 @@ struct WebPluginParams;
namespace webkit_support {
// Initializes or terminates a test environment.
+// |unit_test_mode| should be set to true when running in a TestSuite, in which
+// case no AtExitManager is created and ICU is not initialized (as it is already
+// done by the TestSuite).
// SetUpTestEnvironment() calls WebKit::initialize().
// TearDownTestEnvironment() calls WebKit::shutdown().
+// TODO(jcivelli): remove the next method once DumpRenderTree.cpp is not using
+// it anymore upstream.
void SetUpTestEnvironment();
+void SetUpTestEnvironment(bool unit_test_mode);
void TearDownTestEnvironment();
// Returns a pointer to a WebKitClient implementation for DumpRenderTree.
@@ -53,6 +59,8 @@ WebKit::WebMediaPlayer* CreateMediaPlayer(WebKit::WebFrame* frame,
WebKit::WebApplicationCacheHost* CreateApplicationCacheHost(
WebKit::WebFrame* frame, WebKit::WebApplicationCacheHostClient* client);
+// Returns the root directory of the WebKit code.
+WebKit::WebString GetWebKitRootDir();
// Wrappers to minimize dependecy.