2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
18 using System.Threading.Tasks;
19 using NUnit.Framework;
20 using NUnit.Framework.TUnit;
22 using Tizen.NUI.Components;
23 using Tizen.NUI.BaseComponents;
25 namespace Tizen.NUI.Tests
28 [Description("Tizen.NUI.View test")]
29 public class WebViewTests
31 private const string tag = "NUITEST";
32 private WearableManualTestNUI _wearTestPage;
33 private TextLabel _label;
35 private BaseComponents.WebView _webView = null;
36 private Window _window = null;
37 private string url = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/index.html";
38 private string urlForContextMenu = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/contextmenu.html";
39 //private string urlForFormSubmit = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/webform.html";
40 private string urlForScrollEdge = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/webscrolledge.html";
41 private string urlForOpenWindow = $"file://{Tizen.Applications.Application.Current.DirectoryInfo.Resource}webview/openwindow.html";
42 private Button _menu = null;
43 private WebContextMenu _contextMenu;
48 Log.Info(tag, "Preconditions for each TEST");
49 if (ManualTest.IsWearable())
51 _label = ManualTest.CreateLabel("This case is unsuitable for wearable, please press PASS button to continue!");
52 _wearTestPage = WearableManualTestNUI.GetInstance();
56 _webView = new BaseComponents.WebView()
58 Size = new Size(1920, 540),
59 ParentOrigin = ParentOrigin.Center,
60 PivotPoint = PivotPoint.Center,
61 PositionUsesPivotPoint = true,
63 _window = Window.Instance;
70 Log.Info(tag, "Postconditions for each TEST, webview is being destroyed.");
72 Log.Info(tag, "Postconditions for each TEST");
75 private void OnContextMenuShown(object sender, WebViewContextMenuShownEventArgs e)
77 Log.Info(tag, "TUnit WebView.WebViewContextMenuShownEvent!!!!!!!!!!!!!!!!!!!!!");
81 private void OnMenuClicked(object sender, ClickedEventArgs e)
83 Log.Info(tag, "TUnit OnMenuClicked!!!!!!!!!!!!!!!!!!!!!");
87 private void OnContextMenuHidden(object sender, WebViewContextMenuHiddenEventArgs e)
89 Log.Info(tag, "TUnit WebView.WebViewContextMenuShownEvent!!!!!!!!!!!!!!!!!!!!!");
95 [Description("Test: Handle event. Try to long-press to trigger the event.")]
96 [Property("SPEC", "Tizen.NUI.BaseComponents.WebView.ContextMenuShown E")]
97 [Property("SPEC_URL", "-")]
98 [Property("CRITERIA", "EVL")]
99 [Property("AUTHOR", "guowei.wang@samsung.com")]
100 [Precondition(1, "In case of Emulator, only use PC keyboard or remote controller of emulator itself.")]
101 [Precondition(2, "If test on TV, prepare mouse and connect to TV.")]
102 [Step(1, "Click to runt TC.")]
103 [Step(2, "Long press image of test page.")]
104 [Step(3, "If there is no exception, test will be automatically passed.")]
105 [Postcondition(1, "NA")]
106 public async Task ContextMenuShown_CB()
108 if (ManualTest.IsWearable())
110 _wearTestPage.ExecuteTC(_label);
111 await ManualTest.WaitForConfirm();
112 _wearTestPage.ClearTestCase(_label);
116 _window.GetDefaultLayer().Add(_webView);
117 FocusManager.Instance.SetCurrentFocusView(_webView);
119 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
120 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
122 Log.Info(tag, "onLoadFinished is called.");
123 tcs.TrySetResult(true);
125 Log.Info(tag, "onLoadFinished is called.");
126 _webView.PageLoadFinished += onLoadFinished;
127 _webView.ContextMenuShown += OnContextMenuShown;
128 Log.Info(tag, "onLoadFinished is called.");
129 _webView.LoadUrl(urlForContextMenu);
131 Log.Info(tag, "onLoadFinished is called.");
132 var result = await tcs.Task;
133 Assert.IsTrue(result, "PageLoadFinished event should be invoked");
135 Log.Info(tag, "onLoadFinished is called.");
137 // Waits for user confirmation.
138 await ManualTest.WaitForConfirm();
139 _webView.PageLoadFinished -= onLoadFinished;
140 _webView.ContextMenuShown -= OnContextMenuShown;
141 _window.GetDefaultLayer().Remove(_webView);
147 [Description("Test: Handle event. Try to long-press to trigger the event.")]
148 [Property("SPEC", "Tizen.NUI.BaseComponents.WebView.ContextMenuShown E")]
149 [Property("SPEC_URL", "-")]
150 [Property("CRITERIA", "EVL")]
151 [Property("AUTHOR", "guowei.wang@samsung.com")]
152 [Precondition(1, "In case of Emulator, only use PC keyboard or remote controller of emulator itself.")]
153 [Precondition(2, "If test on TV, prepare mouse and connect to TV.")]
154 [Step(1, "Click to runt TC.")]
155 [Step(2, "Long press image of test page.")]
156 [Step(3, "If there is no exception, test will be automatically passed.")]
157 [Postcondition(1, "NA")]
158 public async Task ContextMenuHidden_CB()
160 if (ManualTest.IsWearable())
162 _wearTestPage.ExecuteTC(_label);
163 await ManualTest.WaitForConfirm();
164 _wearTestPage.ClearTestCase(_label);
168 _window.GetDefaultLayer().Add(_webView);
169 FocusManager.Instance.SetCurrentFocusView(_webView);
171 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
172 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
174 Log.Info(tag, "onLoadFinished is called.");
175 tcs.TrySetResult(true);
177 Log.Info(tag, "onLoadFinished is called.");
178 _webView.PageLoadFinished += onLoadFinished;
180 EventHandler<WebViewContextMenuShownEventArgs> onContextMenuShown = (s, e) =>
182 Log.Info(tag, "onContextMenuShown is called.");
185 _menu = new Button();
186 _menu.Text = "Click here to trigger menu hide event.";
187 _menu.Feedback = false;
188 _menu.PointSize = 20.0f;
189 _menu.BackgroundColor = Color.Cyan;
190 _menu.Size = new Size(Window.Instance.Size.Width * 0.1f, Window.Instance.Size.Height * 0.05f);
191 _menu.Clicked += OnMenuClicked;
192 _window.GetDefaultLayer().Add(_menu);
194 _contextMenu = e.ContextMenu;
196 _webView.ContextMenuShown += onContextMenuShown;
198 _webView.ContextMenuHidden += OnContextMenuHidden;
199 Log.Info(tag, "onLoadFinished is called.");
200 _webView.LoadUrl(urlForContextMenu);
202 Log.Info(tag, "onLoadFinished is called.");
203 var result = await tcs.Task;
204 Assert.IsTrue(result, "PageLoadFinished event should be invoked");
206 Log.Info(tag, "onLoadFinished is called.");
208 // Waits for user confirmation.
209 await ManualTest.WaitForConfirm();
210 _webView.PageLoadFinished -= onLoadFinished;
211 _webView.ContextMenuShown -= OnContextMenuShown;
212 _webView.ContextMenuHidden -= OnContextMenuHidden;
213 _window.GetDefaultLayer().Remove(_webView);
219 [Description("Test: Handle event. Try to sroll to edge to trigger the event.")]
220 [Property("SPEC", "Tizen.NUI.BaseComponents.WebView.ScrollEdgeReached E")]
221 [Property("SPEC_URL", "-")]
222 [Property("CRITERIA", "EVL")]
223 [Property("AUTHOR", "guowei.wang@samsung.com")]
224 [Precondition(1, "In case of Emulator, only use PC keyboard or remote controller of emulator itself.")]
225 [Precondition(2, "If test on TV, prepare mouse and connect to TV.")]
226 [Step(1, "Click to runt TC.")]
227 [Step(2, "Scroll testing page to edge.")]
228 [Step(3, "If there is no exception, test will be automatically passed.")]
229 [Postcondition(1, "NA")]
230 public async Task ScrollEdgeReached_CB()
232 if (ManualTest.IsWearable())
234 _wearTestPage.ExecuteTC(_label);
235 await ManualTest.WaitForConfirm();
236 _wearTestPage.ClearTestCase(_label);
240 _window.GetDefaultLayer().Add(_webView);
241 FocusManager.Instance.SetCurrentFocusView(_webView);
243 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
244 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
246 Log.Info(tag, "onLoadFinished is called.");
247 tcs.TrySetResult(true);
249 Log.Info(tag, "onLoadFinished is called.");
250 _webView.PageLoadFinished += onLoadFinished;
252 EventHandler<WebViewScrollEdgeReachedEventArgs> onScrollEdgeReached = (s, e) =>
254 Log.Info(tag, "TUnit WebView.ScrollEdgeReached!!!!!!!!!!!!!!!!!!!!!");
255 ManualTest.Confirm();
257 _webView.ScrollEdgeReached += onScrollEdgeReached;
258 Log.Info(tag, "onLoadFinished is called.");
259 _webView.LoadUrl(urlForScrollEdge);
261 Log.Info(tag, "onLoadFinished is called.");
262 var result = await tcs.Task;
263 Assert.IsTrue(result, "PageLoadFinished event should be invoked");
265 Log.Info(tag, "onLoadFinished is called.");
267 // Waits for user confirmation.
268 await ManualTest.WaitForConfirm();
269 _webView.PageLoadFinished -= onLoadFinished;
270 _webView.ScrollEdgeReached -= onScrollEdgeReached;
271 _window.GetDefaultLayer().Remove(_webView);
277 [Description("Test: Handle event. Try to sroll to edge to trigger the event.")]
278 [Property("SPEC", "Tizen.NUI.BaseComponents.WebView.NewWindowCreated E")]
279 [Property("SPEC_URL", "-")]
280 [Property("CRITERIA", "EVL")]
281 [Property("AUTHOR", "guowei.wang@samsung.com")]
282 [Precondition(1, "In case of Emulator, only use PC keyboard or remote controller of emulator itself.")]
283 [Precondition(2, "If test on TV, prepare mouse and connect to TV.")]
284 [Step(1, "Click to runt TC.")]
285 [Step(2, "Click button to open new window.")]
286 [Step(3, "If there is no exception, test will be automatically passed.")]
287 [Postcondition(1, "NA")]
288 public async Task NewWindowCreated_CB()
290 if (ManualTest.IsWearable())
292 _wearTestPage.ExecuteTC(_label);
293 await ManualTest.WaitForConfirm();
294 _wearTestPage.ClearTestCase(_label);
298 _window.GetDefaultLayer().Add(_webView);
299 FocusManager.Instance.SetCurrentFocusView(_webView);
301 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
302 EventHandler<WebViewPageLoadEventArgs> onLoadFinished = (s, e) =>
304 Log.Info(tag, "onLoadFinished is called.");
305 tcs.TrySetResult(true);
307 Log.Info(tag, "onLoadFinished is called.");
308 _webView.PageLoadFinished += onLoadFinished;
310 EventHandlerWithReturnType<object, EventArgs, BaseComponents.WebView> onNewWindowCreated = (s, e) =>
312 Log.Info(tag, "TUnit WebView.NewWindowCreated!!!!!!!!!!!!!!!!!!!!!");
313 ManualTest.Confirm();
316 _webView.NewWindowCreated += onNewWindowCreated;
317 Log.Info(tag, "onLoadFinished is called.");
318 _webView.LoadUrl(urlForOpenWindow);
320 Log.Info(tag, "onLoadFinished is called.");
321 var result = await tcs.Task;
322 Assert.IsTrue(result, "PageLoadFinished event should be invoked");
324 Log.Info(tag, "onLoadFinished is called.");
326 // Waits for user confirmation.
327 await ManualTest.WaitForConfirm();
328 _webView.PageLoadFinished -= onLoadFinished;
329 _webView.NewWindowCreated -= onNewWindowCreated;
330 _window.GetDefaultLayer().Remove(_webView);
334 //TODO... FormRepostPolicyDecided event is very hard to be triggered. And this event is used rarely.
337 //[Description("Test: Handle event. Try to sroll to edge to trigger the event.")]
338 //[Property("SPEC", "Tizen.NUI.BaseComponents.WebView.FormRepostPolicyDecided E")]
339 //[Property("SPEC_URL", "-")]
340 //[Property("CRITERIA", "EVL")]
341 //[Property("AUTHOR", "guowei.wang@samsung.com")]
342 //[Precondition(1, "In case of Emulator, only use PC keyboard or remote controller of emulator itself.")]
343 //[Precondition(2, "If test on TV, prepare mouse and connect to TV.")]
344 //[Step(1, "Click to runt TC.")]
345 //[Step(2, "Click submit button.")]
346 //[Step(3, "Click submit button again to simulate form repost.")]
347 //[Step(4, "If there is no exception, test will be automatically passed.")]
348 //[Postcondition(1, "NA")]
349 //public async Task FormRepostPolicyDecided_CB()
351 // if (ManualTest.IsWearable())
353 // _wearTestPage.ExecuteTC(_label);
354 // await ManualTest.WaitForConfirm();
355 // _wearTestPage.ClearTestCase(_label);
359 // _window.GetDefaultLayer().Add(_webView);
360 // FocusManager.Instance.SetCurrentFocusView(_webView);
362 // TaskCompletionSource<bool> tcs1 = new TaskCompletionSource<bool>(false);
363 // EventHandler<WebViewPageLoadEventArgs> onLoadFinished = async (s, e) =>
365 // if (_webView.Url.Contains("index.html"))
367 // tcs1.TrySetResult(true);
370 // Log.Info(tag, "onLoadFinished is called.");
371 // _webView.PageLoadFinished += onLoadFinished;
373 // EventHandler<WebViewFormRepostPolicyDecidedEventArgs> onFormRepostPolicyDecided = (s, e) =>
375 // Log.Info(tag, "TUnit WebView.FormRepostPolicyDecided!!!!!!!!!!!!!!!!!!!!!");
376 // ManualTest.Confirm();
378 // _webView.FormRepostPolicyDecided += onFormRepostPolicyDecided;
379 // EventHandlerWithReturnType<object, View.TouchEventArgs, bool> onTouched = (s, e) =>
381 // // Load index.html.
382 // Log.Info(tag, "TUnit WebView.TouchEvent !!!!!!!!!!!!!!!!!!!!!");
383 // _webView.LoadUrl(url);
386 // _webView.TouchEvent += onTouched;
387 // Log.Info(tag, "onLoadFinished is called.");
388 // _webView.LoadUrl(urlForFormSubmit);
390 // Log.Info(tag, "onLoadFinished is called.");
391 // var result = await tcs1.Task;
392 // Assert.IsTrue(result, "PageLoadFinished event should be invoked");
394 // if (_webView.CanGoBack())
396 // Log.Info(tag, $"GoBack is called. url: {_webView.Url}");
397 // _webView.GoBack();
400 // _webView.PageLoadFinished -= onLoadFinished;
402 // // Waits for user confirmation.
403 // await ManualTest.WaitForConfirm();
404 // _webView.FormRepostPolicyDecided -= onFormRepostPolicyDecided;
405 // _window.GetDefaultLayer().Remove(_webView);