[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_context_web_storage_delete_all_func.cpp
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.
4
5 /* Define those macros _before_ you include the utc_blink_ewk.h header file. */
6
7 #include "utc_blink_ewk_base.h"
8
9 class utc_blink_ewk_context_web_storage_delete_all : public utc_blink_ewk_base
10 {
11 protected:
12  void PostSetUp() override {
13    evas_object_smart_callback_add(GetEwkWebView(), "title,changed",
14                                   title_changed, this);
15   }
16
17   void PreTearDown() override {
18     evas_object_smart_callback_del(GetEwkWebView(), "title,changed", title_changed);
19   }
20
21   static void title_changed(void* data, Evas_Object* webview, void* event_info)
22   {
23     ASSERT_TRUE(data != NULL);
24
25     utc_blink_ewk_context_web_storage_delete_all* owner = static_cast<utc_blink_ewk_context_web_storage_delete_all*>(data);
26
27     owner->EventLoopStop(utc_blink_ewk_base::Success);
28   }
29 };
30
31 /**
32 * @brief Tests if can delete all web storages
33 */
34 TEST_F(utc_blink_ewk_context_web_storage_delete_all, POS_TEST)
35 {
36   std::string storageItemValue;
37
38   // Set web storage item StorageTest=STORAGE_TEST_VALUE
39   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl("ewk_context_web_storage/webStorageSet.html").c_str()));
40   ASSERT_EQ(Success, EventLoopStart());
41
42   // Check if the storage was properly set
43   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl("ewk_context_web_storage/webStorageGet.html").c_str()));
44   ASSERT_EQ(Success, EventLoopStart());
45
46   storageItemValue = ewk_view_title_get(GetEwkWebView());
47   ASSERT_EQ("STORAGE_TEST_VALUE", storageItemValue);
48   // Local storage item may be set in renderer cache but setting it in physical
49   // memory may be delayed. ewk_context_web_storage_delete_all removes all data
50   // of origins present in physical memory. In case of no line below, item may
51   // not be saved in physical memory before ewk_context_web_storage_delete_all
52   // is called.
53   EventLoopWait(6.0);
54
55   // Delete all web storage
56   Ewk_Context* context = ewk_view_context_get(GetEwkWebView());
57   ASSERT_EQ(EINA_TRUE, ewk_context_web_storage_delete_all(context));
58
59   // Check if the storage was really deleted
60   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl("ewk_context_web_storage/webStorageGet.html").c_str()));
61   ASSERT_EQ(Success, EventLoopStart());
62
63   storageItemValue = ewk_view_title_get(GetEwkWebView());
64   EXPECT_EQ("EMPTY", storageItemValue);
65 }
66
67 /**
68 * @brief Tests if returns false when context is null.
69 */
70 TEST_F(utc_blink_ewk_context_web_storage_delete_all, NEG_TEST)
71 {
72   EXPECT_FALSE(ewk_context_web_storage_delete_all(0));
73 }