1 // Copyright 2014-2016 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"
8 class utc_blink_ewk_context_local_file_system_delete
9 : public utc_blink_ewk_base {
11 utc_blink_ewk_context_local_file_system_delete()
12 : utc_blink_ewk_base(),
15 origin_to_delete(nullptr) {}
17 ~utc_blink_ewk_context_local_file_system_delete() override {
21 void PreSetUp() override { AllowFileAccessFromFiles(); }
23 void PostSetUp() override {
24 ctx = ewk_view_context_get(GetEwkWebView());
25 evas_object_smart_callback_add(GetEwkWebView(), "title,changed",
26 title_changed_cb, this);
29 void PreTearDown() override {
30 evas_object_smart_callback_del(GetEwkWebView(), "title,changed",
34 static void origins_get_cb(Eina_List* origins, void* user_data)
36 utc_message("[origins_get_cb] :: %p, %p", origins, user_data);
37 ASSERT_TRUE(user_data);
38 utc_blink_ewk_context_local_file_system_delete* owner = static_cast<utc_blink_ewk_context_local_file_system_delete*>(user_data);
39 owner->SetOrigins(origins);
40 owner->EventLoopStop(Success);
43 void SetOrigins(Eina_List* new_origins) {
44 utc_message("[SetOrigins] :: ");
45 if (new_origins != origins) {
47 ewk_context_origins_free(origins);
49 origins = new_origins;
53 Eina_Bool FindOriginToDelete(const char* expected_protocol,
54 const char* expected_host,
55 uint16_t expected_port) {
56 Eina_List* list = nullptr;
57 void* list_data = nullptr;
58 EINA_LIST_FOREACH(origins, list, list_data) {
59 Ewk_Security_Origin* origin = (Ewk_Security_Origin*)(list_data);
60 const char* protocol = ewk_security_origin_protocol_get(origin);
61 const char* host = ewk_security_origin_host_get(origin);
62 uint16_t port = ewk_security_origin_port_get(origin);
64 "[FindOriginToDelete] :: "
65 "protocol: %s :: host: %s :: port: %" PRIu16,
66 protocol, host, port);
67 if (!strcmp(protocol, expected_protocol) &&
68 !strcmp(host, expected_host) && (port == expected_port)) {
69 origin_to_delete = origin;
76 void GetOrigins(int expected_count) {
77 utc_message("[GetOrigins] :: %d", eina_list_count(origins));
78 // web database operations are async, we must wait for changes to propagate
79 ASSERT_EQ(EINA_TRUE, ewk_context_local_file_system_origins_get(
80 ctx, origins_get_cb, this));
81 ASSERT_EQ(Success, EventLoopStart());
82 ASSERT_EQ(expected_count, eina_list_count(origins));
85 static void origins_get_cb(Eina_List* origins, void* data) {
86 utc_message("[origins_get_cb] :: origins: %p, data: %p", origins, data);
89 static_cast<utc_blink_ewk_context_local_file_system_delete*>(data);
90 owner->SetOrigins(origins);
91 owner->EventLoopStop(Success);
95 static void title_changed_cb(void* data,
98 utc_message("[title_changed_cb] :: data: %p", data);
101 static_cast<utc_blink_ewk_context_local_file_system_delete*>(data);
102 if (!strcmp("SUCCESS", static_cast<char*>(event_info))) {
103 owner->EventLoopStop(Success);
104 } else if (!strcmp("FAILURE", static_cast<char*>(event_info))) {
105 owner->EventLoopStop(Failure);
112 Ewk_Security_Origin* origin_to_delete;
116 * @brief Tests if there is possibility to get local file system origins
118 TEST_F(utc_blink_ewk_context_local_file_system_delete, POS) {
119 std::string url = GetResourceUrl(
120 "ewk_context_local_file_system/"
121 "sample_context_local_file_system_write.html");
122 const char* const expected_protocol = "file";
123 const char* const expected_host = "";
124 const uint16_t expected_port = 0;
125 // Delete the local file system and check if there are no origins left
126 ASSERT_EQ(EINA_TRUE, ewk_context_local_file_system_all_delete(ctx));
129 // Create a local file system
130 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), url.c_str()));
131 ASSERT_EQ(Success, EventLoopStart());
134 // Check if origin is loaded
137 FindOriginToDelete(expected_protocol, expected_host, expected_port));
138 ASSERT_TRUE(origin_to_delete);
140 // Delete selected origin
142 ewk_context_local_file_system_delete(ctx, origin_to_delete));
145 // Check if there is no expected origin
148 FindOriginToDelete(expected_protocol, expected_host, expected_port));
152 * @brief Negative test for ewk_context_local_file_system_delete(). Checking
153 * whether function works properly with null origin value.
155 TEST_F(utc_blink_ewk_context_local_file_system_delete, NEG_ORIGIN_NULL) {
156 ASSERT_EQ(EINA_FALSE, ewk_context_local_file_system_delete(ctx, nullptr));
160 * @brief Negative test for ewk_context_local_file_system_delete(). Checking
161 * whether function works properly with null context and origin value.
163 TEST_F(utc_blink_ewk_context_local_file_system_delete,
164 NEG_ORIGIN_AND_CONTEXT_NULL) {
165 ASSERT_EQ(EINA_FALSE, ewk_context_local_file_system_delete(nullptr, nullptr));