[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_cb_title_changed.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 #define TITLE1 "TestTitle1"
8 #define TITLE2 "TestTitle2"
9
10 class utc_blink_cb_title_changed : public utc_blink_ewk_base
11 {
12 protected:
13   utc_blink_cb_title_changed()
14     : changed_title(NULL)
15   {
16   }
17
18   ~utc_blink_cb_title_changed() override {
19     free(changed_title);
20     changed_title = NULL;
21   }
22
23   void LoadFinished(Evas_Object*) override {
24     EventLoopStop(utc_blink_ewk_base::Failure); // won't fail the test if EventLoopStop was already called
25   }
26
27   static void title_changed_cb(void* data, Evas_Object*, void* eventInfo)
28   {
29     utc_blink_cb_title_changed* owner = NULL;
30     OwnerFromVoid(data, &owner);
31     ASSERT_TRUE(owner);
32
33     free(owner->changed_title);
34     owner->changed_title = NULL;
35
36     if (eventInfo) {
37       char* new_title = static_cast<char*>(eventInfo);
38       owner->changed_title = strdup(new_title);
39     }
40
41     owner->EventLoopStop(Success);
42   }
43
44   void PostSetUp() override {
45     evas_object_smart_callback_add(GetEwkWebView(), "title,changed", title_changed_cb, this);
46   }
47
48   void PreTearDown() override {
49     evas_object_smart_callback_del(GetEwkWebView(), "title,changed", title_changed_cb);
50   }
51
52 protected:
53   char* changed_title;
54 };
55
56 /**
57  * @brief Test case for changing non-empty title to other non-empty title
58  */
59 TEST_F(utc_blink_cb_title_changed, TITLE_CHANGE)
60 {
61   const char textStyleHTML[] =
62           "<html>"
63           "<head><title>" TITLE1 "</title>"
64           "<script>"
65           "window.onload=function(){"
66           "document.title=\"" TITLE2 "\";"
67           "}"
68           "</script>"
69           "</head>"
70           "<body></body>"
71           "</html>";
72
73   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), textStyleHTML, 0, 0));
74   ASSERT_EQ(Success, EventLoopStart());
75   ASSERT_STREQ(TITLE1, changed_title);
76   ASSERT_EQ(Success, EventLoopStart());
77   ASSERT_STREQ(TITLE2, changed_title);
78 }
79
80 /**
81  * @brief Test case for loading page with no title set
82  */
83 TEST_F(utc_blink_cb_title_changed, NO_TITLE)
84 {
85   const char textStyleHTML[] =
86           "<html>"
87           "<head></head>"
88           "<body></body>"
89           "</html>";
90
91   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), textStyleHTML, 0, 0));
92   // we don't want the callback to be actually called, so the Failure is an expected result
93   ASSERT_EQ(Failure, EventLoopStart());
94 }
95
96 /**
97  * @brief Test case for changing non-empty title to null title
98  */
99 TEST_F(utc_blink_cb_title_changed, NULL_TITLE)
100 {
101   const char textStyleHTML[] =
102           "<html>"
103           "<head><title>" TITLE1 "</title>"
104           "<script>"
105           "window.onload=function(){"
106               "document.title=null;"
107           "}"
108           "</script>"
109           "</head>"
110           "<body></body>"
111           "</html>";
112
113   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), textStyleHTML, 0, 0));
114   ASSERT_EQ(Success, EventLoopStart());
115   ASSERT_STREQ(TITLE1, changed_title);
116   ASSERT_EQ(Success, EventLoopStart());
117   ASSERT_STREQ("", changed_title); // after second change should be empty string
118 }