summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/shell/shell_content_renderer_client.cc30
-rw-r--r--content/shell/shell_messages.h5
-rw-r--r--content/shell/webkit_test_controller.cc6
-rw-r--r--content/shell/webkit_test_controller.h1
-rw-r--r--content/shell/webkit_test_runner.cc51
-rw-r--r--content/shell/webkit_test_runner.h2
6 files changed, 65 insertions, 30 deletions
diff --git a/content/shell/shell_content_renderer_client.cc b/content/shell/shell_content_renderer_client.cc
index ad67d49..8fff64a 100644
--- a/content/shell/shell_content_renderer_client.cc
+++ b/content/shell/shell_content_renderer_client.cc
@@ -6,8 +6,6 @@
#include "base/callback.h"
#include "base/command_line.h"
-#include "base/sys_string_conversions.h"
-#include "base/utf_string_conversions.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
@@ -93,14 +91,17 @@ bool ShellContentRendererClient::WillSendRequest(
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switches::kDumpRenderTree))
return false;
+ ShellRenderProcessObserver* render_process_observer =
+ ShellRenderProcessObserver::GetInstance();
if (!command_line->HasSwitch(switches::kAllowExternalPages) &&
IsExternalPage(url) && !IsExternalPage(first_party_for_cookies)) {
- ShellRenderProcessObserver::GetInstance()->test_delegate()->printMessage(
+ render_process_observer->test_delegate()->printMessage(
std::string("Blocked access to external URL " + url.spec() + "\n"));
*new_url = GURL();
return true;
}
- *new_url = RewriteLayoutTestsURL(url);
+ *new_url = render_process_observer->test_delegate()->rewriteLayoutTestsURL(
+ url.spec());
return true;
}
@@ -119,25 +120,4 @@ void ShellContentRendererClient::WebTestProxyCreated(RenderView* render_view,
ShellRenderProcessObserver::GetInstance()->test_interfaces());
}
-GURL ShellContentRendererClient::RewriteLayoutTestsURL(const GURL& url) {
- const char kPrefix[] = "file:///tmp/LayoutTests/";
- const int kPrefixLen = arraysize(kPrefix) - 1;
-
- if (url.spec().compare(0, kPrefixLen, kPrefix, kPrefixLen))
- return url;
-
- FilePath replace_path =
- ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
- FILE_PATH_LITERAL("LayoutTests/"));
-#if defined(OS_WIN)
- std::string utf8_path = WideToUTF8(replace_path.value());
-#else
- std::string utf8_path =
- WideToUTF8(base::SysNativeMBToWide(replace_path.value()));
-#endif
- std::string new_url =
- std::string("file://") + utf8_path + url.spec().substr(kPrefixLen);
- return GURL(new_url);
-}
-
} // namespace content
diff --git a/content/shell/shell_messages.h b/content/shell/shell_messages.h
index 72114f0..08cc391 100644
--- a/content/shell/shell_messages.h
+++ b/content/shell/shell_messages.h
@@ -59,6 +59,11 @@ IPC_MESSAGE_ROUTED0(ShellViewHostMsg_DidFinishLoad)
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_PrintMessage,
std::string /* message */)
+// Read a file and returns its contents.
+IPC_SYNC_MESSAGE_ROUTED1_1(ShellViewHostMsg_ReadFileToString,
+ FilePath /* local path */,
+ std::string /* contents */)
+
// The following messages correspond to methods of the testRunner.
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_NotifyDone)
IPC_MESSAGE_ROUTED0(ShellViewHostMsg_DumpAsText)
diff --git a/content/shell/webkit_test_controller.cc b/content/shell/webkit_test_controller.cc
index 858e0d9..3f6fa90 100644
--- a/content/shell/webkit_test_controller.cc
+++ b/content/shell/webkit_test_controller.cc
@@ -219,6 +219,7 @@ bool WebKitTestController::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(WebKitTestController, message)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_DidFinishLoad, OnDidFinishLoad)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_PrintMessage, OnPrintMessage)
+ IPC_MESSAGE_HANDLER(ShellViewHostMsg_ReadFileToString, OnReadFileToString)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_RegisterIsolatedFileSystem,
OnRegisterIsolatedFileSystem)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_TextDump, OnTextDump)
@@ -360,6 +361,11 @@ void WebKitTestController::OnPrintMessage(const std::string& message) {
printer_->AddMessageRaw(message);
}
+void WebKitTestController::OnReadFileToString(const FilePath& local_file,
+ std::string* contents) {
+ file_util::ReadFileToString(local_file, contents);
+}
+
void WebKitTestController::OnOverridePreferences(
const ShellWebPreferences& prefs) {
*prefs_.get() = prefs;
diff --git a/content/shell/webkit_test_controller.h b/content/shell/webkit_test_controller.h
index 54f77dd..9d83849 100644
--- a/content/shell/webkit_test_controller.h
+++ b/content/shell/webkit_test_controller.h
@@ -113,6 +113,7 @@ class WebKitTestController : public base::NonThreadSafe,
void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image);
void OnTextDump(const std::string& dump);
void OnPrintMessage(const std::string& message);
+ void OnReadFileToString(const FilePath& file_path, std::string* contents);
void OnOverridePreferences(const ShellWebPreferences& prefs);
void OnNotifyDone();
void OnDumpAsText();
diff --git a/content/shell/webkit_test_runner.cc b/content/shell/webkit_test_runner.cc
index 20a06c7..69210e6 100644
--- a/content/shell/webkit_test_runner.cc
+++ b/content/shell/webkit_test_runner.cc
@@ -6,6 +6,7 @@
#include <cmath>
+#include "base/base64.h"
#include "base/md5.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
@@ -19,11 +20,6 @@
#include "content/shell/shell_render_process_observer.h"
#include "net/base/net_util.h"
#include "skia/ext/platform_canvas.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
@@ -31,6 +27,12 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatformSupport.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h"
#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h"
#include "webkit/base/file_path_string_conversions.h"
@@ -45,6 +47,7 @@ using WebKit::WebGamepads;
using WebKit::WebRect;
using WebKit::WebSize;
using WebKit::WebString;
+using WebKit::WebURL;
using WebKit::WebVector;
using WebKit::WebView;
using WebTestRunner::WebPreferences;
@@ -236,6 +239,44 @@ WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path(
return webkit_base::FilePathToWebString(path);
}
+WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) {
+ FilePath local_path;
+ if (!net::FileURLToFilePath(file_url, &local_path))
+ return WebURL();
+
+ std::string contents;
+ Send(new ShellViewHostMsg_ReadFileToString(
+ routing_id(), local_path, &contents));
+
+ std::string contents_base64;
+ if (!base::Base64Encode(contents, &contents_base64))
+ return WebURL();
+
+ const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,";
+ return WebURL(GURL(data_url_prefix + contents_base64));
+}
+
+WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) {
+ const char kPrefix[] = "file:///tmp/LayoutTests/";
+ const int kPrefixLen = arraysize(kPrefix) - 1;
+
+ if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen))
+ return WebURL(GURL(utf8_url));
+
+ FilePath replace_path =
+ ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
+ FILE_PATH_LITERAL("LayoutTests/"));
+#if defined(OS_WIN)
+ std::string utf8_path = WideToUTF8(replace_path.value());
+#else
+ std::string utf8_path =
+ WideToUTF8(base::SysNativeMBToWide(replace_path.value()));
+#endif
+ std::string new_url =
+ std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen);
+ return WebURL(GURL(new_url));
+}
+
WebPreferences* WebKitTestRunner::preferences() {
return &prefs_;
}
diff --git a/content/shell/webkit_test_runner.h b/content/shell/webkit_test_runner.h
index b7e731c..6947bd3 100644
--- a/content/shell/webkit_test_runner.h
+++ b/content/shell/webkit_test_runner.h
@@ -57,6 +57,8 @@ class WebKitTestRunner : public RenderViewObserver,
virtual long long getCurrentTimeInMillisecond();
virtual WebKit::WebString getAbsoluteWebStringFromUTF8Path(
const std::string& utf8_path);
+ virtual WebKit::WebURL localFileToDataURL(const WebKit::WebURL& file_url);
+ virtual WebKit::WebURL rewriteLayoutTestsURL(const std::string& utf8_url);
virtual WebTestRunner::WebPreferences* preferences();
virtual void applyPreferences();