94bd7e904614a79f879a44c2d5afdbd301350ac2
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / WebView / TSWebContext.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6 using System.Threading.Tasks;
7 using System.Collections.Generic;
8
9 namespace Tizen.NUI.Devel.Tests
10 {
11     using tlog = Tizen.Log;
12
13     [TestFixture]
14     [Description("internal/WebView/WebContext")]
15     public class InternalWebContextTest
16     {
17         private const string tag = "NUITEST";
18         private string url = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/index.html";
19         private string urlForDatabase = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/webdb.html";
20         private string urlForStorage = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/webstorage.html";
21         private string urlForLocalFileSystem = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/weblocalfilesystem.html";
22         private string urlForFormPassword = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/webformpasword.html";
23         private string urlForDownload = "https://codeload.github.com/Samsung/TizenFX/zip/refs/heads/master";
24         private string urlForApplicatonCache = "https://www.google.com/";
25
26         private BaseComponents.WebView webview_ = null;
27
28         private bool MimeWrittenCallback(string url, string currentMime, out string newMime) 
29         {
30             newMime = null;
31             return true;
32         }
33
34         [SetUp]
35         public void Init()
36         {
37             webview_ = new BaseComponents.WebView()
38             {
39                 Size = new Size(500, 200),
40             };
41             tlog.Info(tag, "Init() is called!");
42         }
43
44         [TearDown]
45         public void Destroy()
46         {
47             tlog.Info(tag, "Destroy() is being called!");
48             webview_.Dispose();
49             tlog.Info(tag, "Destroy() is called!");
50         }
51
52         [Test]
53         [Category("P1")]
54         [Description("WebContext ProxyUrl.")]
55         [Property("SPEC", "Tizen.NUI.WebContext.ProxyUrl A")]
56         [Property("SPEC_URL", "-")]
57         [Property("CRITERIA", "PRW")]
58         [Property("COVPARAM", "")]
59         [Property("AUTHOR", "guowei.wang@samsung.com")]
60         public void WebContextProxyUrl()
61         {
62             tlog.Debug(tag, $"WebContextProxyUrl START");
63
64             var context = webview_.Context;
65             tlog.Debug(tag, "ProxyUrl : " + context.ProxyUrl);
66
67             context.ProxyUrl = "http://www.baidu.com";
68             tlog.Debug(tag, "ProxyUrl : " + context.ProxyUrl);
69
70             context.Dispose();
71
72             tlog.Debug(tag, $"WebContextProxyUrl END (OK)");
73         }
74
75         [Test]
76         [Category("P1")]
77         [Description("WebContext CertificateFilePath.")]
78         [Property("SPEC", "Tizen.NUI.WebContext.CertificateFilePath A")]
79         [Property("SPEC_URL", "-")]
80         [Property("CRITERIA", "PRW")]
81         [Property("COVPARAM", "")]
82         [Property("AUTHOR", "guowei.wang@samsung.com")]
83         public void WebContextCertificateFilePath()
84         {
85             tlog.Debug(tag, $"WebContextCertificateFilePath START");
86
87             var context = webview_.Context;
88             tlog.Debug(tag, "CertificateFilePath : " + context.CertificateFilePath);
89
90             context.CertificateFilePath = url;
91             tlog.Debug(tag, "CertificateFilePath : " + context.CertificateFilePath);
92
93             context.Dispose();
94
95             tlog.Debug(tag, $"WebContextCertificateFilePath END (OK)");
96         }
97
98         [Test]
99         [Category("P1")]
100         [Description("WebContext CacheEnabled.")]
101         [Property("SPEC", "Tizen.NUI.WebContext.CacheEnabled A")]
102         [Property("SPEC_URL", "-")]
103         [Property("CRITERIA", "PRW")]
104         [Property("COVPARAM", "")]
105         [Property("AUTHOR", "guowei.wang@samsung.com")]
106         public void WebContextCacheEnabled()
107         {
108             tlog.Debug(tag, $"WebContextCacheEnabled START");
109
110             var context = webview_.Context;
111             tlog.Debug(tag, "CacheEnabled : " + context.CacheEnabled);
112
113             context.CacheEnabled = true;
114             tlog.Debug(tag, "CacheEnabled : " + context.CacheEnabled);
115
116             context.CacheEnabled = false;
117             tlog.Debug(tag, "CacheEnabled : " + context.CacheEnabled);
118
119             context.Dispose();
120
121             tlog.Debug(tag, $"WebContextCertificateFilePath END (OK)");
122         }
123
124         [Test]
125         [Category("P1")]
126         [Description("WebContext AppId.")]
127         [Property("SPEC", "Tizen.NUI.WebContext.AppId A")]
128         [Property("SPEC_URL", "-")]
129         [Property("CRITERIA", "PRW")]
130         [Property("COVPARAM", "")]
131         [Property("AUTHOR", "guowei.wang@samsung.com")]
132         public void WebContextAppId()
133         {
134             tlog.Debug(tag, $"WebContextAppId START");
135
136             var context = webview_.Context;
137             tlog.Debug(tag, "AppId : " + context.AppId);
138
139             context.AppId = "WebContextAppId";
140             tlog.Debug(tag, "AppId : " + context.AppId);
141
142             context.Dispose();
143
144             tlog.Debug(tag, $"WebContextAppId END (OK)");
145         }
146
147         [Test]
148         [Category("P1")]
149         [Description("WebContext AppVersion.")]
150         [Property("SPEC", "Tizen.NUI.WebContext.AppVersion A")]
151         [Property("SPEC_URL", "-")]
152         [Property("CRITERIA", "PRW")]
153         [Property("COVPARAM", "")]
154         [Property("AUTHOR", "guowei.wang@samsung.com")]
155         public void WebContextAppVersion()
156         {
157             tlog.Debug(tag, $"WebContextAppVersion START");
158
159             var context = webview_.Context;
160             tlog.Debug(tag, "AppVersion : " + context.AppVersion);
161
162             context.AppVersion = "1.0";
163             tlog.Debug(tag, "AppVersion : " + context.AppVersion);
164
165             context.Dispose();
166
167             tlog.Debug(tag, $"WebContextAppVersion END (OK)");
168         }
169
170         [Test]
171         [Category("P1")]
172         [Description("WebContext AppType.")]
173         [Property("SPEC", "Tizen.NUI.WebContext.AppType A")]
174         [Property("SPEC_URL", "-")]
175         [Property("CRITERIA", "PRW")]
176         [Property("COVPARAM", "")]
177         [Property("AUTHOR", "guowei.wang@samsung.com")]
178         public void WebContextAppType()
179         {
180             tlog.Debug(tag, $"WebContextAppType START");
181
182             var context = webview_.Context;
183             tlog.Debug(tag, "AppType : " + context.AppType);
184
185             context.AppType = WebContext.ApplicationType.WebBrowser;
186             tlog.Debug(tag, "AppType : " + context.AppType);
187
188             context.Dispose();
189
190             tlog.Debug(tag, $"WebContextAppType END (OK)");
191         }
192
193         [Test]
194         [Category("P1")]
195         [Description("WebContext TimeOffset.")]
196         [Property("SPEC", "Tizen.NUI.WebContext.TimeOffset A")]
197         [Property("SPEC_URL", "-")]
198         [Property("CRITERIA", "PRW")]
199         [Property("COVPARAM", "")]
200         [Property("AUTHOR", "guowei.wang@samsung.com")]
201         public void WebContextTimeOffset()
202         {
203             tlog.Debug(tag, $"WebContextTimeOffset START");
204
205             var context = webview_.Context;
206             tlog.Debug(tag, "TimeOffset : " + context.TimeOffset);
207
208             context.TimeOffset = 0.3f;
209             tlog.Debug(tag, "TimeOffset : " + context.TimeOffset);
210
211             context.Dispose();
212
213             tlog.Debug(tag, $"WebContextAppType END (OK)");
214         }
215
216         [Test]
217         [Category("P1")]
218         [Description("WebContext DefaultZoomFactor.")]
219         [Property("SPEC", "Tizen.NUI.WebContext.DefaultZoomFactor A")]
220         [Property("SPEC_URL", "-")]
221         [Property("CRITERIA", "PRW")]
222         [Property("COVPARAM", "")]
223         [Property("AUTHOR", "guowei.wang@samsung.com")]
224         public void WebContextDefaultZoomFactor()
225         {
226             tlog.Debug(tag, $"WebContextDefaultZoomFactor START");
227
228             var context = webview_.Context;
229             tlog.Debug(tag, "DefaultZoomFactor : " + context.DefaultZoomFactor);
230
231             context.DefaultZoomFactor = 0.3f;
232             tlog.Debug(tag, "DefaultZoomFactor : " + context.DefaultZoomFactor);
233
234             context.Dispose();
235
236             tlog.Debug(tag, $"WebContextDefaultZoomFactor END (OK)");
237         }
238
239         [Test]
240         [Category("P1")]
241         [Description("WebContext ContextProxy.")]
242         [Property("SPEC", "Tizen.NUI.WebContext.ContextProxy A")]
243         [Property("SPEC_URL", "-")]
244         [Property("CRITERIA", "PRO")]
245         [Property("COVPARAM", "")]
246         [Property("AUTHOR", "guowei.wang@samsung.com")]
247         public void WebContextContextProxy()
248         {
249             tlog.Debug(tag, $"WebContextContextProxy START");
250
251             var context = webview_.Context;
252             tlog.Debug(tag, "ContextProxy : " + context.ContextProxy);
253
254             context.Dispose();
255
256             tlog.Debug(tag, $"WebContextContextProxy END (OK)");
257         }
258
259         [Test]
260         [Category("P1")]
261         [Description("WebContext ProxyBypassRule.")]
262         [Property("SPEC", "Tizen.NUI.WebContext.ProxyBypassRule A")]
263         [Property("SPEC_URL", "-")]
264         [Property("CRITERIA", "PRO")]
265         [Property("COVPARAM", "")]
266         [Property("AUTHOR", "guowei.wang@samsung.com")]
267         public void WebContextProxyBypassRule()
268         {
269             tlog.Debug(tag, $"WebContextProxyBypassRule START");
270
271             var context = webview_.Context;
272             tlog.Debug(tag, "ProxyBypassRule : " + context.ProxyBypassRule);
273
274             context.Dispose();
275
276             tlog.Debug(tag, $"WebContextProxyBypassRule END (OK)");
277         }
278
279         //TODO...API would block. Its doc in web engine proposes to avoid using this API.
280         //[Test]
281         //[Category("P1")]
282         //[Description("WebContext SetDefaultProxyAuth.")]
283         //[Property("SPEC", "Tizen.NUI.WebContext.SetDefaultProxyAuth M")]
284         //[Property("SPEC_URL", "-")]
285         //[Property("CRITERIA", "MR")]
286         //[Property("COVPARAM", "")]
287         //[Property("AUTHOR", "guowei.wang@samsung.com")]
288         //public async Task WebContextSetDefaultProxyAuth()
289         //{
290         //    tlog.Debug(tag, $"WebContextSetDefaultProxyAuth START");
291
292         //    var context = webview_.Context;
293         //    context.SetDefaultProxyAuth("tizen", "samsung");
294
295         //    TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
296         //    EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
297         //    {
298         //        tcs.TrySetResult(true);
299         //    };
300         //    webview_.PageLoadFinished += onLoadFinished;
301
302         //    webview_.LoadUrl(url);
303         //    var result = await tcs.Task;
304         //    Assert.IsTrue(result, "PageLoadFinished event should be invoked");
305
306         //    webview_.PageLoadFinished -= onLoadFinished;
307         //    context.Dispose();
308
309         //    tlog.Debug(tag, $"WebContextSetDefaultProxyAuth END (OK)");
310         //}
311
312         [Test]
313         [Category("P1")]
314         [Description("WebContext DeleteAllWebDatabase.")]
315         [Property("SPEC", "Tizen.NUI.WebContext.DeleteAllWebDatabase M")]
316         [Property("SPEC_URL", "-")]
317         [Property("CRITERIA", "MR")]
318         [Property("COVPARAM", "")]
319         [Property("AUTHOR", "guowei.wang@samsung.com")]
320         public async Task WebContextDeleteAllWebDatabase()
321         {
322             tlog.Debug(tag, $"WebContextDeleteAllWebDatabase START");
323
324             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
325             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
326             {
327                 tcs.TrySetResult(true);
328             };
329             webview_.PageLoadFinished += onLoadFinished;
330
331             webview_.LoadUrl(urlForDatabase);
332             var result = await tcs.Task;
333             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
334
335             // Check list count.
336             var context = webview_.Context;
337
338             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
339             WebContext.SecurityOriginListAcquiredCallback cb2 = (list) =>
340             {
341                 tcs2.TrySetResult(list.Count);
342             };
343             context.GetWebDatabaseOrigins(cb2);
344
345             var result2 = await tcs2.Task;
346             Assert.AreEqual(result2, 0, "GetWebDatabaseOrigins should be called."); //TODO... result2 is 1?
347
348             // Delete all web db.
349             context.DeleteAllWebDatabase();
350
351             // Check list count.
352             TaskCompletionSource<int> tcs3 = new TaskCompletionSource<int>(0);
353             WebContext.SecurityOriginListAcquiredCallback cb3 = (list) =>
354             {
355                 tcs3.TrySetResult(list.Count);
356             };
357
358             context.GetWebDatabaseOrigins(cb3);
359
360             var result3 = await tcs3.Task;
361             Assert.AreEqual(result3, 0, "GetWebDatabaseOrigins should be called.");
362
363             webview_.PageLoadFinished -= onLoadFinished;
364
365             context.Dispose();
366
367             tlog.Debug(tag, $"WebContextDeleteAllWebDatabase END (OK)");
368         }
369
370         [Test]
371         [Category("P1")]
372         [Description("WebContext GetWebDatabaseOrigins.")]
373         [Property("SPEC", "Tizen.NUI.WebContext.GetWebDatabaseOrigins M")]
374         [Property("SPEC_URL", "-")]
375         [Property("CRITERIA", "MR")]
376         [Property("COVPARAM", "")]
377         [Property("AUTHOR", "guowei.wang@samsung.com")]
378         public async Task WebContextGetWebDatabaseOrigins()
379         {
380             tlog.Debug(tag, $"WebContextGetWebDatabaseOrigins START");
381
382             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
383             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
384             {
385                 tcs.TrySetResult(true);
386             };
387             webview_.PageLoadFinished += onLoadFinished;
388
389             webview_.LoadUrl(urlForDatabase);
390             var result = await tcs.Task;
391             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
392
393             var context = webview_.Context;
394             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
395             WebContext.SecurityOriginListAcquiredCallback cb = (list) =>
396             {
397                 tcs2.TrySetResult(list.Count);
398             };
399             context.GetWebDatabaseOrigins(cb);
400
401             var result2 = await tcs2.Task;
402             Assert.AreEqual(result2, 0, "GetWebDatabaseOrigins should be called.");  //TODO... result2 is 1?
403
404             context.Dispose();
405             webview_.PageLoadFinished -= onLoadFinished;
406
407             tlog.Debug(tag, $"WebContextGetWebDatabaseOrigins END (OK)");
408         }
409
410         [Test]
411         [Category("P1")]
412         [Description("WebContext DeleteWebDatabase.")]
413         [Property("SPEC", "Tizen.NUI.WebContext.DeleteWebDatabase M")]
414         [Property("SPEC_URL", "-")]
415         [Property("CRITERIA", "MR")]
416         [Property("COVPARAM", "")]
417         [Property("AUTHOR", "guowei.wang@samsung.com")]
418         public async Task WebContextDeleteWebDatabase()
419         {
420             tlog.Debug(tag, $"WebContextDeleteWebDatabase START");
421
422             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
423             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
424             {
425                 tcs.TrySetResult(true);
426             };
427             webview_.PageLoadFinished += onLoadFinished;
428
429             webview_.LoadUrl(urlForDatabase);
430             var result = await tcs.Task;
431             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
432
433             var context = webview_.Context;
434             WebSecurityOrigin seo = null;
435             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
436             WebContext.SecurityOriginListAcquiredCallback cb2 = (list) =>
437             {
438                 if (list.Count > 0)
439                 {
440                     seo = list[0];
441                 }
442                 tcs2.TrySetResult(list.Count);
443             };
444             context.GetWebDatabaseOrigins(cb2);
445
446             var result2 = await tcs2.Task;
447             Assert.AreEqual(result2, 0, "GetWebDatabaseOrigins should be called.");  //TODO... result2 is 1?
448
449             // Delete db by security origin.
450             tlog.Debug(tag, $"WebContextDeleteWebDatabase, Host: {seo?.Host}");
451             tlog.Debug(tag, $"WebContextDeleteWebDatabase Protocol: {seo?.Protocol}");
452             if (seo != null)
453             {
454                 context.DeleteWebDatabase(seo);
455             }
456
457             TaskCompletionSource<int> tcs3 = new TaskCompletionSource<int>(0);
458             WebContext.SecurityOriginListAcquiredCallback cb3 = (list) =>
459             {
460                 tcs3.TrySetResult(list.Count);
461             };
462             context.GetWebDatabaseOrigins(cb3);
463
464             var result3 = await tcs3.Task;
465             Assert.AreEqual(result3, 0, "GetWebDatabaseOrigins should be called.");
466
467             context.Dispose();
468             webview_.PageLoadFinished -= onLoadFinished;
469
470             tlog.Debug(tag, $"WebContextDeleteWebDatabase END (OK)");
471         }
472
473         //TODO... Web engine blocks!!!!!!
474         [Test]
475         [Category("P1")]
476         [Description("WebContext GetWebStorageOrigins.")]
477         [Property("SPEC", "Tizen.NUI.WebContext.GetWebStorageUsageForOrigin M")]
478         [Property("SPEC_URL", "-")]
479         [Property("CRITERIA", "MR")]
480         [Property("COVPARAM", "")]
481         [Property("AUTHOR", "guowei.wang@samsung.com")]
482         public async Task WebContextGetWebStorageUsageForOrigin()
483         {
484             tlog.Debug(tag, $"WebContextGetWebStorageUsageForOrigin START");
485
486             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
487             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
488             {
489                 tcs.TrySetResult(true);
490             };
491             webview_.PageLoadFinished += onLoadFinished;
492
493             webview_.LoadUrl(urlForStorage);
494             var result = await tcs.Task;
495             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
496
497             // Get web storage.
498             var context = webview_.Context;
499             WebSecurityOrigin seo = null;
500             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
501             WebContext.SecurityOriginListAcquiredCallback cb2 = (list) =>
502             {
503                 if (list.Count > 0)
504                 {
505                     seo = list[0];
506                 }
507                 tcs2.TrySetResult(list.Count);
508             };
509             context.GetWebStorageOrigins(cb2);
510
511             var result2 = await tcs2.Task;
512             Assert.AreEqual(result2, 1, "GetWebStorageOrigins should be called.");
513
514             if (seo != null)
515             {
516                 TaskCompletionSource<ulong> tcs3 = new TaskCompletionSource<ulong>(0);
517                 WebContext.StorageUsageAcquiredCallback cb3 = (usage) =>
518                 {
519                     tcs3.TrySetResult(usage);
520                 };
521                 context.GetWebStorageUsageForOrigin(seo, cb3);
522                 var result3 = await tcs3.Task;
523                 Assert.Greater(result3, 0, "GetWebStorageUsageForOrigin should be called.");
524             }
525
526             context.Dispose();
527             webview_.PageLoadFinished -= onLoadFinished;
528
529             tlog.Debug(tag, $"WebContextGetWebStorageUsageForOrigin END (OK)");
530         }
531
532         //TODO... Web engine blocks!!!!!!
533         [Test]
534         [Category("P1")]
535         [Description("WebContext DeleteAllWebStorage.")]
536         [Property("SPEC", "Tizen.NUI.WebContext.DeleteAllWebStorage M")]
537         [Property("SPEC_URL", "-")]
538         [Property("CRITERIA", "MR")]
539         [Property("COVPARAM", "")]
540         [Property("AUTHOR", "guowei.wang@samsung.com")]
541         public async Task WebContextDeleteAllWebStorage()
542         {
543             tlog.Debug(tag, $"WebContextDeleteAllWebStorage START");
544
545             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
546             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
547             {
548                 tcs.TrySetResult(true);
549             };
550             webview_.PageLoadFinished += onLoadFinished;
551
552             webview_.LoadUrl(urlForStorage);
553             var result = await tcs.Task;
554             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
555
556             var context = webview_.Context;
557
558             // Check list count.
559             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
560             WebContext.SecurityOriginListAcquiredCallback cb2 = (list) =>
561             {
562                 tcs2.TrySetResult(list.Count);
563             };
564
565             context.GetWebStorageOrigins(cb2);
566
567             var result2 = await tcs2.Task;
568             Assert.Greater(result2, 0, "GetWebStorageOrigins should be called.");
569
570             // Delete all web storage.
571             context.DeleteAllWebStorage();
572
573             // Check list count.
574             TaskCompletionSource<int> tcs3 = new TaskCompletionSource<int>(0);
575             WebContext.SecurityOriginListAcquiredCallback cb3 = (list) =>
576             {
577                 tcs3.TrySetResult(list.Count);
578             };
579
580             context.GetWebStorageOrigins(cb3);
581
582             var result3 = await tcs3.Task;
583             Assert.AreEqual(result3, 0, "GetWebStorageOrigins should be called.");
584
585             webview_.PageLoadFinished -= onLoadFinished;
586             context.Dispose();
587
588             tlog.Debug(tag, $"WebContextDeleteAllWebStorage END (OK)");
589         }
590
591         //TODO... Web engine blocks!!!!!!
592         [Test]
593         [Category("P1")]
594         [Description("WebContext DeleteAllWebStorage.")]
595         [Property("SPEC", "Tizen.NUI.WebContext.DeleteWebStorage M")]
596         [Property("SPEC_URL", "-")]
597         [Property("CRITERIA", "MR")]
598         [Property("COVPARAM", "")]
599         [Property("AUTHOR", "guowei.wang@samsung.com")]
600         public async Task WebContextDeleteWebStorage()
601         {
602             tlog.Debug(tag, $"WebContextDeleteAllWebStorage START");
603
604             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
605             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
606             {
607                 tcs.TrySetResult(true);
608             };
609             webview_.PageLoadFinished += onLoadFinished;
610
611             webview_.LoadUrl(urlForStorage);
612             var result = await tcs.Task;
613             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
614
615             var context = webview_.Context;
616
617             // Check list count.
618             WebSecurityOrigin seo = null;
619             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
620             WebContext.SecurityOriginListAcquiredCallback cb2 = (list) =>
621             {
622                 seo = list[0];
623                 tcs2.TrySetResult(list.Count);
624             };
625
626             context.GetWebStorageOrigins(cb2);
627
628             var result2 = await tcs2.Task;
629             Assert.Greater(result2, 0, "GetWebStorageOrigins should be called.");
630
631             // Delete web storage.
632             context.DeleteWebStorage(seo);
633
634             // Check list count.
635             TaskCompletionSource<int> tcs3 = new TaskCompletionSource<int>(0);
636             WebContext.SecurityOriginListAcquiredCallback cb3 = (list) =>
637             {
638                 tcs3.TrySetResult(list.Count);
639             };
640
641             context.GetWebStorageOrigins(cb3);
642
643             var result3 = await tcs3.Task;
644             Assert.AreEqual(result3, 0, "GetWebStorageOrigins should be called.");
645
646             webview_.PageLoadFinished -= onLoadFinished;
647             context.Dispose();
648
649             tlog.Debug(tag, $"WebContextDeleteAllWebStorage END (OK)");
650         }
651
652         [Test]
653         [Category("P1")]
654         [Description("WebContext DeleteLocalFileSystem.")]
655         [Property("SPEC", "Tizen.NUI.WebContext.DeleteLocalFileSystem M")]
656         [Property("SPEC_URL", "-")]
657         [Property("CRITERIA", "MR")]
658         [Property("COVPARAM", "")]
659         [Property("AUTHOR", "guowei.wang@samsung.com")]
660         public async Task WebContextDeleteLocalFileSystem()
661         {
662             tlog.Debug(tag, $"WebContextDeleteLocalFileSystem START");
663
664             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
665             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
666             {
667                 tcs.TrySetResult(true);
668             };
669             webview_.PageLoadFinished += onLoadFinished;
670
671             webview_.LoadUrl(urlForLocalFileSystem);
672             var result = await tcs.Task;
673             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
674
675             var context = webview_.Context;
676
677             // Delete all web local file system.
678             context.DeleteLocalFileSystem();
679             // TODO...list count need be checked, but query API is not wrapped.
680
681             webview_.PageLoadFinished -= onLoadFinished;
682             context.Dispose();
683
684             tlog.Debug(tag, $"WebContextDeleteLocalFileSystem END (OK)");
685         }
686
687         [Test]
688         [Category("P1")]
689         [Description("WebContext GetFormPasswordList.")]
690         [Property("SPEC", "Tizen.NUI.WebContext.GetFormPasswordList M")]
691         [Property("SPEC_URL", "-")]
692         [Property("CRITERIA", "MR")]
693         [Property("COVPARAM", "")]
694         [Property("AUTHOR", "guowei.wang@samsung.com")]
695         public async Task WebContextGetFormPasswordList()
696         {
697             tlog.Debug(tag, $"WebContextGetFormPasswordList START");
698
699             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
700             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
701             {
702                 tcs.TrySetResult(true);
703             };
704             webview_.PageLoadFinished += onLoadFinished;
705
706             webview_.LoadUrl(urlForFormPassword);
707             var result = await tcs.Task;
708             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
709
710             var context = webview_.Context;
711
712             // Check list count.
713             // Check list count.
714             WebPasswordData pd = null;
715             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
716             WebContext.PasswordDataListAcquiredCallback cb2 = (list) =>
717             {
718                 if (list.Count > 0)
719                 {
720                     pd = list[0];
721                 }
722                 tcs2.TrySetResult(list.Count);
723             };
724
725             context.GetFormPasswordList(cb2);
726
727             var result2 = await tcs2.Task;
728             Assert.AreEqual(result2, 0, "GetFormPasswordList should be called.");
729
730             tlog.Info(tag, $"WebContextGetFormPasswordList, url: {pd?.Url}");
731             tlog.Info(tag, $"WebContextGetFormPasswordList, FingerprintUsed: {pd?.FingerprintUsed}");
732
733             webview_.PageLoadFinished -= onLoadFinished;
734             context.Dispose();
735
736             tlog.Debug(tag, $"WebContextGetFormPasswordList END (OK)");
737         }
738
739         [Test]
740         [Category("P1")]
741         [Description("WebContext DeleteAllFormPasswordData.")]
742         [Property("SPEC", "Tizen.NUI.WebContext.DeleteAllFormPasswordData M")]
743         [Property("SPEC_URL", "-")]
744         [Property("CRITERIA", "MR")]
745         [Property("COVPARAM", "")]
746         [Property("AUTHOR", "guowei.wang@samsung.com")]
747         public async Task WebContextDeleteAllFormPasswordData()
748         {
749             tlog.Debug(tag, $"WebContextDeleteAllFormPasswordData START");
750
751             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
752             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
753             {
754                 tcs.TrySetResult(true);
755             };
756             webview_.PageLoadFinished += onLoadFinished;
757
758             webview_.LoadUrl(urlForFormPassword);
759             var result = await tcs.Task;
760             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
761
762             var context = webview_.Context;
763
764             // Check list count.
765             List<string> pl = new List<string>();
766             TaskCompletionSource<int> tcs2 = new TaskCompletionSource<int>(0);
767             WebContext.PasswordDataListAcquiredCallback cb2 = (list) =>
768             {
769                 if (list.Count > 0)
770                 {
771                     pl.Add(list[0].Url);
772                 }
773                 tcs2.TrySetResult(list.Count);
774             };
775
776             context.GetFormPasswordList(cb2);
777
778             var result2 = await tcs2.Task;
779             Assert.AreEqual(result2, 0, "GetFormPasswordList should be called.");
780
781             // Delete web storage.
782             context.DeleteFormPasswordDataList(pl.ToArray()); //TODO... This API seems not correct.
783             context.DeleteAllFormPasswordData();
784             context.DeleteAllFormCandidateData();
785
786             // Check list count.
787             TaskCompletionSource<int> tcs3 = new TaskCompletionSource<int>(0);
788             WebContext.PasswordDataListAcquiredCallback cb3 = (list) =>
789             {
790                 tcs3.TrySetResult(list.Count);
791             };
792
793             context.GetFormPasswordList(cb3);
794
795             var result3 = await tcs3.Task;
796             Assert.AreEqual(result3, 0, "GetFormPasswordList should be called.");
797
798             webview_.PageLoadFinished -= onLoadFinished;
799             context.Dispose();
800
801             tlog.Debug(tag, $"WebContextDeleteAllFormPasswordData END (OK)");
802         }
803
804         [Test]
805         [Category("P1")]
806         [Description("WebContext RegisterDownloadStartedCallback.")]
807         [Property("SPEC", "Tizen.NUI.WebContext.RegisterDownloadStartedCallback M")]
808         [Property("SPEC_URL", "-")]
809         [Property("CRITERIA", "MR")]
810         [Property("COVPARAM", "")]
811         [Property("AUTHOR", "guowei.wang@samsung.com")]
812         public async Task WebContextRegisterDownloadStartedCallback()
813         {
814             tlog.Debug(tag, $"WebContextRegisterDownloadStartedCallback START");
815
816             // Check if download or not.
817             var context = webview_.Context;
818             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
819             WebContext.DownloadStartedCallback dcb = (url) =>
820             {
821                 tcs.TrySetResult(true);
822             };
823             context.RegisterDownloadStartedCallback(dcb);
824
825             webview_.LoadUrl(urlForDownload);
826             var result = await tcs.Task;
827             Assert.IsTrue(result, "DownloadStartedCallback should be invoked");
828
829             context.Dispose();
830
831             tlog.Debug(tag, $"WebContextRegisterDownloadStartedCallback END (OK)");
832         }
833
834         [Test]
835         [Category("P1")]
836         [Description("WebContext RegisterMimeOverriddenCallback.")]
837         [Property("SPEC", "Tizen.NUI.WebContext.RegisterMimeOverriddenCallback M")]
838         [Property("SPEC_URL", "-")]
839         [Property("CRITERIA", "MR")]
840         [Property("COVPARAM", "")]
841         [Property("AUTHOR", "guowei.wang@samsung.com")]
842         public async Task WebContextRegisterMimeOverriddenCallback()
843         {
844             tlog.Debug(tag, $"WebContextRegisterMimeOverriddenCallback START");
845
846             var context = webview_.Context;
847             context.RegisterMimeOverriddenCallback(MimeWrittenCallback); //TODO... how to test it?
848
849             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
850             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
851             {
852                 tcs.TrySetResult(true);
853             };
854             webview_.PageLoadFinished += onLoadFinished;
855
856             webview_.LoadUrl(url);
857             var result = await tcs.Task;
858             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
859
860             webview_.PageLoadFinished -= onLoadFinished;
861             context.Dispose();
862
863             tlog.Debug(tag, $"WebContextRegisterMimeOverriddenCallback END (OK)");
864         }
865
866         [Test]
867         [Category("P1")]
868         [Description("WebContext SetTimeZoneOffset.")]
869         [Property("SPEC", "Tizen.NUI.WebContext.SetTimeZoneOffset M")]
870         [Property("SPEC_URL", "-")]
871         [Property("CRITERIA", "MR")]
872         [Property("COVPARAM", "")]
873         [Property("AUTHOR", "guowei.wang@samsung.com")]
874         public async Task WebContextSetTimeZoneOffset()
875         {
876             tlog.Debug(tag, $"WebContextSetTimeZoneOffset START");
877
878             var context = webview_.Context;
879             context.SetTimeZoneOffset(0.3f, 1.0f);
880
881             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
882             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
883             {
884                 tcs.TrySetResult(true);
885             };
886             webview_.PageLoadFinished += onLoadFinished;
887
888             webview_.LoadUrl(url);
889             var result = await tcs.Task;
890             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
891
892             webview_.PageLoadFinished -= onLoadFinished;
893             context.Dispose();
894
895             tlog.Debug(tag, $"WebContextSetTimeZoneOffset END (OK)");
896         }
897
898         [Test]
899         [Category("P1")]
900         [Description("WebContext SetContextTimeZoneOffset.")]
901         [Property("SPEC", "Tizen.NUI.WebContext.SetContextTimeZoneOffset M")]
902         [Property("SPEC_URL", "-")]
903         [Property("CRITERIA", "MR")]
904         [Property("COVPARAM", "")]
905         [Property("AUTHOR", "guowei.wang@samsung.com")]
906         public async Task WebContextSetContextTimeZoneOffset()
907         {
908             tlog.Debug(tag, $"WebContextSetContextTimeZoneOffset START");
909
910             var context = webview_.Context;
911             context.SetContextTimeZoneOffset(0.3f, 1.0f);
912
913             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
914             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
915             {
916                 tcs.TrySetResult(true);
917             };
918             webview_.PageLoadFinished += onLoadFinished;
919
920             webview_.LoadUrl(url);
921             var result = await tcs.Task;
922             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
923
924             webview_.PageLoadFinished -= onLoadFinished;
925             context.Dispose();
926
927             tlog.Debug(tag, $"WebContextSetContextTimeZoneOffset END (OK)");
928         }
929
930         [Test]
931         [Category("P1")]
932         [Description("WebContext DeleteAllApplicationCache.")]
933         [Property("SPEC", "Tizen.NUI.WebContext.DeleteAllApplicationCache M")]
934         [Property("SPEC_URL", "-")]
935         [Property("CRITERIA", "MR")]
936         [Property("COVPARAM", "")]
937         [Property("AUTHOR", "guowei.wang@samsung.com")]
938         public async Task WebContextDeleteAllApplicationCache()
939         {
940             tlog.Debug(tag, $"WebContextDeleteAllApplicationCache START");
941
942             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
943             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
944             {
945                 tcs.TrySetResult(true);
946             };
947             webview_.PageLoadFinished += onLoadFinished;
948
949             webview_.LoadUrl(urlForApplicatonCache);
950             var result = await tcs.Task;
951             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
952
953             var context = webview_.Context;
954
955             // Delete all web applicaton cache.
956             context.DeleteAllApplicationCache();
957             // TODO...list count need be checked, but query API is not wrapped.
958
959             webview_.PageLoadFinished -= onLoadFinished;
960             context.Dispose();
961
962             tlog.Debug(tag, $"WebContextDeleteAllApplicationCache END (OK)");
963         }
964
965         [Test]
966         [Category("P1")]
967         [Description("WebContext DeleteAllWebIndexedDatabase.")]
968         [Property("SPEC", "Tizen.NUI.WebContext.DeleteAllWebIndexedDatabase M")]
969         [Property("SPEC_URL", "-")]
970         [Property("CRITERIA", "MR")]
971         [Property("COVPARAM", "")]
972         [Property("AUTHOR", "guowei.wang@samsung.com")]
973         public async Task WebContextDeleteAllWebIndexedDatabase()
974         {
975             tlog.Debug(tag, $"WebContextDeleteAllWebIndexedDatabase START");
976
977             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
978             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
979             {
980                 tcs.TrySetResult(true);
981             };
982             webview_.PageLoadFinished += onLoadFinished;
983
984             webview_.LoadUrl(urlForApplicatonCache);
985             var result = await tcs.Task;
986             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
987
988             var context = webview_.Context;
989
990             // Delete all web indexed db.
991             context.DeleteAllWebIndexedDatabase();
992             // TODO...list count need be checked, but query API is not wrapped.
993
994             webview_.PageLoadFinished -= onLoadFinished;
995             context.Dispose();
996
997             tlog.Debug(tag, $"WebContextDeleteAllWebIndexedDatabase END (OK)");
998         }
999
1000         [Test]
1001         [Category("P1")]
1002         [Description("WebContext FreeUnusedMemory.")]
1003         [Property("SPEC", "Tizen.NUI.WebContext.FreeUnusedMemory M")]
1004         [Property("SPEC_URL", "-")]
1005         [Property("CRITERIA", "MR")]
1006         [Property("COVPARAM", "")]
1007         [Property("AUTHOR", "guowei.wang@samsung.com")]
1008         public async Task WebContextFreeUnusedMemory()
1009         {
1010             tlog.Debug(tag, $"WebContextFreeUnusedMemory START");
1011
1012             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
1013             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
1014             {
1015                 tcs.TrySetResult(true);
1016             };
1017             webview_.PageLoadFinished += onLoadFinished;
1018
1019             webview_.LoadUrl(urlForApplicatonCache);
1020             var result = await tcs.Task;
1021             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
1022
1023             var context = webview_.Context;
1024
1025             // Free unused memory if low memory.
1026             context.FreeUnusedMemory();
1027
1028             webview_.PageLoadFinished -= onLoadFinished;
1029             context.Dispose();
1030
1031             tlog.Debug(tag, $"WebContextFreeUnusedMemory END (OK)");
1032         }
1033     }
1034 }