Title: [98707] trunk/Source/WebKit2
Revision
98707
Author
[email protected]
Date
2011-10-28 01:12:53 -0700 (Fri, 28 Oct 2011)

Log Message

[GTK] Add webkit_web_view_get_uri() to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=70814

Reviewed by Gustavo Noronha Silva.

* UIProcess/API/gtk/WebKitWebLoaderClient.cpp:
(didStartProvisionalLoadForFrame): Update WebView URI to make sure
it's updated to provisional URL.
(didReceiveServerRedirectForProvisionalLoadForFrame): Update
WebView URI if there's a server redirection.
(didCommitLoadForFrame): Update WebView URI to make sure it
contains the final one.
(didSameDocumentNavigationForFrame): Update WebView URI when a
navigation action within the same document is performed.
(webkitWebLoaderClientAttachLoaderClientToPage): Add
implementation for didSameDocumentNavigationForFrame callback.
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_class_init): Add URI property.
(webkitWebViewUpdateURI): Check whether current active URI has
changed to updated it and emit ::notify signal if it changes.
(webkit_web_view_load_uri): Call webkitWebViewUpdateURI() to make
sure the active URI is updated when load operation is started.
(webkit_web_view_load_alternate_html): Ditto.
(webkit_web_view_reload): Ditto.
(webkit_web_view_reload_bypass_cache): Ditto.
(webkit_web_view_go_back): Ditto.
(webkit_web_view_go_forward): Ditto.
(webkit_web_view_get_uri): Ditto.
(webkit_web_view_go_to_back_forward_list_item): Ditto.
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/WebKitWebViewPrivate.h: Add
webkitWebViewUpdateURI().
* UIProcess/API/gtk/tests/LoadTrackingTest.cpp:
(provisionalLoadStartedCallback): Check provisional URL is the
requested URI.
(provisionalLoadReceivedServerRedirectCallback): Check provisional
URL after server redirection is the expected redirected URI.
(provisionalLoadFailedCallback): Check active URI.
(loadCommittedCallback): Ditto.
(loadFinishedCallback): Ditto.
(loadFailedCallback): Ditto
(LoadTrackingTest::LoadTrackingTest): Check active URI is NULL
before any loading operation has started.
* UIProcess/API/gtk/tests/LoadTrackingTest.h:
(LoadTrackingTest::setRedirectURI): Set the redirect URI to check
it after a server redirection.
* UIProcess/API/gtk/tests/TestBackForwardList.cpp:
(testBackForwardListNavigation): Use WebViewTest methods for
navigation actions instead of using WebKitWebView API directly.
(testBackForwardListLimitAndCache): Ditto.
* UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp:
(testLoadingStatus): Ditto.
(testLoadingError): Ditto.
(testLoadAlternateContent): Ditto.
(testLoadCancelled): Ditto.
(testWebViewReload): Ditto.
(testLoadProgress): Ditto.
(testWebViewActiveURI): Add a test to check that notify signal is
emitted when active URI changes and it's correctly updated when
loader client signals are emitted.
(beforeAll): Add active-uri test.
* UIProcess/API/gtk/tests/WebViewTest.cpp: Add custom load methods
wrapping the WebKitWebView ones, to initialize the active URI to
the requested one, so that it can be checked by the loader client
test.
(WebViewTest::loadURI):
(WebViewTest::loadAlternateHTML):
(WebViewTest::goBack):
(WebViewTest::goForward):
(WebViewTest::goToBackForwardListItem):
* UIProcess/API/gtk/tests/WebViewTest.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (98706 => 98707)


