summaryrefslogtreecommitdiff
path: root/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-02-03 09:55:33 +0100
committerSimon Hausmann <simon.hausmann@nokia.com>2012-02-03 09:55:33 +0100
commitcd44dc59cdfc39534aef4d417e9f3c412e3be139 (patch)
tree8d89889ba95ed6ec9322e733846cc9cce9d7dff1 /Tools/DumpRenderTree/gtk/DumpRenderTree.cpp
parentd11f84f5b5cdc0d92a08af01b13472fdd5f9acb9 (diff)
downloadqtwebkit-cd44dc59cdfc39534aef4d417e9f3c412e3be139.tar.gz
Imported WebKit commit fce473cb4d55aa9fe9d0b0322a2fffecb731b961 (http://svn.webkit.org/repository/webkit/trunk@106560)
Diffstat (limited to 'Tools/DumpRenderTree/gtk/DumpRenderTree.cpp')
-rw-r--r--Tools/DumpRenderTree/gtk/DumpRenderTree.cpp208
1 files changed, 195 insertions, 13 deletions
diff --git a/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp b/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp
index d6bb426f2..2ecf1df23 100644
--- a/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp
+++ b/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp
@@ -76,6 +76,7 @@ volatile bool done;
static bool printSeparators;
static int dumpPixels;
static int dumpTree = 1;
+static int useTimeoutWatchdog = 1;
AccessibilityController* axController = 0;
RefPtr<LayoutTestController> gLayoutTestController;
@@ -169,16 +170,10 @@ static void initializeGtkFontSettings(const char* testURL)
CString getTopLevelPath()
{
- if (const char* topLevelDirectory = g_getenv("WEBKIT_TOP_LEVEL"))
- return topLevelDirectory;
+ if (!g_getenv("WEBKIT_TOP_LEVEL"))
+ g_setenv("WEBKIT_TOP_LEVEL", TOP_LEVEL_DIR, FALSE);
- // If the environment variable wasn't provided then assume we were built into
- // WebKitBuild/Debug or WebKitBuild/Release. Obviously this will fail if the build
- // directory is non-standard, but we can't do much more about this.
- GOwnPtr<char> parentPath(g_path_get_dirname(getCurrentExecutablePath().data()));
- GOwnPtr<char> layoutTestsPath(g_build_filename(parentPath.get(), "..", "..", "..", NULL));
- GOwnPtr<char> absoluteTopLevelPath(realpath(layoutTestsPath.get(), 0));
- return absoluteTopLevelPath.get();
+ return TOP_LEVEL_DIR;
}
static void initializeFonts(const char* testURL = 0)
@@ -374,6 +369,16 @@ static void dumpBackForwardListForAllWebViews()
dumpBackForwardListForWebView(WEBKIT_WEB_VIEW(currentView->data));
}
+void setWaitToDumpWatchdog(guint timer)
+{
+ waitToDumpWatchdog = timer;
+}
+
+bool shouldSetWaitToDumpWatchdog()
+{
+ return !waitToDumpWatchdog && useTimeoutWatchdog;
+}
+
static void invalidateAnyPreviousWaitToDumpWatchdog()
{
if (waitToDumpWatchdog) {
@@ -493,6 +498,7 @@ static void initializeGlobalsFromCommandLineOptions(int argc, char *argv[])
{"notree", no_argument, &dumpTree, false},
{"pixel-tests", no_argument, &dumpPixels, true},
{"tree", no_argument, &dumpTree, true},
+ {"no-timeout", no_argument, &useTimeoutWatchdog, false},
{NULL, 0, NULL, 0}
};
@@ -842,14 +848,19 @@ static gboolean webViewConsoleMessage(WebKitWebView* view, const gchar* message,
gchar* filename = g_strrstr(uriScheme, G_DIR_SEPARATOR_S);
if (filename) {
- filename += strlen(G_DIR_SEPARATOR_S);
+ // If the path is a lone slash, keep it to avoid empty output.
+ if (strlen(filename) > 1)
+ filename += strlen(G_DIR_SEPARATOR_S);
tempString = g_string_append_len(tempString, message, (uriScheme - message));
tempString = g_string_append_len(tempString, filename, strlen(filename));
testMessage = g_string_free(tempString, FALSE);
}
}
- fprintf(stdout, "CONSOLE MESSAGE: line %d: %s\n", line, testMessage ? testMessage : message);
+ fprintf(stdout, "CONSOLE MESSAGE: ");
+ if (line)
+ fprintf(stdout, "line %d: ", line);
+ fprintf(stdout, "%s\n", testMessage ? testMessage : message);
g_free(testMessage);
return TRUE;
@@ -1052,14 +1063,151 @@ static void frameCreatedCallback(WebKitWebView* webView, WebKitWebFrame* webFram
g_signal_connect(webFrame, "notify::load-status", G_CALLBACK(webFrameLoadStatusNotified), NULL);
}
-static void willSendRequestCallback(WebKitWebView* webView, WebKitWebFrame*, WebKitWebResource*, WebKitNetworkRequest* request, WebKitNetworkResponse*)
+
+static CString pathFromSoupURI(SoupURI* uri)
+{
+ if (!uri)
+ return CString();
+
+ if (g_str_equal(uri->scheme, "http")) {
+ GOwnPtr<char> uriString(soup_uri_to_string(uri, FALSE));
+ return CString(uriString.get());
+ }
+
+ GOwnPtr<gchar> pathDirname(g_path_get_basename(g_path_get_dirname(uri->path)));
+ GOwnPtr<gchar> pathBasename(g_path_get_basename(uri->path));
+ GOwnPtr<gchar> urlPath(g_strdup_printf("%s/%s", pathDirname.get(), pathBasename.get()));
+ return CString(urlPath.get());
+}
+
+static CString convertSoupMessageToURLPath(SoupMessage* soupMessage)
+{
+ if (!soupMessage)
+ return CString();
+ if (SoupURI* requestURI = soup_message_get_uri(soupMessage))
+ return pathFromSoupURI(requestURI);
+ return CString();
+}
+
+static CString convertNetworkRequestToURLPath(WebKitNetworkRequest* request)
+{
+ return convertSoupMessageToURLPath(webkit_network_request_get_message(request));
+}
+
+static CString convertWebResourceToURLPath(WebKitWebResource* webResource)
+{
+ SoupURI* uri = soup_uri_new(webkit_web_resource_get_uri(webResource));
+ CString urlPath(pathFromSoupURI(uri));
+ soup_uri_free(uri);
+ return urlPath;
+}
+
+static CString urlSuitableForTestResult(const char* uriString)
+{
+ if (!g_str_has_prefix(uriString, "file://"))
+ return CString(uriString);
+
+ GOwnPtr<gchar> basename(g_path_get_basename(uriString));
+ return CString(basename.get());
+}
+
+static CString descriptionSuitableForTestResult(SoupURI* uri)
+{
+ if (!uri)
+ return CString("");
+
+ GOwnPtr<char> uriString(soup_uri_to_string(uri, false));
+ return urlSuitableForTestResult(uriString.get());
+}
+
+static CString descriptionSuitableForTestResult(WebKitWebView* webView, WebKitWebFrame* webFrame, WebKitWebResource* webResource)
+{
+ SoupURI* uri = soup_uri_new(webkit_web_resource_get_uri(webResource));
+ CString description;
+ WebKitWebDataSource* dataSource = webkit_web_frame_get_data_source(webFrame);
+
+ if (webResource == webkit_web_data_source_get_main_resource(dataSource)
+ && (!webkit_web_view_get_progress(webView) || g_str_equal(uri->scheme, "file")))
+ description = CString("<unknown>");
+ else
+ description = convertWebResourceToURLPath(webResource);
+
+ if (uri)
+ soup_uri_free(uri);
+
+ return description;
+}
+
+static CString descriptionSuitableForTestResult(GError* error, WebKitWebResource* webResource)
{
+ const gchar* errorDomain = g_quark_to_string(error->domain);
+ CString resourceURIString(urlSuitableForTestResult(webkit_web_resource_get_uri(webResource)));
+
+ if (g_str_equal(errorDomain, "webkit-network-error-quark"))
+ errorDomain = "NSURLErrorDomain";
+
+ // TODO: the other ports get the failingURL from the ResourceError
+ GOwnPtr<char> errorString(g_strdup_printf("<NSError domain %s, code %d, failing URL \"%s\">",
+ errorDomain, error->code, resourceURIString.data()));
+ return CString(errorString.get());
+}
+
+static CString descriptionSuitableForTestResult(WebKitNetworkRequest* request)
+{
+ SoupMessage* soupMessage = webkit_network_request_get_message(request);
+
+ if (!soupMessage) {
+ g_printerr("GRR\n");
+ return CString("");
+ }
+
+ SoupURI* requestURI = soup_message_get_uri(soupMessage);
+ SoupURI* mainDocumentURI = soup_message_get_first_party(soupMessage);
+ CString requestURIString(descriptionSuitableForTestResult(requestURI));
+ CString mainDocumentURIString(descriptionSuitableForTestResult(mainDocumentURI));
+ CString path(convertNetworkRequestToURLPath(request));
+ GOwnPtr<char> description(g_strdup_printf("<NSURLRequest URL %s, main document URL %s, http method %s>",
+ path.data(), mainDocumentURIString.data(),
+ soupMessage ? soupMessage->method : "(none)"));
+ return CString(description.get());
+}
+
+static CString descriptionSuitableForTestResult(WebKitNetworkResponse* response)
+{
+ if (!response)
+ return CString("(null)");
+
+ int statusCode = 0;
+ CString responseURIString(urlSuitableForTestResult(webkit_network_response_get_uri(response)));
+ SoupMessage* soupMessage = webkit_network_response_get_message(response);
+ CString path;
+
+ if (soupMessage) {
+ statusCode = soupMessage->status_code;
+ path = convertSoupMessageToURLPath(soupMessage);
+ } else
+ path = CString("");
+
+ GOwnPtr<char> description(g_strdup_printf("<NSURLResponse %s, http status code %d>", path.data(), statusCode));
+ return CString(description.get());
+}
+
+static void willSendRequestCallback(WebKitWebView* webView, WebKitWebFrame* webFrame, WebKitWebResource* resource, WebKitNetworkRequest* request, WebKitNetworkResponse* response)
+{
+
+
if (!done && gLayoutTestController->willSendRequestReturnsNull()) {
// As requested by the LayoutTestController, don't perform the request.
webkit_network_request_set_uri(request, "about:blank");
return;
}
+ if (!done && gLayoutTestController->dumpResourceLoadCallbacks())
+ printf("%s - willSendRequest %s redirectResponse %s\n",
+ convertNetworkRequestToURLPath(request).data(),
+ descriptionSuitableForTestResult(request).data(),
+ descriptionSuitableForTestResult(response).data());
+
SoupMessage* soupMessage = webkit_network_request_get_message(request);
SoupURI* uri = soup_uri_new(webkit_network_request_get_uri(request));
@@ -1067,9 +1215,13 @@ static void willSendRequestCallback(WebKitWebView* webView, WebKitWebFrame*, Web
&& g_strcmp0(uri->host, "255.255.255.255")
&& g_ascii_strncasecmp(uri->host, "localhost", 9)) {
printf("Blocked access to external URL %s\n", soup_uri_to_string(uri, FALSE));
+ // Cancel load of blocked resource to avoid potential
+ // network-related timeouts in tests.
+ webkit_network_request_set_uri(request, "about:blank");
soup_uri_free(uri);
return;
}
+
if (uri)
soup_uri_free(uri);
@@ -1080,6 +1232,34 @@ static void willSendRequestCallback(WebKitWebView* webView, WebKitWebFrame*, Web
}
}
+
+static void didReceiveResponse(WebKitWebView* webView, WebKitWebFrame*, WebKitWebResource* webResource, WebKitNetworkResponse* response)
+{
+ if (!done && gLayoutTestController->dumpResourceLoadCallbacks()) {
+ CString responseDescription(descriptionSuitableForTestResult(response));
+ CString path(convertWebResourceToURLPath(webResource));
+ printf("%s - didReceiveResponse %s\n", path.data(), responseDescription.data());
+ }
+
+ // TODO: add "has MIME type" whenever dumpResourceResponseMIMETypes() is supported.
+ // See https://bugs.webkit.org/show_bug.cgi?id=58222.
+}
+
+static void didFinishLoading(WebKitWebView* webView, WebKitWebFrame* webFrame, WebKitWebResource* webResource)
+{
+ if (!done && gLayoutTestController->dumpResourceLoadCallbacks())
+ printf("%s - didFinishLoading\n", descriptionSuitableForTestResult(webView, webFrame, webResource).data());
+}
+
+static void didFailLoadingWithError(WebKitWebView* webView, WebKitWebFrame* webFrame, WebKitWebResource* webResource, GError* webError)
+{
+ if (!done && gLayoutTestController->dumpResourceLoadCallbacks()) {
+ CString webErrorString(descriptionSuitableForTestResult(webError, webResource));
+ printf("%s - didFailLoadingWithError: %s\n", descriptionSuitableForTestResult(webView, webFrame, webResource).data(),
+ webErrorString.data());
+ }
+}
+
static WebKitWebView* createWebView()
{
// It is important to declare DRT is running early so when creating
@@ -1111,7 +1291,9 @@ static WebKitWebView* createWebView()
"signal::drag-failed", dragFailedCallback, 0,
"signal::frame-created", frameCreatedCallback, 0,
"signal::resource-request-starting", willSendRequestCallback, 0,
-
+ "signal::resource-response-received", didReceiveResponse, 0,
+ "signal::resource-load-finished", didFinishLoading, 0,
+ "signal::resource-load-failed", didFailLoadingWithError, 0,
NULL);
connectEditingCallbacks(view);