1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "utc_blink_ewk_base.h"
7 class utc_blink_ewk_view_history_get : public utc_blink_ewk_base
10 void LoadFinished(Evas_Object*) override { EventLoopStop(Success); }
13 static const char* const TEST_URL1;
14 static const char* const TEST_URL2;
15 static const char* const TEST_URL3;
18 const char* const utc_blink_ewk_view_history_get::TEST_URL1 = "ewk_history/page1.html";
19 const char* const utc_blink_ewk_view_history_get::TEST_URL2 = "ewk_history/page2.html";
20 const char* const utc_blink_ewk_view_history_get::TEST_URL3 = "ewk_history/page3.html";
22 TEST_F(utc_blink_ewk_view_history_get, POS_TEST)
24 // load 3 pages to get some interesting history
25 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(TEST_URL1).c_str()));
26 ASSERT_EQ(Success, EventLoopStart());
27 std::string expectedTitle1(ewk_view_title_get(GetEwkWebView()));
28 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(TEST_URL2).c_str()));
29 ASSERT_EQ(Success, EventLoopStart());
30 std::string expectedTitle2(ewk_view_title_get(GetEwkWebView()));
31 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(TEST_URL3).c_str()));
32 ASSERT_EQ(Success, EventLoopStart());
33 std::string expectedTitle3(ewk_view_title_get(GetEwkWebView()));
36 Ewk_History *history = ewk_view_history_get(GetEwkWebView());
39 // check back & forward count
40 ASSERT_EQ(2, ewk_history_back_list_length_get(history));
41 ASSERT_EQ(0, ewk_history_forward_list_length_get(history));
43 // get current item and chack URL and title
44 Ewk_History_Item *item = ewk_history_nth_item_get(history, 0);
46 ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_history_item_uri_get(item));
47 ASSERT_STREQ(expectedTitle3.c_str(), ewk_history_item_title_get(item));
50 ewk_history_free(history);
53 ASSERT_EQ(EINA_TRUE, ewk_view_back(GetEwkWebView()));
54 ASSERT_EQ(Success, EventLoopStart());
57 history = ewk_view_history_get(GetEwkWebView());
60 // check back & forward count
61 ASSERT_EQ(1, ewk_history_back_list_length_get(history));
62 ASSERT_EQ(1, ewk_history_forward_list_length_get(history));
64 // get current item and chack URL and title
65 item = ewk_history_nth_item_get(history, 0);
67 ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_history_item_uri_get(item));
68 ASSERT_STREQ(expectedTitle2.c_str(), ewk_history_item_title_get(item));
70 // get forward item and check URL and title
71 item = ewk_history_nth_item_get(history, 1);
73 ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_history_item_uri_get(item));
74 ASSERT_STREQ(expectedTitle3.c_str(), ewk_history_item_title_get(item));
76 // get back item and check URL and title
77 item = ewk_history_nth_item_get(history, -1);
79 ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_history_item_uri_get(item));
80 ASSERT_STREQ(expectedTitle1.c_str(), ewk_history_item_title_get(item));
83 ewk_history_free(history);
86 ewk_view_back(GetEwkWebView());
87 ASSERT_EQ(Success, EventLoopStart());
90 history = ewk_view_history_get(GetEwkWebView());
93 // check back & forward count
94 ASSERT_EQ(0, ewk_history_back_list_length_get(history));
95 ASSERT_EQ(2, ewk_history_forward_list_length_get(history));
97 // get current item and chack URL and title
98 item = ewk_history_nth_item_get(history, 0);
100 ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_history_item_uri_get(item));
101 ASSERT_STREQ(expectedTitle1.c_str(), ewk_history_item_title_get(item));
104 ewk_history_free(history);
107 TEST_F(utc_blink_ewk_view_history_get, EMPTY_TEST)
109 Ewk_History *history = ewk_view_history_get(GetEwkWebView());
110 ASSERT_TRUE(history);
111 ASSERT_EQ(0, ewk_history_back_list_length_get(history));
112 ASSERT_EQ(0, ewk_history_forward_list_length_get(history));
115 ewk_history_free(history);
118 TEST_F(utc_blink_ewk_view_history_get, NULL_TEST)
120 Ewk_History *history = ewk_view_history_get(NULL);
121 ASSERT_FALSE(history);