1 // Copyright 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"
7 #define SAMPLE_ORIGIN "dwieleverece.github.io"
8 const char* const WEB_DATABASE_SAMPLE_URL =
9 "https://" SAMPLE_ORIGIN "/tests/web_database_test/";
11 class utc_blink_ewk_context_web_database_usage_for_origin_get
12 : public utc_blink_ewk_base {
14 utc_blink_ewk_context_web_database_usage_for_origin_get()
21 usage_get_result_(false) {}
23 void PostSetUp() override {
24 ASSERT_TRUE(context_ = ewk_view_context_get(GetEwkWebView()));
25 // we want empty web database at test start
26 ASSERT_TRUE(ewk_context_web_database_delete_all(context_));
29 void LoadFinished(Evas_Object*) override { EventLoopStop(Success); }
31 void NegTest(Eina_List* origins) {
32 utc_message("NegTest: %p", origins);
34 Ewk_Security_Origin* origin = nullptr;
35 Ewk_Security_Origin* chosen_origin = nullptr;
37 void* vorigin = nullptr;
38 EINA_LIST_FOREACH(origins, it, vorigin) {
39 origin = static_cast<Ewk_Security_Origin*>(vorigin);
41 const char* host = ewk_security_origin_host_get(origin);
42 if (host && !strcmp(host, SAMPLE_ORIGIN)) {
43 chosen_origin = origin;
48 EventLoopStop(Failure);
49 neg_result_1_ = ewk_context_web_database_usage_for_origin_get(
50 nullptr, UsageGetCb, this, origin);
51 neg_result_2_ = ewk_context_web_database_usage_for_origin_get(
52 context_, nullptr, this, origin);
53 neg_result_3_ = ewk_context_web_database_usage_for_origin_get(
54 context_, UsageGetCb, this, nullptr);
55 EventLoopStop(Success);
58 void FindSecurityOrigin(Eina_List* origins) {
59 utc_message("FindSecurityOrigin: %p", origins);
61 Ewk_Security_Origin* origin = nullptr;
63 void* vorigin = nullptr;
64 EINA_LIST_FOREACH(origins, it, vorigin) {
65 origin = static_cast<Ewk_Security_Origin*>(vorigin);
67 const char* host = ewk_security_origin_host_get(origin);
68 if (host && !strcmp(host, SAMPLE_ORIGIN)) {
69 usage_get_result_ = ewk_context_web_database_usage_for_origin_get(
70 context_, UsageGetCb, this, origin);
71 EventLoopStop(Success);
74 EventLoopStop(Failure);
77 static void OriginsGetCb(Eina_List* origins, void* user_data) {
78 utc_message("OriginsGetCb: %p, %p", origins, user_data);
80 ewk_context_origins_free(origins);
85 static_cast<utc_blink_ewk_context_web_database_usage_for_origin_get*>(
89 self->EventLoopStop(Failure);
94 self->NegTest(origins);
96 self->FindSecurityOrigin(origins);
99 static void UsageGetCb(uint64_t usage, void* user_data) {
100 utc_message("UsageGetCb: %lu, %p", usage, user_data);
105 static_cast<utc_blink_ewk_context_web_database_usage_for_origin_get*>(
108 self->usage_ = usage;
109 self->EventLoopStop(Success);
113 Ewk_Context* context_;
119 bool usage_get_result_;
123 * @brief Tests if usage can be obtained when websql is used
125 TEST_F(utc_blink_ewk_context_web_database_usage_for_origin_get, POS_TEST) {
126 utc_message("Loading web page: %s", WEB_DATABASE_SAMPLE_URL);
127 ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), WEB_DATABASE_SAMPLE_URL));
128 ASSERT_EQ(Success, EventLoopStart());
130 // testcase is hosted on github pages (github.io) for free, so it can be slow
133 ewk_context_web_database_origins_get(context_, OriginsGetCb, this));
134 ASSERT_EQ(Success, EventLoopStart());
136 ASSERT_TRUE(usage_get_result_);
137 ASSERT_GT(usage_, 0);
141 * @brief Tests if returns false when parameters are null.
143 TEST_F(utc_blink_ewk_context_web_database_usage_for_origin_get, NEG_TEST) {
144 utc_message("Loading web page: %s", WEB_DATABASE_SAMPLE_URL);
145 ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), WEB_DATABASE_SAMPLE_URL));
146 ASSERT_EQ(Success, EventLoopStart());
148 // testcase is hosted on github pages (github.io) for free, so it can be slow
152 ewk_context_web_database_origins_get(context_, OriginsGetCb, this));
153 ASSERT_EQ(Success, EventLoopStart());
154 ASSERT_FALSE(neg_result_1_);
155 ASSERT_FALSE(neg_result_2_);
156 ASSERT_FALSE(neg_result_3_);