[NUI] Add TCs of WebView & Update some TCs of NUI.Devel.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / WebView / TSWebPolicyDecisionMaker.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/WebPolicyDecisionMaker")]
14     public class InternalWebPolicyDecisionMakerTest
15     {
16         private const string tag = "NUITEST";
17         private string url = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "picture.png";
18         private static string[] runtimeArgs = { "Tizen.NUI.Devel.Tests", "--enable-dali-window", "--enable-spatial-navigation" };
19         private const string USER_AGENT = "Mozilla/5.0 (SMART-TV; Linux; Tizen 6.0) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/4.0 Chrome/76.0.3809.146 TV Safari/537.36";
20
21         [SetUp]
22         public void Init()
23         {
24             tlog.Info(tag, "Init() is called!");
25         }
26
27         [TearDown]
28         public void Destroy()
29         {
30             tlog.Info(tag, "Destroy() is called!");
31         }
32
33         [Test]
34         [Category("P1")]
35         [Description("WebPolicyDecisionMaker Url.")]
36         [Property("SPEC", "Tizen.NUI.WebPolicyDecisionMaker.Url A")]
37         [Property("SPEC_URL", "-")]
38         [Property("CRITERIA", "PRO")]
39         [Property("COVPARAM", "")]
40         [Property("AUTHOR", "guowei.wang@samsung.com")]
41         public async Task WebPolicyDecisionMakerUrl()
42         {
43             tlog.Debug(tag, $"WebViewResponsePolicyDecidedEventArgsConstructor START");
44
45             var testingTarget = new Tizen.NUI.BaseComponents.WebView(runtimeArgs)
46             {
47                 Size = new Size(500, 200),
48                 UserAgent = USER_AGENT
49             };
50             Assert.IsNotNull(testingTarget, "null handle");
51             Assert.IsInstanceOf<Tizen.NUI.BaseComponents.WebView>(testingTarget, "Should return Tizen.NUI.BaseComponents.WebView instance.");
52
53             testingTarget.ResponsePolicyDecided += OnResponsePolicyDecided;
54             NUIApplication.GetDefaultWindow().Add(testingTarget);
55             
56             testingTarget.LoadUrl("https://www.youtube.com");
57
58             await Task.Delay(30000);
59             testingTarget.ClearCache();
60             testingTarget.ClearCookies();
61             NUIApplication.GetDefaultWindow().Remove(testingTarget);
62
63             testingTarget.Dispose();
64             tlog.Debug(tag, $"WebPolicyDecisionMakerUrl END (OK)");
65         }
66
67         private void OnResponsePolicyDecided(object sender, WebViewResponsePolicyDecidedEventArgs e)
68         {
69             tlog.Info(tag, $"response policy decided, Url: {e.ResponsePolicyDecisionMaker.Url}");
70             tlog.Info(tag, $"response policy decided, Cookie: {e.ResponsePolicyDecisionMaker.Cookie}");
71             tlog.Info(tag, $"response policy decided, PolicyDecisionType: {e.ResponsePolicyDecisionMaker.PolicyDecisionType}");
72             tlog.Info(tag, $"response policy decided, ResponseMime: {e.ResponsePolicyDecisionMaker.ResponseMime}");
73             tlog.Info(tag, $"response policy decided, ResponseStatusCode: {e.ResponsePolicyDecisionMaker.ResponseStatusCode}");
74             tlog.Info(tag, $"response policy decided, DecisionNavigationType: {e.ResponsePolicyDecisionMaker.DecisionNavigationType}");
75             tlog.Info(tag, $"response policy decided, Scheme: {e.ResponsePolicyDecisionMaker.Scheme}");
76             if (e.ResponsePolicyDecisionMaker.Frame != null)
77             {
78                 tlog.Info(tag, $"response policy decided, Frame.IsMainFrame: {e.ResponsePolicyDecisionMaker.Frame.IsMainFrame}");
79             }
80             e.ResponsePolicyDecisionMaker.Ignore();
81             e.ResponsePolicyDecisionMaker.Suspend();
82             e.ResponsePolicyDecisionMaker.Use();
83         }
84     }
85 }