1 // Copyright 2015 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 #define SAMPLE_ORIGIN "jmajnert.github.io"
10 const char* const WEB_STORAGE_SAMPLE_URL =
11 "http://" SAMPLE_ORIGIN
13 "localStorage_test/web_storage_create_simple.html";
15 class utc_blink_ewk_context_web_storage_usage_for_origin_get
16 : public utc_blink_ewk_base {
18 utc_blink_ewk_context_web_storage_usage_for_origin_get()
19 : utc_blink_ewk_base(), context_(nullptr), usage_(0), neg_test_(false) {}
21 void PostSetUp() override {
22 ASSERT_TRUE(context_ = ewk_view_context_get(GetEwkWebView()));
23 // we want empty web storage at test start
24 ASSERT_TRUE(ewk_context_web_storage_delete_all(context_));
27 void LoadFinished(Evas_Object*) override { EventLoopStop(Success); }
29 void NegTest(Eina_List* origins) {
30 utc_message("NegTest: %p", origins);
32 Ewk_Security_Origin* origin = nullptr;
33 Ewk_Security_Origin* chosen_origin = nullptr;
35 void* vorigin = nullptr;
36 EINA_LIST_FOREACH(origins, it, vorigin) {
37 origin = static_cast<Ewk_Security_Origin*>(vorigin);
39 const char* host = ewk_security_origin_host_get(origin);
40 if (host && !strcmp(host, SAMPLE_ORIGIN)) {
41 chosen_origin = origin;
46 EventLoopStop(Failure);
47 ASSERT_FALSE(ewk_context_web_storage_usage_for_origin_get(
48 nullptr, origin, usage_get_cb, this));
49 ASSERT_FALSE(ewk_context_web_storage_usage_for_origin_get(
50 context_, nullptr, usage_get_cb, this));
51 ASSERT_FALSE(ewk_context_web_storage_usage_for_origin_get(context_, origin,
53 EventLoopStop(Success);
56 void FindSecurityOrigin(Eina_List* origins) {
57 utc_message("FindSecurityOrigin: %p", origins);
59 Ewk_Security_Origin* origin = nullptr;
61 void* vorigin = nullptr;
62 EINA_LIST_FOREACH(origins, it, vorigin) {
63 origin = static_cast<Ewk_Security_Origin*>(vorigin);
65 const char* host = ewk_security_origin_host_get(origin);
66 if (host && !strcmp(host, SAMPLE_ORIGIN)) {
67 ASSERT_TRUE(ewk_context_web_storage_usage_for_origin_get(
68 context_, origin, usage_get_cb, this));
72 EventLoopStop(Failure);
75 static void origins_get_cb(Eina_List* origins, void* user_data) {
76 utc_message("origins_get_cb: %p, %p", origins, user_data);
78 ewk_context_origins_free(origins);
83 static_cast<utc_blink_ewk_context_web_storage_usage_for_origin_get*>(
87 self->EventLoopStop(Failure);
92 self->NegTest(origins);
94 self->FindSecurityOrigin(origins);
97 static void usage_get_cb(uint64_t usage, void* user_data) {
98 utc_message("usage_get_cb: %lu, %p", usage, user_data);
105 static_cast<utc_blink_ewk_context_web_storage_usage_for_origin_get*>(
108 self->usage_ = usage;
109 self->EventLoopStop(Success);
113 Ewk_Context* context_;
119 * @brief Tests if usage can be obtained when localstorage is used
121 TEST_F(utc_blink_ewk_context_web_storage_usage_for_origin_get, POS_TEST) {
122 utc_message("Loading web page: %s", WEB_STORAGE_SAMPLE_URL);
123 ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), WEB_STORAGE_SAMPLE_URL));
124 ASSERT_EQ(Success, EventLoopStart());
128 ewk_context_web_storage_origins_get(context_, origins_get_cb, this));
129 ASSERT_EQ(Success, EventLoopStart());
135 * @brief Tests if returns false when parameters are null.
137 TEST_F(utc_blink_ewk_context_web_storage_usage_for_origin_get, NEG_TEST) {
138 utc_message("Loading web page: %s", WEB_STORAGE_SAMPLE_URL);
139 ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), WEB_STORAGE_SAMPLE_URL));
140 ASSERT_EQ(Success, EventLoopStart());
145 ewk_context_web_storage_origins_get(context_, origins_get_cb, this));
146 ASSERT_EQ(Success, EventLoopStart());