--- trunk/Source/WebKit2/ChangeLog	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/ChangeLog	2011-10-28 08:12:53 UTC (rev 98707)
@@ -1,3 +1,77 @@
+2011-10-28  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Add webkit_web_view_get_uri() to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=70814
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * UIProcess/API/gtk/WebKitWebLoaderClient.cpp:
+        (didStartProvisionalLoadForFrame): Update WebView URI to make sure
+        it's updated to provisional URL.
+        (didReceiveServerRedirectForProvisionalLoadForFrame): Update
+        WebView URI if there's a server redirection.
+        (didCommitLoadForFrame): Update WebView URI to make sure it
+        contains the final one.
+        (didSameDocumentNavigationForFrame): Update WebView URI when a
+        navigation action within the same document is performed.
+        (webkitWebLoaderClientAttachLoaderClientToPage): Add
+        implementation for didSameDocumentNavigationForFrame callback.
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkit_web_view_class_init): Add URI property.
+        (webkitWebViewUpdateURI): Check whether current active URI has
+        changed to updated it and emit ::notify signal if it changes.
+        (webkit_web_view_load_uri): Call webkitWebViewUpdateURI() to make
+        sure the active URI is updated when load operation is started.
+        (webkit_web_view_load_alternate_html): Ditto.
+        (webkit_web_view_reload): Ditto.
+        (webkit_web_view_reload_bypass_cache): Ditto.
+        (webkit_web_view_go_back): Ditto.
+        (webkit_web_view_go_forward): Ditto.
+        (webkit_web_view_get_uri): Ditto.
+        (webkit_web_view_go_to_back_forward_list_item): Ditto.
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/WebKitWebViewPrivate.h: Add
+        webkitWebViewUpdateURI().
+        * UIProcess/API/gtk/tests/LoadTrackingTest.cpp:
+        (provisionalLoadStartedCallback): Check provisional URL is the
+        requested URI.
+        (provisionalLoadReceivedServerRedirectCallback): Check provisional
+        URL after server redirection is the expected redirected URI.
+        (provisionalLoadFailedCallback): Check active URI.
+        (loadCommittedCallback): Ditto.
+        (loadFinishedCallback): Ditto.
+        (loadFailedCallback): Ditto
+        (LoadTrackingTest::LoadTrackingTest): Check active URI is NULL
+        before any loading operation has started.
+        * UIProcess/API/gtk/tests/LoadTrackingTest.h:
+        (LoadTrackingTest::setRedirectURI): Set the redirect URI to check
+        it after a server redirection.
+        * UIProcess/API/gtk/tests/TestBackForwardList.cpp:
+        (testBackForwardListNavigation): Use WebViewTest methods for
+        navigation actions instead of using WebKitWebView API directly.
+        (testBackForwardListLimitAndCache): Ditto.
+        * UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp:
+        (testLoadingStatus): Ditto.
+        (testLoadingError): Ditto.
+        (testLoadAlternateContent): Ditto.
+        (testLoadCancelled): Ditto.
+        (testWebViewReload): Ditto.
+        (testLoadProgress): Ditto.
+        (testWebViewActiveURI): Add a test to check that notify signal is
+        emitted when active URI changes and it's correctly updated when
+        loader client signals are emitted.
+        (beforeAll): Add active-uri test.
+        * UIProcess/API/gtk/tests/WebViewTest.cpp: Add custom load methods
+        wrapping the WebKitWebView ones, to initialize the active URI to
+        the requested one, so that it can be checked by the loader client
+        test.
+        (WebViewTest::loadURI):
+        (WebViewTest::loadAlternateHTML):
+        (WebViewTest::goBack):
+        (WebViewTest::goForward):
+        (WebViewTest::goToBackForwardListItem):
+        * UIProcess/API/gtk/tests/WebViewTest.h:
+
 2011-10-21  No'am Rosenthal  <[email protected]>
 
         [Qt][WK2] Synchronize tiling with accelerated compositing

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.cpp (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.cpp	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.cpp	2011-10-28 08:12:53 UTC (rev 98707)
@@ -57,6 +57,7 @@
 
     gboolean returnValue;
     WebKitWebView* webView = WEBKIT_WEB_VIEW(toImpl(page)->viewWidget());
+    webkitWebViewUpdateURI(webView);
     g_signal_emit(WEBKIT_WEB_LOADER_CLIENT(clientInfo), signals[PROVISIONAL_LOAD_STARTED], 0, webView, &returnValue);
 }
 
