[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_history_nth_item_get.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_history_nth_item_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_history_nth_item_get::TEST_URL1 = "ewk_history/page1.html";
19 const char* const utc_blink_ewk_history_nth_item_get::TEST_URL2 = "ewk_history/page2.html";
20 const char* const utc_blink_ewk_history_nth_item_get::TEST_URL3 = "ewk_history/page3.html";
21
22 TEST_F(utc_blink_ewk_history_nth_item_get, EXISTING_HISTORY)
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   // go back
36   ASSERT_EQ(EINA_TRUE, ewk_view_back(GetEwkWebView()));
37
38   Ewk_History *history = ewk_view_history_get(GetEwkWebView());
39   ASSERT_TRUE(history);
40
41   // get current item
42   Ewk_History_Item *item = ewk_history_nth_item_get(history, 0);
43
44   ASSERT_TRUE(item);
45
46   ASSERT_STREQ(expectedTitle2.c_str(), ewk_history_item_title_get(item));
47   ASSERT_STREQ(GetResourceUrl(TEST_URL2).c_str(), ewk_history_item_uri_get(item));
48
49   // get back item
50   item = ewk_history_nth_item_get(history, -1);
51
52   ASSERT_TRUE(item);
53
54   ASSERT_STREQ(expectedTitle1.c_str(), ewk_history_item_title_get(item));
55   ASSERT_STREQ(GetResourceUrl(TEST_URL1).c_str(), ewk_history_item_uri_get(item));
56
57   // get forward item
58   item = ewk_history_nth_item_get(history, 1);
59
60   ASSERT_TRUE(item);
61
62   ASSERT_STREQ(expectedTitle3.c_str(), ewk_history_item_title_get(item));
63   ASSERT_STREQ(GetResourceUrl(TEST_URL3).c_str(), ewk_history_item_uri_get(item));
64
65   // get out of bounds item (positive index)
66   item = ewk_history_nth_item_get(history, 10);
67   ASSERT_FALSE(item);
68
69   // get out of bounds item (negative index)
70   item = ewk_history_nth_item_get(history, -10);
71   ASSERT_FALSE(item);
72
73   ewk_history_free(history);
74 }
75
76 TEST_F(utc_blink_ewk_history_nth_item_get, EMPTY_HISTORY)
77 {
78   Ewk_History *history = ewk_view_history_get(GetEwkWebView());
79   ASSERT_TRUE(history);
80
81   ASSERT_FALSE(ewk_history_nth_item_get(history, 0));
82
83   ewk_history_free(history);
84 }
85
86 TEST_F(utc_blink_ewk_history_nth_item_get, NULL_HISTORY)
87 {
88   ASSERT_FALSE(ewk_history_nth_item_get(NULL, 0));
89 }