[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_back_forward_list_item_at_index_get_func.cpp
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.
4
5 #include "utc_blink_ewk_base.h"
6
7 class utc_blink_ewk_back_forward_list_item_at_index_get : public utc_blink_ewk_base
8 {
9 protected:
10  void LoadFinished(Evas_Object*) override { EventLoopStop(Success); }
11
12 protected:
13   static const char* const TEST_URL1;
14   static const char* const TEST_URL2;
15   static const char* const TEST_URL3;
16 };
17
18 const char* const utc_blink_ewk_back_forward_list_item_at_index_get::TEST_URL1 = "ewk_history/page1.html";
19 const char* const utc_blink_ewk_back_forward_list_item_at_index_get::TEST_URL2 = "ewk_history/page2.html";
20 const char* const utc_blink_ewk_back_forward_list_item_at_index_get::TEST_URL3 = "ewk_history/page3.html";
21
22 TEST_F(utc_blink_ewk_back_forward_list_item_at_index_get, POS_TEST)
23 {
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()));
34
35   // get back-forward list
36   Ewk_Back_Forward_List *list = ewk_view_back_forward_list_get(GetEwkWebView());
37   ASSERT_TRUE(list);
38
39   // get current item and check URL, original URL and title
40   Ewk_Back_Forward_List_Item *item = ewk_back_forward_list_item_at_index_get(list, 0);
41
42   ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_back_forward_list_item_url_get(item));
43   ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_back_forward_list_item_original_url_get(item));
44   ASSERT_STREQ(expectedTitle3.c_str(), ewk_back_forward_list_item_title_get(item));
45
46   // get item at -1 and check URL, original URL and title
47   item = ewk_back_forward_list_item_at_index_get(list, -1);
48
49   ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_back_forward_list_item_url_get(item));
50   ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_back_forward_list_item_original_url_get(item));
51   ASSERT_STREQ(expectedTitle2.c_str(), ewk_back_forward_list_item_title_get(item));
52
53   // get item at -2 and check URL, original URL and title
54   item = ewk_back_forward_list_item_at_index_get(list, -2);
55
56   ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_back_forward_list_item_url_get(item));
57   ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_back_forward_list_item_original_url_get(item));
58   ASSERT_STREQ(expectedTitle1.c_str(), ewk_back_forward_list_item_title_get(item));
59
60   // go back
61   ASSERT_EQ(EINA_TRUE, ewk_view_back(GetEwkWebView()));
62   ASSERT_EQ(Success, EventLoopStart());
63
64   // get item at 1 and check URL, original URL and title
65   item = ewk_back_forward_list_item_at_index_get(list, 1);
66
67   ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_back_forward_list_item_url_get(item));
68   ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_back_forward_list_item_original_url_get(item));
69   ASSERT_STREQ(expectedTitle3.c_str(), ewk_back_forward_list_item_title_get(item));
70
71   // get item at 0 and check URL, original URL and title
72   item = ewk_back_forward_list_item_at_index_get(list, 0);
73
74   ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_back_forward_list_item_url_get(item));
75   ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_back_forward_list_item_original_url_get(item));
76   ASSERT_STREQ(expectedTitle2.c_str(), ewk_back_forward_list_item_title_get(item));
77
78   // get item at -1 and check URL, original URL and title
79   item = ewk_back_forward_list_item_at_index_get(list, -1);
80
81   ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_back_forward_list_item_url_get(item));
82   ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_back_forward_list_item_original_url_get(item));
83   ASSERT_STREQ(expectedTitle1.c_str(), ewk_back_forward_list_item_title_get(item));
84
85   // go back
86   ASSERT_EQ(EINA_TRUE, ewk_view_back(GetEwkWebView()));
87   ASSERT_EQ(Success, EventLoopStart());
88
89   // get item at 2 and check URL, original URL and title
90   item = ewk_back_forward_list_item_at_index_get(list, 2);
91
92   ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_back_forward_list_item_url_get(item));
93   ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_back_forward_list_item_original_url_get(item));
94   ASSERT_STREQ(expectedTitle3.c_str(), ewk_back_forward_list_item_title_get(item));
95
96   // get item at 1 and check URL, original URL and title
97   item = ewk_back_forward_list_item_at_index_get(list, 1);
98
99   ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_back_forward_list_item_url_get(item));
100   ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_back_forward_list_item_original_url_get(item));
101   ASSERT_STREQ(expectedTitle2.c_str(), ewk_back_forward_list_item_title_get(item));
102
103   // get item at 0 and check URL, original URL and title
104   item = ewk_back_forward_list_item_at_index_get(list, 0);
105
106   ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_back_forward_list_item_url_get(item));
107   ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_back_forward_list_item_original_url_get(item));
108   ASSERT_STREQ(expectedTitle1.c_str(), ewk_back_forward_list_item_title_get(item));
109
110   // get item at 10 and it should be NULL
111   ASSERT_EQ(NULL, ewk_back_forward_list_item_at_index_get(list, 10));
112
113   // get item at -10 and it should be NULL
114   ASSERT_EQ(NULL, ewk_back_forward_list_item_at_index_get(list, -10));
115 }
116
117 TEST_F(utc_blink_ewk_back_forward_list_item_at_index_get, EMPTY_TEST)
118 {
119   Ewk_Back_Forward_List *list = ewk_view_back_forward_list_get(GetEwkWebView());
120   ASSERT_TRUE(list);
121   ASSERT_EQ(NULL, ewk_back_forward_list_item_at_index_get(list, 0));
122   ASSERT_EQ(NULL, ewk_back_forward_list_item_at_index_get(list, 1));
123   ASSERT_EQ(NULL, ewk_back_forward_list_item_at_index_get(list, -1));
124 }
125
126 TEST_F(utc_blink_ewk_back_forward_list_item_at_index_get, NULL_TEST)
127 {
128   ASSERT_EQ(NULL, ewk_back_forward_list_item_at_index_get(NULL, 0));
129 }
130