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 #define TITLE1 "TestTitle1"
8 #define TITLE2 "TestTitle2"
10 class utc_blink_cb_title_changed : public utc_blink_ewk_base
13 utc_blink_cb_title_changed()
18 ~utc_blink_cb_title_changed() override {
23 void LoadFinished(Evas_Object*) override {
24 EventLoopStop(utc_blink_ewk_base::Failure); // won't fail the test if EventLoopStop was already called
27 static void title_changed_cb(void* data, Evas_Object*, void* eventInfo)
29 utc_blink_cb_title_changed* owner = NULL;
30 OwnerFromVoid(data, &owner);
33 free(owner->changed_title);
34 owner->changed_title = NULL;
37 char* new_title = static_cast<char*>(eventInfo);
38 owner->changed_title = strdup(new_title);
41 owner->EventLoopStop(Success);
44 void PostSetUp() override {
45 evas_object_smart_callback_add(GetEwkWebView(), "title,changed", title_changed_cb, this);
48 void PreTearDown() override {
49 evas_object_smart_callback_del(GetEwkWebView(), "title,changed", title_changed_cb);
57 * @brief Test case for changing non-empty title to other non-empty title
59 TEST_F(utc_blink_cb_title_changed, TITLE_CHANGE)
61 const char textStyleHTML[] =
63 "<head><title>" TITLE1 "</title>"
65 "window.onload=function(){"
66 "document.title=\"" TITLE2 "\";"
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);
81 * @brief Test case for loading page with no title set
83 TEST_F(utc_blink_cb_title_changed, NO_TITLE)
85 const char textStyleHTML[] =
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());
97 * @brief Test case for changing non-empty title to null title
99 TEST_F(utc_blink_cb_title_changed, NULL_TITLE)
101 const char textStyleHTML[] =
103 "<head><title>" TITLE1 "</title>"
105 "window.onload=function(){"
106 "document.title=null;"
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