@@ -67,6 +68,7 @@
 
     gboolean returnValue;
     WebKitWebView* webView = WEBKIT_WEB_VIEW(toImpl(page)->viewWidget());
+    webkitWebViewUpdateURI(webView);
     g_signal_emit(WEBKIT_WEB_LOADER_CLIENT(clientInfo), signals[PROVISIONAL_LOAD_RECEIVED_SERVER_REDIRECT], 0, webView, &returnValue);
 }
 
@@ -92,6 +94,7 @@
 
     gboolean returnValue;
     WebKitWebView* webView = WEBKIT_WEB_VIEW(toImpl(page)->viewWidget());
+    webkitWebViewUpdateURI(webView);
     g_signal_emit(WEBKIT_WEB_LOADER_CLIENT(clientInfo), signals[LOAD_COMMITTED], 0, webView,  &returnValue);
 }
 
@@ -120,6 +123,14 @@
                   resourceError.failingURL().utf8().data(), webError.get(), &returnValue);
 }
 
+static void didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType, WKTypeRef, const void*)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+
+    webkitWebViewUpdateURI(WEBKIT_WEB_VIEW(toImpl(page)->viewWidget()));
+}
+
 static void didChangeProgress(WKPageRef page, const void* clientInfo)
 {
     WebKitWebView* webView = WEBKIT_WEB_VIEW(toImpl(page)->viewWidget());
@@ -144,7 +155,7 @@
         0, // didFinishDocumentLoadForFrame
         didFinishLoadForFrame,
         didFailLoadWithErrorForFrame,
-        0, // didSameDocumentNavigationForFrame
+        didSameDocumentNavigationForFrame,
         0, // didReceiveTitleForFrame
         0, // didFirstLayoutForFrame
         0, // didFirstVisuallyNonEmptyLayoutForFrame

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-10-28 08:12:53 UTC (rev 98707)
@@ -42,13 +42,15 @@
     PROP_0,
 
     PROP_WEB_CONTEXT,
-    PROP_ESTIMATED_LOAD_PROGRESS
+    PROP_ESTIMATED_LOAD_PROGRESS,
+    PROP_URI
 };
 
 struct _WebKitWebViewPrivate {
     WebKitWebContext* context;
     CString customTextEncoding;
     double estimatedLoadProgress;
+    CString activeURI;
 
     GRefPtr<WebKitWebLoaderClient> loaderClient;
     GRefPtr<WebKitBackForwardList> backForwardList;
@@ -105,6 +107,9 @@
     case PROP_ESTIMATED_LOAD_PROGRESS:
         g_value_set_double(value, webkit_web_view_get_estimated_load_progress(webView));
         break;
+    case PROP_URI:
+        g_value_set_string(value, webkit_web_view_get_uri(webView));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     }
@@ -164,6 +169,19 @@
                                                         "An estimate of the percent completion for a document load",
                                                         0.0, 1.0, 0.0,
                                                         WEBKIT_PARAM_READABLE));
+    /**
+     * WebKitWebView:uri:
+     *
+     * The current active URI of the #WebKitWebView.
+     * See webkit_web_view_get_uri() for more details.
+     */
+    g_object_class_install_property(gObjectClass,
+                                    PROP_URI,
+                                    g_param_spec_string("uri",
+                                                        "URI",
+                                                        "The current active URI of the view",
+                                                        0,
+                                                        WEBKIT_PARAM_READABLE));
 }
 
 void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress)
@@ -174,6 +192,21 @@
     g_object_notify(G_OBJECT(webView), "estimated-load-progress");
 }
 
