[EFL][WK2] Back-forward list API needs extension
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2012 11:47:54 +0000 (11:47 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2012 11:47:54 +0000 (11:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94582

Patch by Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com> on 2012-08-24
Reviewed by Kenneth Rohde Christiansen.

Added several new functions wrapping existing WK2 C back-forward list API
and returning list of items preceding or following the current one.
Corresponding API unit tests are also added.

* UIProcess/API/efl/ewk_back_forward_list.cpp:
(createEinaList):
(ewk_back_forward_list_n_back_items_copy):
(ewk_back_forward_list_n_forward_items_copy):
* UIProcess/API/efl/ewk_back_forward_list.h:
* UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp:
(freeEinaList):
(TEST_F):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126571 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp
Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.h
Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp

index c955f6c..c305516 100644 (file)
@@ -1,3 +1,23 @@
+2012-08-24  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
+
+        [EFL][WK2] Back-forward list API needs extension
+        https://bugs.webkit.org/show_bug.cgi?id=94582
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Added several new functions wrapping existing WK2 C back-forward list API
+        and returning list of items preceding or following the current one.
+        Corresponding API unit tests are also added.
+
+        * UIProcess/API/efl/ewk_back_forward_list.cpp:
+        (createEinaList):
+        (ewk_back_forward_list_n_back_items_copy):
+        (ewk_back_forward_list_n_forward_items_copy):
+        * UIProcess/API/efl/ewk_back_forward_list.h:
+        * UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp:
+        (freeEinaList):
+        (TEST_F):
+
 2012-08-24  Michael BrĂ¼ning  <michaelbruening@gmail.com>
 
         [Qt][WK2] Make viewport related experimental.test properties encapsulated.
index acf8d56..c3c7c1a 100644 (file)
@@ -84,6 +84,24 @@ static inline Ewk_Back_Forward_List_Item* addItemToWrapperCache(const Ewk_Back_F
     return item;
 }
 
+static inline Eina_List* createEinaList(const Ewk_Back_Forward_List* list, WKArrayRef wkList)
+{
+    if (!wkList)
+        return 0;
+
+    Eina_List* result = 0;
+
+    const size_t count = WKArrayGetSize(wkList);
+    for (size_t i = 0; i < count; ++i) {
+        WKBackForwardListItemRef wkItem = static_cast<WKBackForwardListItemRef>(WKArrayGetItemAtIndex(wkList, i));
+        Ewk_Back_Forward_List_Item* item = addItemToWrapperCache(list, wkItem);
+        ewk_back_forward_list_item_ref(item);
+        result = eina_list_append(result, item);
+    }
+
+    return result;
+}
+
 Ewk_Back_Forward_List_Item* ewk_back_forward_list_current_item_get(const Ewk_Back_Forward_List* list)
 {
     EWK_BACK_FORWARD_LIST_WK_GET_OR_RETURN(list, wkList, 0);
@@ -121,6 +139,29 @@ unsigned ewk_back_forward_list_count(Ewk_Back_Forward_List* list)
     return WKBackForwardListGetBackListCount(wkList) + WKBackForwardListGetForwardListCount(wkList) + currentItem;
 }
 
+Eina_List* ewk_back_forward_list_n_back_items_copy(const Ewk_Back_Forward_List* list, int limit)
+{
+    EWK_BACK_FORWARD_LIST_WK_GET_OR_RETURN(list, wkList, 0);
+
+    if (limit == -1)
+        limit = WKBackForwardListGetBackListCount(wkList);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(limit >= 0, 0);
+    WKRetainPtr<WKArrayRef> backList(AdoptWK, WKBackForwardListCopyBackListWithLimit(wkList, limit));
+
+    return createEinaList(list, backList.get());
+}
+
+Eina_List* ewk_back_forward_list_n_forward_items_copy(const Ewk_Back_Forward_List* list, int limit)
+{
+    EWK_BACK_FORWARD_LIST_WK_GET_OR_RETURN(list, wkList, 0);
+
+    if (limit == -1)
+        limit = WKBackForwardListGetForwardListCount(wkList);
+    EINA_SAFETY_ON_NULL_RETURN_VAL(limit >= 0, 0);
+    WKRetainPtr<WKArrayRef> forwardList(AdoptWK, WKBackForwardListCopyForwardListWithLimit(wkList, limit));
+
+    return createEinaList(list, forwardList.get());
+}
 
 /**
  * @internal
index 5b9cca7..c584761 100644 (file)
@@ -86,6 +86,68 @@ EAPI Ewk_Back_Forward_List_Item *ewk_back_forward_list_item_at_index_get(const E
  */
 EAPI unsigned ewk_back_forward_list_count(Ewk_Back_Forward_List *list);
 
+/**
+ * Creates the list containing the items preceding the current item limited by @a limit.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ * if @a limit is equal to @c -1 all the items preceding the current item are returned.
+ *
+ * @param list the back-forward list instance
+ * @param limit the number of items to retrieve
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ *            the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ *            to free the items
+ */
+EAPI Eina_List *ewk_back_forward_list_n_back_items_copy(const Ewk_Back_Forward_List *list, int limit);
+
+/**
+ * Creates the list containing the items following the current item limited by @a limit.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ * if @a limit is equal to @c -1 all the items preceding the current item are returned.
+ *
+ * @param list the back-forward list instance
+ * @param limit the number of items to retrieve
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ *            the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ *            to free the items
+ */
+EAPI Eina_List *ewk_back_forward_list_n_forward_items_copy(const Ewk_Back_Forward_List *list, int limit);
+
+/**
+ * Creates the list containing the items preceding the current item.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ *
+ * @param list the back-forward list instance
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ *            the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ *            to free the items
+ *
+ * @see ewk_back_forward_list_n_back_items_copy
+ */
+#define ewk_back_forward_list_back_items_copy(list) \
+    ewk_back_forward_list_n_back_items_copy(list, -1)
+
+/**
+ * Creates the list containing the items following the current item.
+ *
+ * The @c Ewk_Back_Forward_List_Item elements are located in the result list starting with the oldest one.
+ *
+ * @param list the back-forward list instance
+ *
+ * @return @c Eina_List containing @c Ewk_Back_Forward_List_Item elements or @c NULL in case of error,
+ *            the Eina_List and its items should be freed after use. Use ewk_back_forward_list_item_unref()
+ *            to free the items
+ *
+ * @see ewk_back_forward_list_n_forward_items_copy
+ */
+#define ewk_back_forward_list_forward_items_copy(list) \
+    ewk_back_forward_list_n_forward_items_copy(list, -1)
+
 #ifdef __cplusplus
 }
 #endif
index af10981..68c15db 100644 (file)
@@ -41,6 +41,7 @@ extern EWK2UnitTestEnvironment* environment;
 
 static const char title1[] = "Page1";
 static const char title2[] = "Page2";
+static const char title3[] = "Page3";
 
 static void serverCallbackNavigation(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
 {
@@ -78,6 +79,13 @@ static inline WKEinaSharedString urlFromTitle(EWK2UnitTestServer* httpServer, co
     return res;
 }
 
+static inline void freeEinaList(Eina_List* list)
+{
+    void* data = 0;
+    EINA_LIST_FREE(list, data)
+        ewk_back_forward_list_item_unref(static_cast<Ewk_Back_Forward_List_Item*>(data));
+}
+
 TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get)
 {
     const char* url = environment->defaultTestPageUrl();
@@ -181,3 +189,83 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_count)
 
     EXPECT_EQ(ewk_back_forward_list_count(backForwardList), 2);
 }
+
+TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_back_items_copy)
+{
+    OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
+    httpServer->run(serverCallbackNavigation);
+
+    WKEinaSharedString url1 = urlFromTitle(httpServer.get(), title1);
+    loadUrlSync(url1);
+    ASSERT_STREQ(ewk_view_title_get(webView()), title1);
+
+    WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2);
+    loadUrlSync(url2);
+    ASSERT_STREQ(ewk_view_title_get(webView()), title2);
+
+    loadUrlSync(urlFromTitle(httpServer.get(), title3));
+    ASSERT_STREQ(ewk_view_title_get(webView()), title3);
+
+    Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
+    ASSERT_TRUE(backForwardList);
+
+    Eina_List* backList = ewk_back_forward_list_n_back_items_copy(backForwardList, 1);
+    ASSERT_TRUE(backList);
+    ASSERT_EQ(eina_list_count(backList), 1);
+    checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 0)), title2, url2, url2);
+    freeEinaList(backList);
+
+    // Check '0' limit.
+    backList = ewk_back_forward_list_n_back_items_copy(backForwardList, 0);
+    ASSERT_FALSE(backList);
+
+    backList = ewk_back_forward_list_n_back_items_copy(backForwardList, -1);
+    ASSERT_TRUE(backList);
+    ASSERT_EQ(eina_list_count(backList), 2);
+    checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 0)), title1, url1, url1);
+    checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 1)), title2, url2, url2);
+    freeEinaList(backList);
+}
+
+TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_forward_items_copy)
+{
+    OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
+    httpServer->run(serverCallbackNavigation);
+
+    loadUrlSync(urlFromTitle(httpServer.get(), title1));
+    ASSERT_STREQ(ewk_view_title_get(webView()), title1);
+
+    WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2);
+    loadUrlSync(url2);
+    ASSERT_STREQ(ewk_view_title_get(webView()), title2);
+
+    WKEinaSharedString url3 = urlFromTitle(httpServer.get(), title3);
+    loadUrlSync(url3);
+    ASSERT_STREQ(ewk_view_title_get(webView()), title3);
+
+    // Go back to Page1.
+    ewk_view_back(webView());
+    waitUntilTitleChangedTo(title2);
+    ewk_view_back(webView());
+    waitUntilTitleChangedTo(title1);
+
+    Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
+    ASSERT_TRUE(backForwardList);
+
+    Eina_List* forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, 1);
+    ASSERT_TRUE(forwardList);
+    ASSERT_EQ(eina_list_count(forwardList), 1);
+    checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 0)), title2, url2, url2);
+    freeEinaList(forwardList);
+
+    // Check '0' limit.
+    forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, 0);
+    ASSERT_FALSE(forwardList);
+
+    forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, -1);
+    ASSERT_TRUE(forwardList);
+    ASSERT_EQ(eina_list_count(forwardList), 2);
+    checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 0)), title2, url2, url2);
+    checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 1)), title3, url3, url3);
+    freeEinaList(forwardList);
+}