[NUI] Update webview TCs.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / WebView / TSWebBackForwardList.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
8 namespace Tizen.NUI.Devel.Tests
9 {
10     using tlog = Tizen.Log;
11
12     [TestFixture]
13     [Description("internal/WebView/WebBackForwardList")]
14     public class InternalWebBackForwardListTest
15     {
16         private const string tag = "NUITEST";
17         private string url = $"file://{Applications.Application.Current.DirectoryInfo.Resource}webview/index.html";
18         private string secondUrl = $"file://{Applications.Application.Current.DirectoryInfo.Resource}webview/second.html";
19         private BaseComponents.WebView webView = null;
20
21         [SetUp]
22         public void Init()
23         {
24             webView = new BaseComponents.WebView()
25             {
26                 Size = new Size(150, 100),
27             };
28             tlog.Info(tag, "Init() is called!");
29         }
30
31         [TearDown]
32         public void Destroy()
33         {
34             tlog.Info(tag, "Destroy() is being called!");
35             webView.Dispose();
36             tlog.Info(tag, "Destroy() is called!");
37         }
38
39         [Test]
40         [Category("P1")]
41         [Description("WebBackForwardList ItemCount.")]
42         [Property("SPEC", "Tizen.NUI.WebBackForwardList.ItemCount A")]
43         [Property("SPEC_URL", "-")]
44         [Property("CRITERIA", "PRO")]
45         [Property("COVPARAM", "")]
46         [Property("AUTHOR", "guowei.wang@samsung.com")]
47         public async Task WebBackForwardListConstructor()
48         {
49             tlog.Debug(tag, $"WebBackForwardListConstructor START");
50
51             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
52             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
53             {
54                 tlog.Info(tag, "onLoadFinished is called!");
55                 tcs.TrySetResult(true);
56             };
57             webView.PageLoadFinished += onLoadFinished;
58
59             webView.LoadUrl(url);
60             var result = await tcs.Task;
61             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
62
63             // Make current thread (CPU) sleep...
64             await Task.Delay(1);
65
66             Assert.IsNotNull(webView.BackForwardList, "null handle");
67             Assert.IsInstanceOf<WebBackForwardList>(webView.BackForwardList, "Should return WebBackForwardList instance.");
68             Assert.Greater(webView.BackForwardList.ItemCount, 0, "ItemCount should be greater than 0.");
69
70             webView.PageLoadFinished -= onLoadFinished;
71
72             tlog.Debug(tag, $"WebBackForwardListConstructor END (OK)");
73         }
74
75         [Test]
76         [Category("P1")]
77         [Description("WebBackForwardList GetCurrentItem.")]
78         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetCurrentItem M")]
79         [Property("SPEC_URL", "-")]
80         [Property("CRITERIA", "MR")]
81         [Property("COVPARAM", "")]
82         [Property("AUTHOR", "guowei.wang@samsung.com")]
83         public async Task WebBackForwardListGetCurrentItem()
84         {
85             tlog.Debug(tag, $"WebBackForwardListGetCurrentItem START");
86
87             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
88             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
89             {
90                 tlog.Info(tag, "onLoadFinished is called!");
91                 tcs.TrySetResult(true);
92             };
93             webView.PageLoadFinished += onLoadFinished;
94
95             webView.LoadUrl(url);
96             var result = await tcs.Task;
97             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
98
99             // Make current thread (CPU) sleep...
100             await Task.Delay(1);
101
102             Assert.IsNotNull(webView.BackForwardList.GetCurrentItem(), "handle should not be null.");
103
104             webView.PageLoadFinished -= onLoadFinished;
105
106             tlog.Debug(tag, $"WebBackForwardListGetCurrentItem END (OK)");
107         }
108
109         [Test]
110         [Category("P1")]
111         [Description("WebBackForwardList GetPreviousItem.")]
112         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetPreviousItem M")]
113         [Property("SPEC_URL", "-")]
114         [Property("CRITERIA", "MR")]
115         [Property("COVPARAM", "")]
116         [Property("AUTHOR", "guowei.wang@samsung.com")]
117         public async Task WebBackForwardListGetPreviousItem()
118         {
119             tlog.Debug(tag, $"WebBackForwardListGetPreviousItem START");
120
121             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
122             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
123             {
124                 tlog.Info(tag, "onLoadFinished is called!");
125                 tcs.TrySetResult(true);
126             };
127             webView.PageLoadFinished += onLoadFinished;
128
129             webView.LoadUrl(url);
130             var result = await tcs.Task;
131             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
132
133             // Make current thread (CPU) sleep...
134             await Task.Delay(1);
135
136             webView.PageLoadFinished -= onLoadFinished;
137
138             // Load second url.
139             TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
140             EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
141             {
142                 tlog.Info(tag, "onLoadFinished is called!");
143                 tcs2.TrySetResult(true);
144             };
145             webView.PageLoadFinished += onLoadFinished2;
146
147             webView.LoadUrl(secondUrl);
148             var result2 = await tcs2.Task;
149             Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
150
151             // Make current thread (CPU) sleep...
152             await Task.Delay(1);
153
154             Assert.IsNotNull(webView.BackForwardList.GetPreviousItem(), "handle should not be null.");
155
156             webView.PageLoadFinished -= onLoadFinished2;
157
158             tlog.Debug(tag, $"WebBackForwardListGetPreviousItem END (OK)");
159         }
160
161         [Test]
162         [Category("P1")]
163         [Description("WebBackForwardList GetNextItem.")]
164         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetNextItem M")]
165         [Property("SPEC_URL", "-")]
166         [Property("CRITERIA", "MR")]
167         [Property("COVPARAM", "")]
168         [Property("AUTHOR", "guowei.wang@samsung.com")]
169         public async Task WebBackForwardListGetNextItem()
170         {
171             tlog.Debug(tag, $"WebBackForwardListGetNextItem START");
172
173             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
174             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
175             {
176                 tlog.Info(tag, "onLoadFinished is called!");
177                 tcs.TrySetResult(true);
178             };
179             webView.PageLoadFinished += onLoadFinished;
180
181             webView.LoadUrl(url);
182             var result = await tcs.Task;
183             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
184
185             // Make current thread (CPU) sleep...
186             await Task.Delay(1);
187
188             webView.PageLoadFinished -= onLoadFinished;
189
190             // Load second url.
191             TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
192             EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
193             {
194                 tlog.Info(tag, "onLoadFinished is called!");
195                 tcs2.TrySetResult(true);
196             };
197             webView.PageLoadFinished += onLoadFinished2;
198
199             webView.LoadUrl(secondUrl);
200             var result2 = await tcs2.Task;
201             Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
202
203             // Make current thread (CPU) sleep...
204             await Task.Delay(1);
205
206             webView.GoBack();
207             Assert.IsNotNull(webView.BackForwardList.GetNextItem(), "handle should not be null.");
208
209             webView.PageLoadFinished -= onLoadFinished2;
210
211             tlog.Debug(tag, $"WebBackForwardListGetNextItem END (OK)");
212         }
213
214         [Test]
215         [Category("P1")]
216         [Description("WebBackForwardList GetItemAtIndex.")]
217         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetItemAtIndex M")]
218         [Property("SPEC_URL", "-")]
219         [Property("CRITERIA", "MR")]
220         [Property("COVPARAM", "")]
221         [Property("AUTHOR", "guowei.wang@samsung.com")]
222         public async Task WebBackForwardListGetItemAtIndex()
223         {
224             tlog.Debug(tag, $"WebBackForwardListGetItemAtIndex START");
225
226             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
227             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
228             {
229                 tlog.Info(tag, "onLoadFinished is called!");
230                 tcs.TrySetResult(true);
231             };
232             webView.PageLoadFinished += onLoadFinished;
233
234             webView.LoadUrl(url);
235             var result = await tcs.Task;
236             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
237
238             // Make current thread (CPU) sleep...
239             await Task.Delay(1);
240
241             webView.PageLoadFinished -= onLoadFinished;
242
243             // Load second url.
244             TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
245             EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
246             {
247                 tlog.Info(tag, "onLoadFinished is called!");
248                 tcs2.TrySetResult(true);
249             };
250             webView.PageLoadFinished += onLoadFinished2;
251
252             webView.LoadUrl(secondUrl);
253             var result2 = await tcs2.Task;
254             Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
255
256             // Make current thread (CPU) sleep...
257             await Task.Delay(1);
258
259             Assert.IsNotNull(webView.BackForwardList.GetItemAtIndex(0), "handle should not be null.");
260
261             webView.PageLoadFinished -= onLoadFinished2;
262
263             tlog.Debug(tag, $"WebBackForwardListGetItemAtIndex END (OK)");
264         }
265
266         //[Test]
267         //[Category("P1")]
268         //[Description("WebBackForwardList GetBackwardItems.")]
269         //[Property("SPEC", "Tizen.NUI.WebBackForwardList.GetBackwardItems M")]
270         //[Property("SPEC_URL", "-")]
271         //[Property("CRITERIA", "MR")]
272         //[Property("COVPARAM", "")]
273         //[Property("AUTHOR", "guowei.wang@samsung.com")]
274         //public async Task WebBackForwardListGetBackwardItems()
275         //{
276         //    tlog.Debug(tag, $"WebBackForwardListGetBackwardItems START");
277
278         //    TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
279         //    EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
280         //    {
281         //        tlog.Info(tag, "onLoadFinished is called!");
282         //        tcs.TrySetResult(true);
283         //    };
284         //    webView.PageLoadFinished += onLoadFinished;
285
286         //    webView.LoadUrl(url);
287         //    var result = await tcs.Task;
288         //    Assert.IsTrue(result, "PageLoadFinished event should be invoked");
289
290         //    // Make current thread (CPU) sleep...
291         //    await Task.Delay(1);
292
293         //    webView.PageLoadFinished -= onLoadFinished;
294
295         //    // Load second url.
296         //    TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
297         //    EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
298         //    {
299         //        tlog.Info(tag, "onLoadFinished is called!");
300         //        tcs2.TrySetResult(true);
301         //    };
302         //    webView.PageLoadFinished += onLoadFinished2;
303
304         //    webView.LoadUrl(secondUrl);
305         //    var result2 = await tcs2.Task;
306         //    Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
307
308         //    // Make current thread (CPU) sleep...
309         //    await Task.Delay(1);
310
311         //    Assert.IsNotNull(webView.BackForwardList.GetBackwardItems(1), "handle should not be null.");
312
313         //    webView.PageLoadFinished -= onLoadFinished2;
314
315         //    tlog.Debug(tag, $"WebBackForwardListGetBackwardItems END (OK)");
316         //}
317
318         //[Test]
319         //[Category("P1")]
320         //[Description("WebBackForwardList GetForwardItems.")]
321         //[Property("SPEC", "Tizen.NUI.WebBackForwardList.GetForwardItems M")]
322         //[Property("SPEC_URL", "-")]
323         //[Property("CRITERIA", "MR")]
324         //[Property("COVPARAM", "")]
325         //[Property("AUTHOR", "guowei.wang@samsung.com")]
326         //public async Task WebBackForwardListGetForwardItems()
327         //{
328         //    tlog.Debug(tag, $"WebBackForwardListGetForwardItems START");
329
330         //    TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
331         //    EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
332         //    {
333         //        tlog.Info(tag, "onLoadFinished is called!");
334         //        tcs.TrySetResult(true);
335         //    };
336         //    webView.PageLoadFinished += onLoadFinished;
337
338         //    webView.LoadUrl(url);
339         //    var result = await tcs.Task;
340         //    Assert.IsTrue(result, "PageLoadFinished event should be invoked");
341
342         //    // Make current thread (CPU) sleep...
343         //    await Task.Delay(1);
344
345         //    webView.PageLoadFinished -= onLoadFinished;
346
347         //    // Load second url.
348         //    TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
349         //    EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
350         //    {
351         //        tlog.Info(tag, "onLoadFinished is called!");
352         //        tcs2.TrySetResult(true);
353         //    };
354         //    webView.PageLoadFinished += onLoadFinished2;
355
356         //    webView.LoadUrl(secondUrl);
357         //    var result2 = await tcs2.Task;
358         //    Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
359
360         //    // Make current thread (CPU) sleep...
361         //    await Task.Delay(1);
362
363         //    webView.GoBack();
364         //    Assert.IsNotNull(webView.BackForwardList.GetForwardItems(1), "handle should not be null.");
365
366         //    webView.PageLoadFinished -= onLoadFinished2;
367
368         //    tlog.Debug(tag, $"WebBackForwardListGetForwardItems END (OK)");
369         //}
370
371         [Test]
372         [Category("P1")]
373         [Description("WebBackForwardListItem Url.")]
374         [Property("SPEC", "Tizen.NUI.WebBackForwardListItem.Url A")]
375         [Property("SPEC_URL", "-")]
376         [Property("CRITERIA", "PRO")]
377         [Property("COVPARAM", "")]
378         [Property("AUTHOR", "guowei.wang@samsung.com")]
379         public async Task WebBackForwardListItemUrl()
380         {
381             tlog.Debug(tag, $"WebBackForwardListItemUrl START");
382
383             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
384             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
385             {
386                 tlog.Info(tag, "onLoadFinished is called!");
387                 tcs.TrySetResult(true);
388             };
389             webView.PageLoadFinished += onLoadFinished;
390
391             webView.LoadUrl(url);
392             var result = await tcs.Task;
393             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
394
395             // Make current thread (CPU) sleep...
396             await Task.Delay(1);
397
398             var testingTarget = webView.BackForwardList.GetCurrentItem();
399             Assert.IsNotNull(testingTarget, "Handle should not be null.");
400             Assert.IsNotNull(testingTarget.Url, "Url should not be null.");
401             Assert.IsTrue(testingTarget.Url.Contains("index.html"), "Url of current item should contain a correct string.");
402
403             webView.PageLoadFinished -= onLoadFinished;
404
405             tlog.Debug(tag, $"WebBackForwardListItemUrl END (OK)");
406         }
407
408         [Test]
409         [Category("P1")]
410         [Description("WebBackForwardListItem Title.")]
411         [Property("SPEC", "Tizen.NUI.WebBackForwardListItem.Title A")]
412         [Property("SPEC_URL", "-")]
413         [Property("CRITERIA", "PRO")]
414         [Property("COVPARAM", "")]
415         [Property("AUTHOR", "guowei.wang@samsung.com")]
416         public async Task WebBackForwardListItemTitle()
417         {
418             tlog.Debug(tag, $"WebBackForwardListItemTitle START");
419
420             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
421             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
422             {
423                 tlog.Info(tag, "onLoadFinished is called!");
424                 tcs.TrySetResult(true);
425             };
426             webView.PageLoadFinished += onLoadFinished;
427
428             webView.LoadUrl(url);
429             var result = await tcs.Task;
430             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
431
432             // Make current thread (CPU) sleep...
433             await Task.Delay(1);
434
435             var testingTarget = webView.BackForwardList.GetCurrentItem();
436             Assert.IsNotNull(testingTarget, "handle should not be null.");
437             Assert.IsNotNull(testingTarget.Title, "Title should not be null.");
438             Assert.IsTrue(testingTarget.Title.Contains("Title"), "Title of current item should contain a correct string.");
439
440             webView.PageLoadFinished -= onLoadFinished;
441
442             tlog.Debug(tag, $"WebBackForwardListItemTitle END (OK)");
443         }
444
445         [Test]
446         [Category("P1")]
447         [Description("WebBackForwardListItem OriginalUrl.")]
448         [Property("SPEC", "Tizen.NUI.WebBackForwardListItem.OriginalUrl A")]
449         [Property("SPEC_URL", "-")]
450         [Property("CRITERIA", "PRO")]
451         [Property("COVPARAM", "")]
452         [Property("AUTHOR", "guowei.wang@samsung.com")]
453         public async Task WebBackForwardListItemOriginalUrl()
454         {
455             tlog.Debug(tag, $"WebBackForwardListItemOriginalUrl START");
456
457             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
458             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
459             {
460                 tlog.Info(tag, "onLoadFinished is called!");
461                 tcs.TrySetResult(true);
462             };
463             webView.PageLoadFinished += onLoadFinished;
464
465             webView.LoadUrl(url);
466             var result = await tcs.Task;
467             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
468
469             // Make current thread (CPU) sleep...
470             await Task.Delay(1);
471
472             var testingTarget = webView.BackForwardList.GetCurrentItem();
473             Assert.IsNotNull(testingTarget, "Handle should not be null.");
474             Assert.IsNotNull(testingTarget.OriginalUrl, "Url should not be null.");
475             Assert.IsTrue(testingTarget.OriginalUrl.Contains("index.html"), "Url of current item should contain a correct string.");
476
477             webView.PageLoadFinished -= onLoadFinished;
478
479             tlog.Debug(tag, $"WebBackForwardListItemOriginalUrl END (OK)");
480         }
481     }
482 }