summaryrefslogtreecommitdiff
path: root/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp')
-rw-r--r--Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp83
1 files changed, 56 insertions, 27 deletions
diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp
index 211fa8b82..4a260b812 100644
--- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp
+++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp
@@ -39,7 +39,7 @@ static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEven
break;
case WEBKIT_LOAD_COMMITTED: {
g_assert(webkit_web_view_is_loading(webView));
- g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView));
+ test->m_activeURI = webkit_web_view_get_uri(webView);
// Check that on committed we always have a main resource with a response.
WebKitWebResource* resource = webkit_web_view_get_main_resource(webView);
@@ -50,9 +50,15 @@ static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEven
break;
}
case WEBKIT_LOAD_FINISHED:
- g_assert(!webkit_web_view_is_loading(webView));
- if (!test->m_loadFailed)
+ if (!test->m_loadFailed) {
+ g_assert(!webkit_web_view_is_loading(webView));
g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView));
+ } else if (!g_error_matches(test->m_error.get(), WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)) {
+ // When a new load is started before the previous one has finished, we receive the load-finished signal
+ // of the ongoing load while we already have a provisional URL for the new load. This is the only case
+ // where isloading is true when the load has finished.
+ g_assert(!webkit_web_view_is_loading(webView));
+ }
test->loadFinished();
break;
default:
@@ -63,19 +69,24 @@ static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEven
static void loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError* error, LoadTrackingTest* test)
{
test->m_loadFailed = true;
+
+ g_assert(error);
test->m_error.reset(g_error_copy(error));
+ if (!g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)) {
+ // When a new load is started before the previous one has finished, we receive the load-failed signal
+ // of the ongoing load while we already have a provisional URL for the new load. This is the only case
+ // where is-loading is true when the load has failed.
+ g_assert(!webkit_web_view_is_loading(webView));
+ }
+
switch (loadEvent) {
case WEBKIT_LOAD_STARTED:
- g_assert(!webkit_web_view_is_loading(webView));
- g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView));
- g_assert(error);
+ g_assert_cmpstr(test->m_activeURI.data(), ==, failingURI);
test->provisionalLoadFailed(failingURI, error);
break;
case WEBKIT_LOAD_COMMITTED:
- g_assert(!webkit_web_view_is_loading(webView));
g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView));
- g_assert(error);
test->loadFailed(failingURI, error);
break;
default:
@@ -83,6 +94,16 @@ static void loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent
}
}
+static gboolean loadFailedWithTLSErrorsCallback(WebKitWebView* webView, const char* failingURI, GTlsCertificate* certificate, GTlsCertificateFlags tlsErrors, LoadTrackingTest* test)
+{
+ test->m_loadFailed = true;
+ g_assert(!webkit_web_view_is_loading(webView));
+ g_assert_cmpstr(test->m_activeURI.data(), ==, failingURI);
+ g_assert(G_IS_TLS_CERTIFICATE(certificate));
+ g_assert(tlsErrors);
+ return test->loadFailedWithTLSErrors(failingURI, certificate, tlsErrors);
+}
+
static void estimatedProgressChangedCallback(GObject*, GParamSpec*, LoadTrackingTest* test)
{
test->estimatedProgressChanged();
@@ -94,6 +115,7 @@ LoadTrackingTest::LoadTrackingTest()
{
g_signal_connect(m_webView, "load-changed", G_CALLBACK(loadChangedCallback), this);
g_signal_connect(m_webView, "load-failed", G_CALLBACK(loadFailedCallback), this);
+ g_signal_connect(m_webView, "load-failed-with-tls-errors", G_CALLBACK(loadFailedWithTLSErrorsCallback), this);
g_signal_connect(m_webView, "notify::estimated-load-progress", G_CALLBACK(estimatedProgressChangedCallback), this);
g_assert(!webkit_web_view_get_uri(m_webView));
@@ -143,6 +165,12 @@ void LoadTrackingTest::loadFailed(const gchar* failingURI, GError* error)
m_loadEvents.append(LoadFailed);
}
+bool LoadTrackingTest::loadFailedWithTLSErrors(const gchar* /*failingURI*/, GTlsCertificate*, GTlsCertificateFlags)
+{
+ m_loadEvents.append(LoadFailedWithTLSErrors);
+ return false;
+}
+
void LoadTrackingTest::estimatedProgressChanged()
{
double progress = webkit_web_view_get_estimated_load_progress(m_webView);
@@ -152,56 +180,57 @@ void LoadTrackingTest::estimatedProgressChanged()
void LoadTrackingTest::loadURI(const char* uri)
{
- m_loadEvents.clear();
- m_estimatedProgress = 0;
- m_error.reset();
+ reset();
WebViewTest::loadURI(uri);
}
void LoadTrackingTest::loadHtml(const char* html, const char* baseURI)
{
- m_loadEvents.clear();
- m_estimatedProgress = 0;
- m_error.reset();
+ reset();
WebViewTest::loadHtml(html, baseURI);
}
void LoadTrackingTest::loadPlainText(const char* plainText)
{
- m_loadEvents.clear();
- m_estimatedProgress = 0;
- m_error.reset();
+ reset();
WebViewTest::loadPlainText(plainText);
}
+void LoadTrackingTest::loadBytes(GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI)
+{
+ reset();
+ WebViewTest::loadBytes(bytes, mimeType, encoding, baseURI);
+}
+
void LoadTrackingTest::loadRequest(WebKitURIRequest* request)
{
- m_loadEvents.clear();
- m_estimatedProgress = 0;
- m_error.reset();
+ reset();
WebViewTest::loadRequest(request);
}
void LoadTrackingTest::reload()
{
- m_loadEvents.clear();
- m_estimatedProgress = 0;
- m_error.reset();
+ reset();
webkit_web_view_reload(m_webView);
}
void LoadTrackingTest::goBack()
{
- m_loadEvents.clear();
- m_estimatedProgress = 0;
- m_error.reset();
+ reset();
WebViewTest::goBack();
}
void LoadTrackingTest::goForward()
{
+ reset();
+ WebViewTest::goForward();
+}
+
+void LoadTrackingTest::reset()
+{
+ m_runLoadUntilCompletion = false;
+ m_loadFailed = false;
m_loadEvents.clear();
m_estimatedProgress = 0;
m_error.reset();
- WebViewTest::goForward();
}