1c3f4bf3b06af388c7228048292dab4e4f698d75
[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 urlForResponsePolicyTest = "http://www.samsung.com";
18         private BaseComponents.WebView webView = null;
19
20         [SetUp]
21         public void Init()
22         {
23             webView = new BaseComponents.WebView()
24             {
25                 Size = new Size(150, 100),
26             };
27             tlog.Info(tag, "Init() is called!");
28         }
29
30         [TearDown]
31         public void Destroy()
32         {
33             tlog.Info(tag, "Destroy() is being called!");
34             webView.Dispose();
35             tlog.Info(tag, "Destroy() is called!");
36         }
37
38         [Test]
39         [Category("P1")]
40         [Description("WebPolicyDecisionMaker Url.")]
41         [Property("SPEC", "Tizen.NUI.WebPolicyDecisionMaker.Ignore M")]
42         [Property("SPEC_URL", "-")]
43         [Property("CRITERIA", "PRO")]
44         [Property("COVPARAM", "")]
45         [Property("AUTHOR", "guowei.wang@samsung.com")]
46         public async Task WebPolicyDecisionMakerIgnore()
47         {
48             tlog.Debug(tag, $"WebPolicyDecisionMakerIgnore START");
49
50             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
51             EventHandler<WebViewPolicyDecidedEventArgs> onResponsePolicyDecide = (s, e) =>
52             {
53                 tlog.Info(tag, $"response policy decided, Url: {e.ResponsePolicyDecisionMaker.Url}");
54                 tlog.Info(tag, $"response policy decided, Cookie: {e.ResponsePolicyDecisionMaker.Cookie}");
55                 tlog.Info(tag, $"response policy decided, PolicyDecisionType: {e.ResponsePolicyDecisionMaker.PolicyDecisionType}");
56                 tlog.Info(tag, $"response policy decided, ResponseMime: {e.ResponsePolicyDecisionMaker.ResponseMime}");
57                 tlog.Info(tag, $"response policy decided, ResponseStatusCode: {e.ResponsePolicyDecisionMaker.ResponseStatusCode}");
58                 tlog.Info(tag, $"response policy decided, DecisionNavigationType: {e.ResponsePolicyDecisionMaker.DecisionNavigationType}");
59                 tlog.Info(tag, $"response policy decided, Scheme: {e.ResponsePolicyDecisionMaker.Scheme}");
60                 if (e.ResponsePolicyDecisionMaker.Frame != null)
61                 {
62                     tlog.Info(tag, $"response policy decided, Frame.IsMainFrame: {e.ResponsePolicyDecisionMaker.Frame.IsMainFrame}");
63                 }
64                 e.ResponsePolicyDecisionMaker.Ignore();
65
66                 tcs.TrySetResult(true);
67             };
68             webView.ResponsePolicyDecided += onResponsePolicyDecide;
69
70             webView.LoadUrl(urlForResponsePolicyTest);
71             var result = await tcs.Task;
72             Assert.IsTrue(result, "ResponsePolicyDecided event should be invoked");
73
74             webView.ResponsePolicyDecided -= onResponsePolicyDecide;
75
76             tlog.Debug(tag, $"WebPolicyDecisionMakerIgnore END (OK)");
77         }
78
79         [Test]
80         [Category("P1")]
81         [Description("WebPolicyDecisionMaker Url.")]
82         [Property("SPEC", "Tizen.NUI.WebPolicyDecisionMaker.Suspend M")]
83         [Property("SPEC_URL", "-")]
84         [Property("CRITERIA", "PRO")]
85         [Property("COVPARAM", "")]
86         [Property("AUTHOR", "guowei.wang@samsung.com")]
87         public async Task WebPolicyDecisionMakerSuspend()
88         {
89             tlog.Debug(tag, $"WebPolicyDecisionMakerSuspend START");
90
91             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
92             EventHandler<WebViewPolicyDecidedEventArgs> onResponsePolicyDecide = (s, e) =>
93             {
94                 e.ResponsePolicyDecisionMaker.Suspend();
95
96                 tcs.TrySetResult(true);
97             };
98             webView.ResponsePolicyDecided += onResponsePolicyDecide;
99
100             webView.LoadUrl(urlForResponsePolicyTest);
101             var result = await tcs.Task;
102             Assert.IsTrue(result, "ResponsePolicyDecided event should be invoked");
103
104             webView.ResponsePolicyDecided -= onResponsePolicyDecide;
105
106             tlog.Debug(tag, $"WebPolicyDecisionMakerSuspend END (OK)");
107         }
108
109         [Test]
110         [Category("P1")]
111         [Description("WebPolicyDecisionMaker Url.")]
112         [Property("SPEC", "Tizen.NUI.WebPolicyDecisionMaker.Use M")]
113         [Property("SPEC_URL", "-")]
114         [Property("CRITERIA", "PRO")]
115         [Property("COVPARAM", "")]
116         [Property("AUTHOR", "guowei.wang@samsung.com")]
117         public async Task WebPolicyDecisionMakerUse()
118         {
119             tlog.Debug(tag, $"WebPolicyDecisionMakerUse START");
120
121             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
122             EventHandler<WebViewPolicyDecidedEventArgs> onResponsePolicyDecide = (s, e) =>
123             {
124                 e.ResponsePolicyDecisionMaker.Use();
125
126                 tcs.TrySetResult(true);
127             };
128             webView.ResponsePolicyDecided += onResponsePolicyDecide;
129
130             webView.LoadUrl(urlForResponsePolicyTest);
131             var result = await tcs.Task;
132             Assert.IsTrue(result, "ResponsePolicyDecided event should be invoked");
133
134             webView.ResponsePolicyDecided -= onResponsePolicyDecide;
135
136             tlog.Debug(tag, $"WebPolicyDecisionMakerUse END (OK)");
137         }
138     }
139 }