124d29fa47ee77b9632d4fe0299f6a0f653b6478
[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             Assert.IsNotNull(webView.BackForwardList, "null handle");
64             Assert.IsInstanceOf<WebBackForwardList>(webView.BackForwardList, "Should return WebBackForwardList instance.");
65             Assert.Greater(webView.BackForwardList.ItemCount, 0, "ItemCount should be greater than 0.");
66
67             webView.PageLoadFinished -= onLoadFinished;
68
69             tlog.Debug(tag, $"WebBackForwardListConstructor END (OK)");
70         }
71
72         [Test]
73         [Category("P1")]
74         [Description("WebBackForwardList GetCurrentItem.")]
75         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetCurrentItem M")]
76         [Property("SPEC_URL", "-")]
77         [Property("CRITERIA", "MR")]
78         [Property("COVPARAM", "")]
79         [Property("AUTHOR", "guowei.wang@samsung.com")]
80         public async Task WebBackForwardListGetCurrentItem()
81         {
82             tlog.Debug(tag, $"WebBackForwardListGetCurrentItem START");
83
84             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
85             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
86             {
87                 tlog.Info(tag, "onLoadFinished is called!");
88                 tcs.TrySetResult(true);
89             };
90             webView.PageLoadFinished += onLoadFinished;
91
92             webView.LoadUrl(url);
93             var result = await tcs.Task;
94             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
95             Assert.IsNotNull(webView.BackForwardList.GetCurrentItem(), "handle should not be null.");
96
97             webView.PageLoadFinished -= onLoadFinished;
98
99             tlog.Debug(tag, $"WebBackForwardListGetCurrentItem END (OK)");
100         }
101
102         [Test]
103         [Category("P1")]
104         [Description("WebBackForwardList GetPreviousItem.")]
105         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetPreviousItem M")]
106         [Property("SPEC_URL", "-")]
107         [Property("CRITERIA", "MR")]
108         [Property("COVPARAM", "")]
109         [Property("AUTHOR", "guowei.wang@samsung.com")]
110         public async Task WebBackForwardListGetPreviousItem()
111         {
112             tlog.Debug(tag, $"WebBackForwardListGetPreviousItem START");
113
114             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
115             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
116             {
117                 if (webView.Url.Contains("index.html"))
118                 {
119                     tlog.Info(tag, "onLoadFinished is called!");
120                     webView.LoadUrl(secondUrl);
121                 }
122                 else
123                 {
124                     tlog.Info(tag, "onLoadFinished is called!");
125                     tcs.TrySetResult(true);
126                 }
127             };
128             webView.PageLoadFinished += onLoadFinished;
129
130             webView.LoadUrl(url);
131             var result = await tcs.Task;
132             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
133             Assert.IsNotNull(webView.BackForwardList.GetPreviousItem(), "handle should not be null.");
134
135             webView.PageLoadFinished -= onLoadFinished;
136
137             tlog.Debug(tag, $"WebBackForwardListGetPreviousItem END (OK)");
138         }
139
140         [Test]
141         [Category("P1")]
142         [Description("WebBackForwardList GetNextItem.")]
143         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetNextItem M")]
144         [Property("SPEC_URL", "-")]
145         [Property("CRITERIA", "MR")]
146         [Property("COVPARAM", "")]
147         [Property("AUTHOR", "guowei.wang@samsung.com")]
148         public async Task WebBackForwardListGetNextItem()
149         {
150             tlog.Debug(tag, $"WebBackForwardListGetNextItem START");
151
152             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
153             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
154             {
155                 if (webView.Url.Contains("index.html"))
156                 {
157                     tlog.Info(tag, "onLoadFinished is called!");
158                     webView.LoadUrl(secondUrl);
159                 }
160                 else
161                 {
162                     tlog.Info(tag, "onLoadFinished is called!");
163                     webView.GoBack();
164                     tcs.TrySetResult(true);
165                 }
166             };
167             webView.PageLoadFinished += onLoadFinished;
168
169             webView.LoadUrl(url);
170             var result = await tcs.Task;
171             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
172             Assert.IsNotNull(webView.BackForwardList.GetNextItem(), "handle should not be null.");
173
174             webView.PageLoadFinished -= onLoadFinished;
175
176             tlog.Debug(tag, $"WebBackForwardListGetNextItem END (OK)");
177         }
178
179         [Test]
180         [Category("P1")]
181         [Description("WebBackForwardList GetItemAtIndex.")]
182         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetItemAtIndex M")]
183         [Property("SPEC_URL", "-")]
184         [Property("CRITERIA", "MR")]
185         [Property("COVPARAM", "")]
186         [Property("AUTHOR", "guowei.wang@samsung.com")]
187         public async Task WebBackForwardListGetItemAtIndex()
188         {
189             tlog.Debug(tag, $"WebBackForwardListGetItemAtIndex START");
190
191             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
192             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
193             {
194                 if (webView.Url.Contains("index.html"))
195                 {
196                     tlog.Info(tag, "onLoadFinished is called!");
197                     webView.LoadUrl(secondUrl);
198                 }
199                 else
200                 {
201                     tlog.Info(tag, "onLoadFinished is called!");
202                     tcs.TrySetResult(true);
203                 }
204             };
205             webView.PageLoadFinished += onLoadFinished;
206
207             webView.LoadUrl(url);
208             var result = await tcs.Task;
209             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
210             Assert.IsNotNull(webView.BackForwardList.GetItemAtIndex(0), "handle should not be null.");
211
212             webView.PageLoadFinished -= onLoadFinished;
213
214             tlog.Debug(tag, $"WebBackForwardListGetItemAtIndex END (OK)");
215         }
216
217         [Test]
218         [Category("P1")]
219         [Description("WebBackForwardList GetBackwardItems.")]
220         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetBackwardItems M")]
221         [Property("SPEC_URL", "-")]
222         [Property("CRITERIA", "MR")]
223         [Property("COVPARAM", "")]
224         [Property("AUTHOR", "guowei.wang@samsung.com")]
225         public async Task WebBackForwardListGetBackwardItems()
226         {
227             tlog.Debug(tag, $"WebBackForwardListGetBackwardItems START");
228
229             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
230             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
231             {
232                 if (webView.Url.Contains("index.html"))
233                 {
234                     tlog.Info(tag, "onLoadFinished is called!");
235                     webView.LoadUrl(secondUrl);
236                 }
237                 else
238                 {
239                     tlog.Info(tag, "onLoadFinished is called!");
240                     tcs.TrySetResult(true);
241                 }
242             };
243             webView.PageLoadFinished += onLoadFinished;
244
245             webView.LoadUrl(url);
246             var result = await tcs.Task;
247             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
248             Assert.IsNotNull(webView.BackForwardList.GetBackwardItems(2), "handle should not be null.");
249
250             webView.PageLoadFinished -= onLoadFinished;
251
252             tlog.Debug(tag, $"WebBackForwardListGetBackwardItems END (OK)");
253         }
254
255         [Test]
256         [Category("P1")]
257         [Description("WebBackForwardList GetForwardItems.")]
258         [Property("SPEC", "Tizen.NUI.WebBackForwardList.GetForwardItems M")]
259         [Property("SPEC_URL", "-")]
260         [Property("CRITERIA", "MR")]
261         [Property("COVPARAM", "")]
262         [Property("AUTHOR", "guowei.wang@samsung.com")]
263         public async Task WebBackForwardListGetForwardItems()
264         {
265             tlog.Debug(tag, $"WebBackForwardListGetForwardItems START");
266
267             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
268             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
269             {
270                 if (webView.Url.Contains("index.html"))
271                 {
272                     tlog.Info(tag, "onLoadFinished is called!");
273                     webView.LoadUrl(secondUrl);
274                 }
275                 else
276                 {
277                     tlog.Info(tag, "onLoadFinished is called!");
278                     webView.GoBack();
279                     tcs.TrySetResult(true);
280                 }
281             };
282             webView.PageLoadFinished += onLoadFinished;
283
284             webView.LoadUrl(url);
285             var result = await tcs.Task;
286             Assert.IsTrue(result, "PageLoadFinished event should be invoked");
287             Assert.IsNotNull(webView.BackForwardList.GetForwardItems(2), "handle should not be null.");
288
289             webView.PageLoadFinished -= onLoadFinished;
290
291             tlog.Debug(tag, $"WebBackForwardListGetForwardItems END (OK)");
292         }
293
294         [Test]
295         [Category("P1")]
296         [Description("WebBackForwardListItem Url.")]
297         [Property("SPEC", "Tizen.NUI.WebBackForwardListItem.Url A")]
298         [Property("SPEC_URL", "-")]
299         [Property("CRITERIA", "PRO")]
300         [Property("COVPARAM", "")]
301         [Property("AUTHOR", "guowei.wang@samsung.com")]
302         public async Task WebBackForwardListItemUrl()
303         {
304             tlog.Debug(tag, $"WebBackForwardListItemUrl START");
305
306             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
307             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
308             {
309                 tlog.Info(tag, "onLoadFinished is called!");
310                 tcs.TrySetResult(true);
311             };
312             webView.PageLoadFinished += onLoadFinished;
313
314             webView.LoadUrl(url);
315             var result = await tcs.Task;
316             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
317
318             var testingTarget = webView.BackForwardList.GetCurrentItem();
319             Assert.IsNotNull(testingTarget, "Handle should not be null.");
320             Assert.IsNotNull(testingTarget.Url, "Url should not be null.");
321             Assert.IsTrue(testingTarget.Url.Contains("index.html"), "Url of current item should contain a correct string.");
322
323             tlog.Debug(tag, $"WebBackForwardListItemUrl END (OK)");
324         }
325
326         [Test]
327         [Category("P1")]
328         [Description("WebBackForwardListItem Title.")]
329         [Property("SPEC", "Tizen.NUI.WebBackForwardListItem.Title A")]
330         [Property("SPEC_URL", "-")]
331         [Property("CRITERIA", "PRO")]
332         [Property("COVPARAM", "")]
333         [Property("AUTHOR", "guowei.wang@samsung.com")]
334         public async Task WebBackForwardListItemTitle()
335         {
336             tlog.Debug(tag, $"WebBackForwardListItemTitle START");
337
338             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
339             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
340             {
341                 tlog.Info(tag, "onLoadFinished is called!");
342                 tcs.TrySetResult(true);
343             };
344             webView.PageLoadFinished += onLoadFinished;
345
346             webView.LoadUrl(url);
347             var result = await tcs.Task;
348             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
349
350             var testingTarget = webView.BackForwardList.GetCurrentItem();
351             Assert.IsNotNull(testingTarget, "handle should not be null.");
352             Assert.IsNotNull(testingTarget.Title, "Title should not be null.");
353             Assert.IsTrue(testingTarget.Title.Contains("Title"), "Title of current item should contain a correct string.");
354
355             tlog.Debug(tag, $"WebBackForwardListItemTitle END (OK)");
356         }
357
358         [Test]
359         [Category("P1")]
360         [Description("WebBackForwardListItem OriginalUrl.")]
361         [Property("SPEC", "Tizen.NUI.WebBackForwardListItem.OriginalUrl A")]
362         [Property("SPEC_URL", "-")]
363         [Property("CRITERIA", "PRO")]
364         [Property("COVPARAM", "")]
365         [Property("AUTHOR", "guowei.wang@samsung.com")]
366         public async Task WebBackForwardListItemOriginalUrl()
367         {
368             tlog.Debug(tag, $"WebBackForwardListItemOriginalUrl START");
369
370             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
371             EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
372             {
373                 tlog.Info(tag, "onLoadFinished is called!");
374                 tcs.TrySetResult(true);
375             };
376             webView.PageLoadFinished += onLoadFinished;
377
378             webView.LoadUrl(url);
379             var result = await tcs.Task;
380             Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
381
382             var testingTarget = webView.BackForwardList.GetCurrentItem();
383             Assert.IsNotNull(testingTarget, "Handle should not be null.");
384             Assert.IsNotNull(testingTarget.OriginalUrl, "Url should not be null.");
385             Assert.IsTrue(testingTarget.OriginalUrl.Contains("index.html"), "Url of current item should contain a correct string.");
386
387             tlog.Debug(tag, $"WebBackForwardListItemOriginalUrl END (OK)");
388         }
389     }
390 }