3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6 using System.Threading.Tasks;
8 namespace Tizen.NUI.Devel.Tests
10 using tlog = Tizen.Log;
13 [Description("internal/WebView/WebBackForwardList")]
14 public class InternalWebBackForwardListTest
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;
24 webView = new BaseComponents.WebView()
26 Size = new Size(150, 100),
28 tlog.Info(tag, "Init() is called!");
34 tlog.Info(tag, "Destroy() is being called!");
36 tlog.Info(tag, "Destroy() is called!");
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()
49 tlog.Debug(tag, $"WebBackForwardListConstructor START");
51 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
52 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
54 tlog.Info(tag, "onLoadFinished is called!");
55 tcs.TrySetResult(true);
57 webView.PageLoadFinished += onLoadFinished;
60 var result = await tcs.Task;
61 Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
63 // Make current thread (CPU) sleep...
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.");
70 webView.PageLoadFinished -= onLoadFinished;
72 tlog.Debug(tag, $"WebBackForwardListConstructor END (OK)");
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()
85 tlog.Debug(tag, $"WebBackForwardListGetCurrentItem START");
87 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
88 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
90 tlog.Info(tag, "onLoadFinished is called!");
91 tcs.TrySetResult(true);
93 webView.PageLoadFinished += onLoadFinished;
96 var result = await tcs.Task;
97 Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
99 // Make current thread (CPU) sleep...
102 Assert.IsNotNull(webView.BackForwardList.GetCurrentItem(), "handle should not be null.");
104 webView.PageLoadFinished -= onLoadFinished;
106 tlog.Debug(tag, $"WebBackForwardListGetCurrentItem END (OK)");
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()
119 tlog.Debug(tag, $"WebBackForwardListGetPreviousItem START");
121 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
122 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
124 tlog.Info(tag, "onLoadFinished is called!");
125 tcs.TrySetResult(true);
127 webView.PageLoadFinished += onLoadFinished;
129 webView.LoadUrl(url);
130 var result = await tcs.Task;
131 Assert.IsTrue(result, "PageLoadFinished event should be invoked");
133 // Make current thread (CPU) sleep...
136 webView.PageLoadFinished -= onLoadFinished;
139 TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
140 EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
142 tlog.Info(tag, "onLoadFinished is called!");
143 tcs2.TrySetResult(true);
145 webView.PageLoadFinished += onLoadFinished2;
147 webView.LoadUrl(secondUrl);
148 var result2 = await tcs2.Task;
149 Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
151 // Make current thread (CPU) sleep...
154 Assert.IsNotNull(webView.BackForwardList.GetPreviousItem(), "handle should not be null.");
156 webView.PageLoadFinished -= onLoadFinished2;
158 tlog.Debug(tag, $"WebBackForwardListGetPreviousItem END (OK)");
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()
171 tlog.Debug(tag, $"WebBackForwardListGetNextItem START");
173 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
174 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
176 tlog.Info(tag, "onLoadFinished is called!");
177 tcs.TrySetResult(true);
179 webView.PageLoadFinished += onLoadFinished;
181 webView.LoadUrl(url);
182 var result = await tcs.Task;
183 Assert.IsTrue(result, "PageLoadFinished event should be invoked");
185 // Make current thread (CPU) sleep...
188 webView.PageLoadFinished -= onLoadFinished;
191 TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
192 EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
194 tlog.Info(tag, "onLoadFinished is called!");
195 tcs2.TrySetResult(true);
197 webView.PageLoadFinished += onLoadFinished2;
199 webView.LoadUrl(secondUrl);
200 var result2 = await tcs2.Task;
201 Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
203 // Make current thread (CPU) sleep...
207 Assert.IsNotNull(webView.BackForwardList.GetNextItem(), "handle should not be null.");
209 webView.PageLoadFinished -= onLoadFinished2;
211 tlog.Debug(tag, $"WebBackForwardListGetNextItem END (OK)");
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()
224 tlog.Debug(tag, $"WebBackForwardListGetItemAtIndex START");
226 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
227 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
229 tlog.Info(tag, "onLoadFinished is called!");
230 tcs.TrySetResult(true);
232 webView.PageLoadFinished += onLoadFinished;
234 webView.LoadUrl(url);
235 var result = await tcs.Task;
236 Assert.IsTrue(result, "PageLoadFinished event should be invoked");
238 // Make current thread (CPU) sleep...
241 webView.PageLoadFinished -= onLoadFinished;
244 TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
245 EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
247 tlog.Info(tag, "onLoadFinished is called!");
248 tcs2.TrySetResult(true);
250 webView.PageLoadFinished += onLoadFinished2;
252 webView.LoadUrl(secondUrl);
253 var result2 = await tcs2.Task;
254 Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
256 // Make current thread (CPU) sleep...
259 Assert.IsNotNull(webView.BackForwardList.GetItemAtIndex(0), "handle should not be null.");
261 webView.PageLoadFinished -= onLoadFinished2;
263 tlog.Debug(tag, $"WebBackForwardListGetItemAtIndex END (OK)");
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()
276 // tlog.Debug(tag, $"WebBackForwardListGetBackwardItems START");
278 // TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
279 // EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
281 // tlog.Info(tag, "onLoadFinished is called!");
282 // tcs.TrySetResult(true);
284 // webView.PageLoadFinished += onLoadFinished;
286 // webView.LoadUrl(url);
287 // var result = await tcs.Task;
288 // Assert.IsTrue(result, "PageLoadFinished event should be invoked");
290 // // Make current thread (CPU) sleep...
291 // await Task.Delay(1);
293 // webView.PageLoadFinished -= onLoadFinished;
295 // // Load second url.
296 // TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
297 // EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
299 // tlog.Info(tag, "onLoadFinished is called!");
300 // tcs2.TrySetResult(true);
302 // webView.PageLoadFinished += onLoadFinished2;
304 // webView.LoadUrl(secondUrl);
305 // var result2 = await tcs2.Task;
306 // Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
308 // // Make current thread (CPU) sleep...
309 // await Task.Delay(1);
311 // Assert.IsNotNull(webView.BackForwardList.GetBackwardItems(1), "handle should not be null.");
313 // webView.PageLoadFinished -= onLoadFinished2;
315 // tlog.Debug(tag, $"WebBackForwardListGetBackwardItems END (OK)");
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()
328 // tlog.Debug(tag, $"WebBackForwardListGetForwardItems START");
330 // TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
331 // EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
333 // tlog.Info(tag, "onLoadFinished is called!");
334 // tcs.TrySetResult(true);
336 // webView.PageLoadFinished += onLoadFinished;
338 // webView.LoadUrl(url);
339 // var result = await tcs.Task;
340 // Assert.IsTrue(result, "PageLoadFinished event should be invoked");
342 // // Make current thread (CPU) sleep...
343 // await Task.Delay(1);
345 // webView.PageLoadFinished -= onLoadFinished;
347 // // Load second url.
348 // TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>(false);
349 // EventHandler<WebViewPageLoadEventArgs> onLoadFinished2 = (s, e) =>
351 // tlog.Info(tag, "onLoadFinished is called!");
352 // tcs2.TrySetResult(true);
354 // webView.PageLoadFinished += onLoadFinished2;
356 // webView.LoadUrl(secondUrl);
357 // var result2 = await tcs2.Task;
358 // Assert.IsTrue(result2, "PageLoadFinished event should be invoked");
360 // // Make current thread (CPU) sleep...
361 // await Task.Delay(1);
364 // Assert.IsNotNull(webView.BackForwardList.GetForwardItems(1), "handle should not be null.");
366 // webView.PageLoadFinished -= onLoadFinished2;
368 // tlog.Debug(tag, $"WebBackForwardListGetForwardItems END (OK)");
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()
381 tlog.Debug(tag, $"WebBackForwardListItemUrl START");
383 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
384 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
386 tlog.Info(tag, "onLoadFinished is called!");
387 tcs.TrySetResult(true);
389 webView.PageLoadFinished += onLoadFinished;
391 webView.LoadUrl(url);
392 var result = await tcs.Task;
393 Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
395 // Make current thread (CPU) sleep...
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.");
403 webView.PageLoadFinished -= onLoadFinished;
405 tlog.Debug(tag, $"WebBackForwardListItemUrl END (OK)");
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()
418 tlog.Debug(tag, $"WebBackForwardListItemTitle START");
420 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
421 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
423 tlog.Info(tag, "onLoadFinished is called!");
424 tcs.TrySetResult(true);
426 webView.PageLoadFinished += onLoadFinished;
428 webView.LoadUrl(url);
429 var result = await tcs.Task;
430 Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
432 // Make current thread (CPU) sleep...
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.");
440 webView.PageLoadFinished -= onLoadFinished;
442 tlog.Debug(tag, $"WebBackForwardListItemTitle END (OK)");
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()
455 tlog.Debug(tag, $"WebBackForwardListItemOriginalUrl START");
457 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
458 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
460 tlog.Info(tag, "onLoadFinished is called!");
461 tcs.TrySetResult(true);
463 webView.PageLoadFinished += onLoadFinished;
465 webView.LoadUrl(url);
466 var result = await tcs.Task;
467 Assert.IsTrue(result, "PageLoadFinished event should be invoked.");
469 // Make current thread (CPU) sleep...
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.");
477 webView.PageLoadFinished -= onLoadFinished;
479 tlog.Debug(tag, $"WebBackForwardListItemOriginalUrl END (OK)");