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 #include "utc_blink_ewk_base.h"
8 class utc_blink_ewk_context_application_cache_origins_get : public utc_blink_ewk_base {
10 utc_blink_ewk_context_application_cache_origins_get()
11 : utc_blink_ewk_base()
17 ~utc_blink_ewk_context_application_cache_origins_get() override {
21 void PostSetUp() override {
22 ctx = ewk_view_context_get(GetEwkWebView());
23 ASSERT_TRUE(ctx != NULL);
26 void LoadFinished(Evas_Object* webview) override {
27 utc_message("LoadFinished");
28 EventLoopStop(Success);
31 Eina_Bool FindSecurityOrigin(const char* origin_host, const char* origin_protocol)
33 utc_message("FindSecurityOrigin: %s in %p", origin_host, origins);
35 if(origins && origin_host) {
37 void* list_data = NULL;
38 EINA_LIST_FOREACH(origins, it, list_data) {
39 Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(list_data);
41 if (!strcmp(ewk_security_origin_protocol_get(origin), origin_protocol) &&
42 !strcmp(ewk_security_origin_host_get(origin), origin_host)) {
50 void GetOrigins(unsigned int expected_count)
52 utc_message("GetOrigins: %d", expected_count);
53 // origins operations are async, we must wait for changes to propagate
54 for (int i = 0; i < 3; ++i) {
55 if (EINA_TRUE != ewk_context_application_cache_origins_get(ctx, applicationCacheOriginsGet, this)) {
59 if (Success != EventLoopStart()) {
63 if (expected_count == eina_list_count(origins)) {
67 if (!EventLoopWait(3.0)) {
73 void SetOrigins(Eina_List* new_origins)
75 utc_message("SetOrigins");
76 if (new_origins != origins) {
78 ewk_context_origins_free(origins);
81 origins = new_origins;
85 static void applicationCacheOriginsGet(Eina_List* origins, void* data)
87 utc_message("[applicationCacheOriginsGet] : %p, %p", origins, data);
90 ewk_context_origins_free(origins);
94 utc_blink_ewk_context_application_cache_origins_get* owner =
95 static_cast<utc_blink_ewk_context_application_cache_origins_get*>(data);
97 owner->SetOrigins(origins);
98 owner->EventLoopStop(Success);
102 static const char* const appCacheURL;
107 #define SAMPLE_ORIGIN_HOST "appcache.offline.technology"
108 #define SAMPLE_ORIGIN_PROTOCOL "http"
109 const char* const utc_blink_ewk_context_application_cache_origins_get::appCacheURL = SAMPLE_ORIGIN_PROTOCOL "://" SAMPLE_ORIGIN_HOST "/demo/";
112 * @brief Load page and check if the origins is there
114 TEST_F(utc_blink_ewk_context_application_cache_origins_get, POS_TEST)
116 // Load page, so all related APIs are initialized
117 ASSERT_TRUE(ewk_view_url_set(GetEwkWebView(), "http://www.google.pl"));
118 ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart());
120 // we want empty cache at test start
121 ASSERT_EQ(EINA_TRUE, ewk_context_application_cache_delete_all(ctx));
123 ASSERT_TRUE(origins == NULL);
124 ASSERT_EQ(0, eina_list_count(origins));
126 utc_message("Loading web page: %s", appCacheURL);
127 ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), appCacheURL));
129 ASSERT_EQ(Success, EventLoopStart());
132 ASSERT_TRUE(origins != NULL);
133 ASSERT_EQ(1, eina_list_count(origins));
135 ASSERT_TRUE(FindSecurityOrigin(SAMPLE_ORIGIN_HOST, SAMPLE_ORIGIN_PROTOCOL));
139 * @brief Tests in case of bad parameters
141 TEST_F(utc_blink_ewk_context_application_cache_origins_get, INVALID_ARGS)
143 EXPECT_EQ(EINA_FALSE, ewk_context_application_cache_origins_get(NULL, applicationCacheOriginsGet, NULL));
144 EXPECT_EQ(EINA_FALSE, ewk_context_application_cache_origins_get(ctx, NULL, NULL));