Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[EFL][wk2] Add unit tests for back-forward list API
https://bugs.webkit.org/show_bug.cgi?id=92617

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

Added unit tests covering the existing EFL WK2 back-forward list API.

* PlatformEfl.cmake:
* UIProcess/API/efl/tests/resources/default_test_page.html:
* UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp: Added.
(serverCallbackNavigation):
(checkItem):
(urlFromTitle):
(TEST_F):

Canonical link: https://commits.webkit.org/112156@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125905 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Mikhail Pozdnyakov authored and webkit-commit-queue committed Aug 17, 2012
1 parent 35063c3 commit add1138
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,20 @@
2012-08-17 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>

[EFL][wk2] Add unit tests for back-forward list API
https://bugs.webkit.org/show_bug.cgi?id=92617

Reviewed by Kenneth Rohde Christiansen.

Added unit tests covering the existing EFL WK2 back-forward list API.

* PlatformEfl.cmake:
* UIProcess/API/efl/tests/resources/default_test_page.html:
* UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp: Added.
(serverCallbackNavigation):
(checkItem):
(urlFromTitle):
(TEST_F):

2012-08-17 Jeff Miller <jeffm@apple.com>

UserMessageEncoder::baseEncode() should ASSERT when attempting to encode a non-shareable image
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit2/PlatformEfl.cmake
Expand Up @@ -265,6 +265,7 @@ TARGET_LINK_LIBRARIES(ewk2UnitTestUtils ${EWK2UnitTests_LIBRARIES})
# The "ewk" on the test name needs to be suffixed with "2", otherwise it
# will clash with tests from the WebKit 1 test suite.
SET(EWK2UnitTests_BINARIES
test_ewk2_back_forward_list
test_ewk2_context
test_ewk2_cookie_manager
test_ewk2_download_job
Expand Down
@@ -1,4 +1,5 @@
<HTML>
<title>Default Testing Web Page</title>
<BODY>
<H2 align="center">EFL Unit Tests</H2>
<H2 align="center">Default Testing Web Page</H2>
Expand Down
183 changes: 183 additions & 0 deletions Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp
@@ -0,0 +1,183 @@
/*
* Copyright (C) 2012 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"

#include "UnitTestUtils/EWK2UnitTestBase.h"
#include "UnitTestUtils/EWK2UnitTestEnvironment.h"
#include "UnitTestUtils/EWK2UnitTestServer.h"
#include "WKEinaSharedString.h"
#include <EWebKit2.h>
#include <gtest/gtest.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>

using namespace EWK2UnitTest;
using namespace WTF;

extern EWK2UnitTestEnvironment* environment;

static const char title1[] = "Page1";
static const char title2[] = "Page2";

static void serverCallbackNavigation(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
if (message->method != SOUP_METHOD_GET) {
soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
return;
}

soup_message_set_status(message, SOUP_STATUS_OK);

Eina_Strbuf* body = eina_strbuf_new();
eina_strbuf_append_printf(body, "<html><title>%s</title><body>%s</body></html>", path + 1, path + 1);
const size_t bodyLength = eina_strbuf_length_get(body);
soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, eina_strbuf_string_steal(body), bodyLength);
eina_strbuf_free(body);

soup_message_body_complete(message->response_body);
}

static inline void checkItem(Ewk_Back_Forward_List_Item* item, const char* title, const char* uri, const char* originalURI)
{
ASSERT_TRUE(item);
EXPECT_STREQ(uri, ewk_back_forward_list_item_uri_get(item));
EXPECT_STREQ(title, ewk_back_forward_list_item_title_get(item));
EXPECT_STREQ(originalURI, ewk_back_forward_list_item_original_uri_get(item));
}

static inline WKEinaSharedString urlFromTitle(EWK2UnitTestServer* httpServer, const char* title)
{
Eina_Strbuf* path = eina_strbuf_new();
eina_strbuf_append_printf(path, "/%s", title);
WKEinaSharedString res = httpServer->getURIForPath(eina_strbuf_string_get(path)).data();
eina_strbuf_free(path);

return res;
}

TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get)
{
const char* url = environment->defaultTestPageUrl();
loadUrlSync(url);
Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
ASSERT_TRUE(backForwardList);

Ewk_Back_Forward_List_Item* currentItem = ewk_back_forward_list_current_item_get(backForwardList);
checkItem(currentItem, ewk_view_title_get(webView()), url, url);

Ewk_Back_Forward_List_Item* anotherCurrentItem = ewk_back_forward_list_current_item_get(backForwardList);
ASSERT_EQ(currentItem, anotherCurrentItem);
}

TEST_F(EWK2UnitTestBase, ewk_back_forward_list_previous_item_get)
{
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);

loadUrlSync(urlFromTitle(httpServer.get(), title2));
ASSERT_STREQ(ewk_view_title_get(webView()), title2);

Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
ASSERT_TRUE(backForwardList);

Ewk_Back_Forward_List_Item* previousItem = ewk_back_forward_list_previous_item_get(backForwardList);
checkItem(previousItem, title1, url1, url1);

Ewk_Back_Forward_List_Item* anotherPreviousItem = ewk_back_forward_list_previous_item_get(backForwardList);
ASSERT_EQ(previousItem, anotherPreviousItem);
}

TEST_F(EWK2UnitTestBase, ewk_back_forward_list_next_item_get)
{
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);

// Go back to Page1.
ewk_view_back(webView());
waitUntilTitleChangedTo(title1);

Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
ASSERT_TRUE(backForwardList);

Ewk_Back_Forward_List_Item* nextItem = ewk_back_forward_list_next_item_get(backForwardList);
checkItem(nextItem, title2, url2, url2);

Ewk_Back_Forward_List_Item* anotherNextItem = ewk_back_forward_list_next_item_get(backForwardList);
ASSERT_EQ(nextItem, anotherNextItem);
}

TEST_F(EWK2UnitTestBase, ewk_back_forward_list_item_at_index_get)
{
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);

loadUrlSync(urlFromTitle(httpServer.get(), title2));
ASSERT_STREQ(ewk_view_title_get(webView()), title2);

Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
ASSERT_TRUE(backForwardList);

Ewk_Back_Forward_List_Item* previousItem = ewk_back_forward_list_item_at_index_get(backForwardList, -1);
checkItem(previousItem, title1, url1, url1);

Ewk_Back_Forward_List_Item* anotherPreviousItem = ewk_back_forward_list_item_at_index_get(backForwardList, -1);
ASSERT_EQ(previousItem, anotherPreviousItem);

Ewk_Back_Forward_List_Item* nonExistingItem = ewk_back_forward_list_item_at_index_get(backForwardList, 10);
ASSERT_FALSE(nonExistingItem);
}

TEST_F(EWK2UnitTestBase, ewk_back_forward_list_count)
{
OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
httpServer->run(serverCallbackNavigation);

loadUrlSync(urlFromTitle(httpServer.get(), title1));
ASSERT_STREQ(ewk_view_title_get(webView()), title1);

loadUrlSync(urlFromTitle(httpServer.get(), title2));
ASSERT_STREQ(ewk_view_title_get(webView()), title2);

Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView());
ASSERT_TRUE(backForwardList);

EXPECT_EQ(ewk_back_forward_list_count(backForwardList), 2);
}

0 comments on commit add1138

Please sign in to comment.