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 /* Define those macros _before_ you include the utc_blink_ewk.h header file. */
7 #include "utc_blink_ewk_base.h"
9 class utc_blink_ewk_context_web_storage_origin_delete: public utc_blink_ewk_base {
11 utc_blink_ewk_context_web_storage_origin_delete()
12 : utc_blink_ewk_base()
18 ~utc_blink_ewk_context_web_storage_origin_delete() override {
22 void PostSetUp() override {
23 ctx = ewk_view_context_get(GetEwkWebView());
24 ASSERT_TRUE(ctx != NULL);
26 // we want empty web storage at test start
27 ASSERT_EQ(EINA_TRUE, ewk_context_web_storage_delete_all(ctx));
30 ASSERT_TRUE(origins == NULL);
33 void LoadFinished(Evas_Object* webview) override { EventLoopStop(Success); }
35 static void origins_get_cb(Eina_List* origins, void* user_data)
37 utc_message("origins_get_cb: %p, %p", origins, user_data);
39 ewk_context_origins_free(origins);
43 utc_blink_ewk_context_web_storage_origin_delete* owner = static_cast<utc_blink_ewk_context_web_storage_origin_delete*>(user_data);
45 owner->SetOrigins(origins);
46 owner->EventLoopStop(Success);
49 Ewk_Security_Origin* FindSecurityOrigin(const char* origin_host)
51 utc_message("FindSecurityOrigin: %s in %p", origin_host, origins);
52 Ewk_Security_Origin* retval = NULL;
54 if(origins && origin_host) {
57 EINA_LIST_FOREACH(origins, it, vorigin) {
58 Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(vorigin);
60 const char* host = ewk_security_origin_host_get(origin);
61 if (host && strcmp(host, origin_host) == 0) {
71 void SetOrigins(Eina_List* new_origins)
73 if (new_origins != origins) {
75 ewk_context_origins_free(origins);
78 origins = new_origins;
82 void GetOrigins(int expected_count)
84 // web storage operations are async, we must wait for changes to propagate
85 for (int i = 0; i < 3; ++i) {
86 if (EINA_TRUE != ewk_context_web_storage_origins_get(ctx, origins_get_cb, this)) {
90 if (Success != EventLoopStart()) {
94 if (expected_count == eina_list_count(origins)) {
98 if (!EventLoopWait(3.0)) {
105 static const char* const web_storage_sample_resource;
106 static const char* const web_storage_sample_url;
107 static const char* const sample_origin;
114 const char* const utc_blink_ewk_context_web_storage_origin_delete::web_storage_sample_resource = "ewk_context_web_storage/web_storage_create_simple.html";
115 const char* const utc_blink_ewk_context_web_storage_origin_delete::web_storage_sample_url = "http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_webstorage_local";
116 const char* const utc_blink_ewk_context_web_storage_origin_delete::sample_origin = "www.w3schools.com";
119 * @brief Tests if can delete all web storages
121 TEST_F(utc_blink_ewk_context_web_storage_origin_delete, POS_TEST)
123 // load some pages with web storage
124 std::string resurl = GetResourceUrl(web_storage_sample_resource);
125 utc_message("Loading resource: %s", resurl.c_str());
126 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), resurl.c_str()));
127 ASSERT_EQ(Success, EventLoopStart());
129 utc_message("Loading web page: %s", web_storage_sample_url);
130 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), web_storage_sample_url));
131 ASSERT_EQ(Success, EventLoopStart());
134 ASSERT_TRUE(origins != NULL);
135 ASSERT_EQ(2, eina_list_count(origins));
137 // remove sample origin
138 Ewk_Security_Origin* origin = FindSecurityOrigin(sample_origin);
139 ASSERT_TRUE(origin != NULL);
141 ASSERT_EQ(EINA_TRUE, ewk_context_web_storage_origin_delete(ctx, origin));
144 ASSERT_TRUE(origins != NULL);
145 ASSERT_EQ(1, eina_list_count(origins));
147 // verify security origin was removed
148 origin = FindSecurityOrigin(sample_origin);
149 ASSERT_TRUE(origin == NULL);
153 * @brief Tests if returns false when context is null.
155 TEST_F(utc_blink_ewk_context_web_storage_origin_delete, invalid_args)
157 EXPECT_EQ(EINA_FALSE, ewk_context_web_storage_origin_delete(NULL, NULL));
158 EXPECT_EQ(EINA_FALSE, ewk_context_web_storage_origin_delete(ctx, NULL));