+void webkitWebViewUpdateURI(WebKitWebView* webView)
+{
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKPageCopyActiveURL(toAPI(page)));
+    CString activeURI;
+    if (wkURL)
+        activeURI = toImpl(wkURL.get())->string().utf8();
+
+    if (webView->priv->activeURI == activeURI)
+        return;
+
+    webView->priv->activeURI = activeURI;
+    g_object_notify(G_OBJECT(webView), "uri");
+}
+
 /**
  * webkit_web_view_new:
  *
@@ -271,6 +304,7 @@
     WKRetainPtr<WKURLRef> url(AdoptWK, WKURLCreateWithUTF8CString(uri));
     WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
     WKPageLoadURL(toAPI(page), url.get());
+    webkitWebViewUpdateURI(webView);
 }
 
 /**
@@ -299,6 +333,7 @@
     WKRetainPtr<WKURLRef> unreachableURL = unreachableURI ? adoptWK(WKURLCreateWithUTF8CString(unreachableURI)) : 0;
     WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
     WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), unreachableURL.get());
+    webkitWebViewUpdateURI(webView);
 }
 
 /**
@@ -313,6 +348,7 @@
     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
 
     WKPageReload(toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))));
+    webkitWebViewUpdateURI(webView);
 }
 
 /**
@@ -327,6 +363,7 @@
     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
 
     WKPageReloadFromOrigin(toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))));
+    webkitWebViewUpdateURI(webView);
 }
 
 /**
@@ -361,6 +398,7 @@
     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
 
     WKPageGoBack(toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))));
+    webkitWebViewUpdateURI(webView);
 }
 
 /**
@@ -391,6 +429,7 @@
     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
 
     WKPageGoForward(toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))));
+    webkitWebViewUpdateURI(webView);
 }
 
 /**
@@ -409,6 +448,67 @@
 }
 
 /**
+ * webkit_web_view_get_uri:
+ * @web_view: a #WebKitWebView
+ *
+ * Returns the current active URI of @web_view. The active URI might change during
+ * a load operation:
+ *
+ * <orderedlist>
+ * <listitem><para>
+ *   When nothing has been loaded yet on @web_view the active URI is %NULL.
+ * </para></listitem>
+ * <listitem><para>
+ *   When a new load operation starts the active URI is the requested URI:
+ *   <itemizedlist>
+ *   <listitem><para>
+ *     If the load operation was started by webkit_web_view_load_uri(),
+ *     the requested URI is the given one.
+ *   </para></listitem>
+ *   <listitem><para>
+ *     If the load operation was started by webkit_web_view_load_alternate_html(),
+ *     the requested URI is "about:blank".
+ *   </para></listitem>
+ *   <listitem><para>
+ *     If the load operation was started by webkit_web_view_go_back() or
+ *     webkit_web_view_go_forward(), the requested URI is the original URI
+ *     of the previous/next item in the #WebKitBackForwardList of @web_view.
+ *   </para></listitem>
+ *   <listitem><para>
+ *     If the load operation was started by
+ *     webkit_web_view_go_to_back_forward_list_item(), the requested URI
+ *     is the opriginal URI of the given #WebKitBackForwardListItem.
+ *   </para></listitem>
+ *   </itemizedlist>
+ * </para></listitem>
+ * <listitem><para>
+ *   If there is a server redirection during the load operation,
+ *   the active URI is the redirected URI. When the signal
+ *   #WebKitWebLoaderClient::provisional-load-received-server-redirect
+ *   is emitted, the active URI is already updated to the redirected URI.
+ * </para></listitem>
+ * <listitem><para>
+ *   When the signal #WebKitWebLoaderClient::load-committed is emitted,
+ *   the active URI is the final one and it will not change unless
+ *   a new load operation is started or a navigation action within the
+ *   same page is performed.
+ * </para></listitem>
+ * </orderedlist>
+ *
+ * You can monitor the active URI by connecting to the notify::uri
+ * signal of @web_view.
+ *
+ * Returns: the current active URI of @web_view or %NULL
+ *    if nothing has been loaded yet.
+ */
+const gchar* webkit_web_view_get_uri(WebKitWebView* webView)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
+
+    return webView->priv->activeURI.data();
+}
+
+/**
  * webkit_web_view_get_custom_charset:
  * @web_view: a #WebKitWebView
  *
@@ -499,4 +599,5 @@
 
     WKPageGoToBackForwardListItem(toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))),
                                   webkitBackForwardListItemGetWKItem(listItem));
+    webkitWebViewUpdateURI(webView);
 }

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-10-28 08:12:53 UTC (rev 98707)
@@ -124,6 +124,8 @@
 WEBKIT_API void
 webkit_web_view_go_to_back_forward_list_item (WebKitWebView             *web_view,
                                               WebKitBackForwardListItem *list_item);
+WEBKIT_API const gchar *
+webkit_web_view_get_uri                      (WebKitWebView             *web_view);
 
 WEBKIT_API const gchar *
 webkit_web_view_get_custom_charset           (WebKitWebView             *web_view);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h	2011-10-28 08:12:53 UTC (rev 98707)
@@ -30,5 +30,6 @@
 #include <WebKit2/WebKit2.h>
 
 void webkitWebViewSetEstimatedLoadProgress(WebKitWebView*, double estimatedLoadProgress);
+void webkitWebViewUpdateURI(WebKitWebView*);
 
 #endif // WebKitWebViewPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2011-10-28 08:12:53 UTC (rev 98707)
@@ -63,6 +63,7 @@
 webkit_web_view_set_custom_charset
 webkit_web_view_get_back_forward_list
 webkit_web_view_go_to_back_forward_list_item
+webkit_web_view_get_uri
 
 <SUBSECTION Standard>
 WebKitWebViewClass

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp	2011-10-28 08:12:53 UTC (rev 98707)
@@ -24,18 +24,23 @@
 
 static gboolean provisionalLoadStartedCallback(WebKitWebLoaderClient* client, WebKitWebView*, LoadTrackingTest* test)
 {
+    g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(test->m_webView));
     test->provisionalLoadStarted(client);
     return TRUE;
 }
 
 static gboolean provisionalLoadReceivedServerRedirectCallback(WebKitWebLoaderClient* client, WebKitWebView*, LoadTrackingTest* test)
 {
+    test->m_activeURI = webkit_web_view_get_uri(test->m_webView);
+    if (!test->m_redirectURI.isNull())
+        g_assert_cmpstr(test->m_redirectURI.data(), ==, test->m_activeURI.data());
     test->provisionalLoadReceivedServerRedirect(client);
     return TRUE;
 }
 
 static gboolean provisionalLoadFailedCallback(WebKitWebLoaderClient* client, WebKitWebView*, const gchar* failingURI, GError* error, LoadTrackingTest* test)
 {
+    g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(test->m_webView));
     g_assert(error);
     test->provisionalLoadFailed(client, failingURI, error);
     return TRUE;
@@ -43,18 +48,21 @@
 
 static gboolean loadCommittedCallback(WebKitWebLoaderClient* client, WebKitWebView*, LoadTrackingTest* test)
 {
+    g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(test->m_webView));
     test->loadCommitted(client);
     return TRUE;
 }
 
 static gboolean loadFinishedCallback(WebKitWebLoaderClient* client, WebKitWebView*, LoadTrackingTest* test)
 {
+    g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(test->m_webView));
     test->loadFinished(client);
     return TRUE;
 }
 
 static gboolean loadFailedCallback(WebKitWebLoaderClient* client, WebKitWebView*, const gchar* failingURI, GError* error, LoadTrackingTest* test)
 {
+    g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(test->m_webView));
     g_assert(error);
     test->loadFailed(client, failingURI, error);
     return TRUE;
@@ -76,6 +84,8 @@
     g_signal_connect(client, "load-finished", G_CALLBACK(loadFinishedCallback), this);
     g_signal_connect(client, "load-failed", G_CALLBACK(loadFailedCallback), this);
     g_signal_connect(m_webView, "notify::estimated-load-progress", G_CALLBACK(estimatedProgressChangedCallback), this);
+
+    g_assert(!webkit_web_view_get_uri(m_webView));
 }
 
 LoadTrackingTest::~LoadTrackingTest()

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h	2011-10-28 08:12:53 UTC (rev 98707)
@@ -39,6 +39,8 @@
     virtual void loadFailed(WebKitWebLoaderClient*, const char* failingURI, GError*);
     virtual void estimatedProgressChanged();
 
+    void setRedirectURI(const char* uri) { m_redirectURI = uri; }
+
     enum LoadEvents {
         ProvisionalLoadStarted,
         ProvisionalLoadReceivedServerRedirect,
@@ -50,6 +52,7 @@
     bool m_runLoadUntilCompletion;
     Vector<LoadEvents> m_loadEvents;
     float m_estimatedProgress;
+    CString m_redirectURI;
 };
 
 #endif // LoadTrackingTest_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp	2011-10-28 08:12:53 UTC (rev 98707)
@@ -164,7 +164,7 @@
 
     CString uriPage1 = kServer->getURIForPath("/Page1");
     test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem;
-    webkit_web_view_load_uri(test->m_webView, uriPage1.data());
+    test->loadURI(uriPage1.data());
     test->waitUntilLoadFinished();
 
     g_assert(!webkit_web_view_can_go_back(test->m_webView));
@@ -181,7 +181,7 @@
 
     CString uriPage2 = kServer->getURIForPath("/Page2");
     test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem;
-    webkit_web_view_load_uri(test->m_webView, uriPage2.data());
+    test->loadURI(uriPage2.data());
     test->waitUntilLoadFinished();
 
     g_assert(webkit_web_view_can_go_back(test->m_webView));
@@ -198,7 +198,7 @@
     g_assert(!webkit_back_forward_list_get_forward_list(test->m_list));
 
     test->m_changedFlags = BackForwardListTest::CurrentItem;
-    webkit_web_view_go_back(test->m_webView);
+    test->goBack();
     test->waitUntilLoadFinished();
 
     g_assert(!webkit_web_view_can_go_back(test->m_webView));
@@ -215,7 +215,7 @@
     BackForwardListTest::checkList(test->m_list, BackForwardListTest::Forward, items, 1);
 
     test->m_changedFlags = BackForwardListTest::CurrentItem;
-    webkit_web_view_go_forward(test->m_webView);
+    test->goForward();
     test->waitUntilLoadFinished();
 
     g_assert(webkit_web_view_can_go_back(test->m_webView));
@@ -232,7 +232,7 @@
     g_assert(!webkit_back_forward_list_get_forward_list(test->m_list));
 
     test->m_changedFlags = BackForwardListTest::CurrentItem;
-    webkit_web_view_go_to_back_forward_list_item(test->m_webView, itemPage1);
+    test->goToBackForwardListItem(itemPage1);
     test->waitUntilLoadFinished();
 
     g_assert(itemPage1 == webkit_back_forward_list_get_current_item(test->m_list));
@@ -243,7 +243,7 @@
     for (size_t i = 0; i < kBackForwardListLimit; i++) {
         GOwnPtr<char> path(g_strdup_printf("/Page%d", i));
         test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem;
-        webkit_web_view_load_uri(test->m_webView, kServer->getURIForPath(path.get()).data());
+        test->loadURI(kServer->getURIForPath(path.get()).data());
         test->waitUntilLoadFinished();
     }
 
@@ -253,7 +253,7 @@
 
     GOwnPtr<char> path(g_strdup_printf("/Page%d", kBackForwardListLimit));
     test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem | BackForwardListTest::RemovedItems;
-    webkit_web_view_load_uri(test->m_webView, kServer->getURIForPath(path.get()).data());
+    test->loadURI(kServer->getURIForPath(path.get()).data());
     test->waitUntilLoadFinishedAndCheckRemovedItems(removedItems.get());
 
     g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, kBackForwardListLimit);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp	2011-10-28 08:12:53 UTC (rev 98707)
@@ -30,7 +30,8 @@
 
 static void testLoadingStatus(LoadTrackingTest* test, gconstpointer data)
 {
-    webkit_web_view_load_uri(test->m_webView, kServer->getURIForPath("/redirect").data());
+    test->setRedirectURI(kServer->getURIForPath("/normal").data());
+    test->loadURI(kServer->getURIForPath("/redirect").data());
     test->waitUntilLoadFinished();
 
     Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents;
@@ -43,7 +44,7 @@
 
 static void testLoadingError(LoadTrackingTest* test, gconstpointer)
 {
-    webkit_web_view_load_uri(test->m_webView, kServer->getURIForPath("/error").data());
+    test->loadURI(kServer->getURIForPath("/error").data());
     test->waitUntilLoadFinished();
 
     Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents;
@@ -63,9 +64,7 @@
 
 static void testLoadAlternateContent(LoadTrackingTest* test, gconstpointer)
 {
-    webkit_web_view_load_alternate_html(test->m_webView,
-                                        "<html><body>Alternate Content</body></html>",
-                                        0, kServer->getURIForPath("/alternate").data());
+    test->loadAlternateHTML("<html><body>Alternate Content</body></html>", 0, kServer->getURIForPath("/alternate").data());
     test->waitUntilLoadFinished();
     assertNormalLoadHappenedAndClearEvents(test->m_loadEvents);
 }
@@ -92,7 +91,7 @@
 
 static void testLoadCancelled(LoadStopTrackingTest* test, gconstpointer)
 {
-    webkit_web_view_load_uri(test->m_webView, kServer->getURIForPath("/cancelled").data());
+    test->loadURI(kServer->getURIForPath("/cancelled").data());
     test->waitUntilLoadFinished();
 
     Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents;
@@ -108,7 +107,7 @@
     webkit_web_view_reload(test->m_webView);
     test->wait(0.25); // Wait for a quarter of a second.
 
-    webkit_web_view_load_uri(test->m_webView, kServer->getURIForPath("/normal").data());
+    test->loadURI(kServer->getURIForPath("/normal").data());
     test->waitUntilLoadFinished();
     assertNormalLoadHappenedAndClearEvents(test->m_loadEvents);
 
@@ -119,11 +118,66 @@
 
 static void testLoadProgress(LoadTrackingTest* test, gconstpointer)
 {
-    webkit_web_view_load_uri(test->m_webView, kServer->getURIForPath("/normal").data());
+    test->loadURI(kServer->getURIForPath("/normal").data());
     test->waitUntilLoadFinished();
     g_assert_cmpfloat(test->m_estimatedProgress, ==, 1);
 }
 
+class ViewURITrackingTest: public LoadTrackingTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(ViewURITrackingTest);
+
+    static void uriChanged(GObject*, GParamSpec*, ViewURITrackingTest* test)
+    {
+        g_assert_cmpstr(test->m_activeURI.data(), !=, webkit_web_view_get_uri(test->m_webView));
+        test->m_activeURI = webkit_web_view_get_uri(test->m_webView);
+    }
+
+    ViewURITrackingTest()
+        : m_activeURI(webkit_web_view_get_uri(m_webView))
+    {
+        g_assert(m_activeURI.isNull());
+        g_signal_connect(m_webView, "notify::uri", G_CALLBACK(uriChanged), this);
+    }
+
+    void provisionalLoadStarted(WebKitWebLoaderClient*)
+    {
+        checkActiveURI("/redirect");
+    }
+
+    void provisionalLoadReceivedServerRedirect(WebKitWebLoaderClient*)
+    {
+        checkActiveURI("/normal");
+    }
+
+    void loadCommitted(WebKitWebLoaderClient*)
+    {
+        checkActiveURI("/normal");
+    }
+
+    void loadFinished(WebKitWebLoaderClient* client)
+    {
+        checkActiveURI("/normal");
+        LoadTrackingTest::loadFinished(client);
+    }
+
+    CString m_activeURI;
+
+private:
+    void checkActiveURI(const char* uri)
+    {
+        // g_assert_cmpstr is a macro, so we need to cache the temporary string.
+        CString serverURI = kServer->getURIForPath(uri);
+        g_assert_cmpstr(m_activeURI.data(), ==, serverURI.data());
+    }
+};
+
+static void testWebViewActiveURI(ViewURITrackingTest* test, gconstpointer)
+{
+    test->loadURI(kServer->getURIForPath("/redirect").data());
+    test->waitUntilLoadFinished();
+}
+
 static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
 {
     static const char* responseString = "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
@@ -170,6 +224,10 @@
     LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled);
     LoadTrackingTest::add("WebKitWebView", "progress", testLoadProgress);
     LoadTrackingTest::add("WebKitWebView", "reload", testWebViewReload);
+
+    // This test checks that web view notify::uri signal is correctly emitted
+    // and the uri is already updated when loader client signals are emitted.
+    ViewURITrackingTest::add("WebKitWebView", "active-uri", testWebViewActiveURI);
 }
 
 void afterAll()

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2011-10-28 08:12:53 UTC (rev 98707)
@@ -39,6 +39,48 @@
     return FALSE;
 }
 
+void WebViewTest::loadURI(const char* uri)
+{
+    m_activeURI = uri;
+    webkit_web_view_load_uri(m_webView, uri);
+}
+
+void WebViewTest::loadAlternateHTML(const char* html, const char* baseURI, const char* unreachableURI)
+{
+    m_activeURI = "about:blank";
+    webkit_web_view_load_alternate_html(m_webView, html, baseURI, unreachableURI);
+}
+
+void WebViewTest::goBack()
+{
+    if (webkit_web_view_can_go_back(m_webView)) {
+        WebKitBackForwardList* list = webkit_web_view_get_back_forward_list(m_webView);
+        WebKitBackForwardListItem* item = webkit_back_forward_list_get_nth_item(list, -1);
+        m_activeURI = webkit_back_forward_list_item_get_original_uri(item);
+    }
+
+    // Call go_back even when can_go_back returns FALSE to check nothing happens.
+    webkit_web_view_go_back(m_webView);
+}
+
+void WebViewTest::goForward()
+{
+    if (webkit_web_view_can_go_forward(m_webView)) {
+        WebKitBackForwardList* list = webkit_web_view_get_back_forward_list(m_webView);
+        WebKitBackForwardListItem* item = webkit_back_forward_list_get_nth_item(list, 1);
+        m_activeURI = webkit_back_forward_list_item_get_original_uri(item);
+    }
+
+    // Call go_forward even when can_go_forward returns FALSE to check nothing happens.
+    webkit_web_view_go_forward(m_webView);
+}
+
+void WebViewTest::goToBackForwardListItem(WebKitBackForwardListItem* item)
+{
+    m_activeURI = webkit_back_forward_list_item_get_original_uri(item);
+    webkit_web_view_go_to_back_forward_list_item(m_webView, item);
+}
+
 void WebViewTest::wait(double seconds)
 {
     g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(testLoadTimeoutFinishLoop), m_mainLoop);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h (98706 => 98707)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2011-10-28 07:59:18 UTC (rev 98706)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2011-10-28 08:12:53 UTC (rev 98707)
@@ -22,6 +22,7 @@
 
 #include "TestMain.h"
 #include <webkit2/webkit2.h>
+#include <wtf/text/CString.h>
 
 class WebViewTest: public Test {
 public:
@@ -29,10 +30,17 @@
     WebViewTest();
     virtual ~WebViewTest();
 
+    void loadURI(const char* uri);
+    void loadAlternateHTML(const char* html, const char* baseURI, const char* unreachableURI);
+    void goBack();
+    void goForward();
+    void goToBackForwardListItem(WebKitBackForwardListItem*);
+
     void wait(double seconds);
 
     WebKitWebView* m_webView;
     GMainLoop* m_mainLoop;
+    CString m_activeURI;
 };
 
 #endif // WebViewTest_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to