4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * This library is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation; either version 2.1 of the License, or (at your option)
11 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, write to the Free Software Foundation, Inc., 51
18 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "utc_blink_ewk_base.h"
24 class utc_blink_ewk_context_local_file_system_delete : public utc_blink_ewk_base
27 utc_blink_ewk_context_local_file_system_delete()
28 : utc_blink_ewk_base()
31 , origin_to_delete(NULL)
35 ~utc_blink_ewk_context_local_file_system_delete()
37 origin_to_delete = NULL;
43 static char* args[]={"--allow-file-access-from-files"};
44 ewk_set_arguments(1,args);
49 utc_message("[PostSetUp] :: ");
50 ctx = ewk_view_context_get(GetEwkWebView());
51 evas_object_smart_callback_add(GetEwkWebView(), "title,changed", title_changed_cb, this);
56 evas_object_smart_callback_del(GetEwkWebView(), "title,changed", title_changed_cb);
59 static void origins_get_cb(Eina_List* origins, void* user_data)
61 utc_message("[origins_get_cb] :: %p, %p", origins, user_data);
62 ASSERT_TRUE(user_data);
63 utc_blink_ewk_context_local_file_system_delete* owner = static_cast<utc_blink_ewk_context_local_file_system_delete*>(user_data);
64 owner->SetOrigins(origins);
65 owner->EventLoopStop(Success);
68 static void title_changed_cb(void* user_data, Evas_Object* webView, void* event_info)
70 utc_message("[title_changed_cb] :: \n");
72 ASSERT_TRUE(user_data);
73 utc_blink_ewk_context_local_file_system_delete* owner = static_cast<utc_blink_ewk_context_local_file_system_delete*>(user_data);
75 if (!strcmp("SUCCESS", (char*)event_info)) {
76 owner->EventLoopStop(Success);
78 else if (!strcmp("FAILURE", (char*)event_info)) {
79 owner->EventLoopStop(Failure);
83 void SetOrigins(Eina_List* new_origins)
85 utc_message("[SetOrigins] :: ");
86 if (new_origins != origins) {
88 ewk_context_origins_free(origins);
90 origins = new_origins;
94 Eina_Bool HasOrigin(const char* protocol, const char* host, uint16_t port)
96 Eina_List* list = NULL;
97 void* list_data = NULL;
98 EINA_LIST_FOREACH(origins, list, list_data) {
99 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(list_data);
100 const char* protocol_ = ewk_security_origin_protocol_get(origin);
101 const char* host_ = ewk_security_origin_host_get(origin);
102 uint16_t port_ = ewk_security_origin_port_get(origin);
103 if (!strcmp(protocol_, protocol) && !strcmp(host_, host) && (port_ == port)) {
104 origin_to_delete = origin;
111 void GetOrigins(int expected_count)
113 utc_message("[GetOrigins] :: %d", eina_list_count(origins));
114 // web database operations are async, we must wait for changes to propagate
115 for (int i = 0; i < 3; ++i) {
116 if (EINA_TRUE != ewk_context_local_file_system_origins_get(ctx, origins_get_cb, this))
119 if (Success != EventLoopStart())
122 if (expected_count == eina_list_count(origins))
125 if (!EventLoopWait(3.0))
131 static const char* const URL;
132 static const char* const expected_protocol;
133 static const char* const expected_host;
134 static const uint16_t expected_port;
138 Ewk_Security_Origin* origin_to_delete;
142 const char* const utc_blink_ewk_context_local_file_system_delete::URL = "ewk_context_local_file_system/sample_context_local_file_system_write.html";
143 const char* const utc_blink_ewk_context_local_file_system_delete::expected_protocol = "file";
144 const char* const utc_blink_ewk_context_local_file_system_delete::expected_host = "";
145 const uint16_t utc_blink_ewk_context_local_file_system_delete::expected_port = 65535;
148 * @brief Tests if there is possibility to get local file system origins
150 TEST_F(utc_blink_ewk_context_local_file_system_delete, POS_TEST)
152 // Delete the local file system and check if there are no origins left
153 ASSERT_EQ(EINA_TRUE, ewk_context_local_file_system_all_delete(ctx));
155 ASSERT_EQ(0, eina_list_count(origins));
156 ASSERT_TRUE(origins == NULL);
158 // Create a local file system
159 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(URL).c_str()));
160 ASSERT_EQ(Success, EventLoopStart());
162 // Check if origin is loaded
164 ASSERT_EQ(EINA_TRUE, HasOrigin(expected_protocol, expected_host, expected_port));
166 // Delete selected origin
167 ASSERT_TRUE(origin_to_delete);
168 ASSERT_EQ(EINA_TRUE, ewk_context_local_file_system_delete(ctx, origin_to_delete));
170 // Check if there is no expected origin
172 ASSERT_EQ(EINA_FALSE, HasOrigin(expected_protocol, expected_host, expected_port));
176 * @brief Tests if cannot delete local file systems when origin is null
178 TEST_F(utc_blink_ewk_context_local_file_system_delete, NEG_TEST1)
180 ASSERT_EQ(EINA_FALSE, ewk_context_local_file_system_delete(ctx, NULL));
184 * @brief Tests if cannot delete local file systems when context is null
186 TEST_F(utc_blink_ewk_context_local_file_system_delete, NEG_TEST2)
188 ASSERT_EQ(EINA_FALSE, ewk_context_local_file_system_delete(NULL, NULL));