From: yh106.jung Date: Fri, 7 Dec 2018 01:36:23 +0000 (+0900) Subject: [WebView][Non-ACR] Adds auto TCT for Tizen.WebView X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F65%2F194665%2F6;p=test%2Ftct%2Fcsharp%2Fapi.git [WebView][Non-ACR] Adds auto TCT for Tizen.WebView Auto TCT for Tizen.WebView was applied on Tizen 4.0[1], but it was removed on Tizen 5.0. This patch adds again auto TCT for Tizen.WebView. Tizen.WebView has been already added as API level 4, so we don't need to ACR for this patch. [1] http://165.213.149.170/gerrit/#/c/162552/ Change-Id: I487cce3293d1c7cf0da1a0f51ea5880166dbb025 Signed-off-by: yh106.jung --- diff --git a/tct-suite-vs/Tizen.WebView.Tests/Program.cs b/tct-suite-vs/Tizen.WebView.Tests/Program.cs new file mode 100755 index 000000000..38f49125a --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/Program.cs @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using System; +using NUnitLite.TUnit; +using AutoTemplate; +using Tizen.WebView; + +namespace XamarinForTizen.Tizen +{ + + class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication + { + private static App _app; + protected override void OnCreate() + { + base.OnCreate(); + + Console.WriteLine("TCT : OnCreate()"); + _app = new App(); + LoadApplication(_app); + + TRunner t = new TRunner(); + t.LoadTestsuite(); + t.Execute(); + } + + public static App getApp() + { + return _app; + } + static void Main(string[] args) + { + Console.WriteLine("TCT : Main()"); + var app = new Program(); + global::Xamarin.Forms.Platform.Tizen.Forms.Init(app); + Chromium.Initialize(); + app.Run(args); + Chromium.Shutdown(); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/Tizen.WebView.Tests.csproj b/tct-suite-vs/Tizen.WebView.Tests/Tizen.WebView.Tests.csproj new file mode 100755 index 000000000..1c4ad04fc --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/Tizen.WebView.Tests.csproj @@ -0,0 +1,39 @@ + + + + + Exe + tizen60 + + + + + true + + + + portable + + + None + + + + + + + + + + + Runtime + + + + + + + + + + diff --git a/tct-suite-vs/Tizen.WebView.Tests/Tizen.WebView.Tests.sln b/tct-suite-vs/Tizen.WebView.Tests/Tizen.WebView.Tests.sln new file mode 100755 index 000000000..c687114fb --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/Tizen.WebView.Tests.sln @@ -0,0 +1,78 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.15 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.WebView.Tests", "Tizen.WebView.Tests.csproj", "{D92BEEAC-3B2A-45F8-8C53-53B92550404A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.framework", "..\nunit.framework\nunit.framework.csproj", "{B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunitlite", "..\nunitlite\nunitlite.csproj", "{FDB8025A-C029-461F-895E-287B4C65939B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoTemplate", "..\Template\AutoTemplate\AutoTemplate.csproj", "{B11ABB0C-C3C1-4B5C-8251-A15628A775F3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|x64.ActiveCfg = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|x64.Build.0 = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|x86.ActiveCfg = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|x86.Build.0 = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|Any CPU.Build.0 = Release|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|x64.ActiveCfg = Release|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|x64.Build.0 = Release|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|x86.ActiveCfg = Release|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|x86.Build.0 = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|x64.ActiveCfg = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|x64.Build.0 = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|x86.ActiveCfg = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|x86.Build.0 = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|Any CPU.Build.0 = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|x64.ActiveCfg = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|x64.Build.0 = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|x86.ActiveCfg = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|x86.Build.0 = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|x64.ActiveCfg = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|x64.Build.0 = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|x86.ActiveCfg = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|x86.Build.0 = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|Any CPU.Build.0 = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|x64.ActiveCfg = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|x64.Build.0 = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|x86.ActiveCfg = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|x86.Build.0 = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|x64.ActiveCfg = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|x64.Build.0 = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|x86.ActiveCfg = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|x86.Build.0 = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|Any CPU.Build.0 = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|x64.ActiveCfg = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|x64.Build.0 = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|x86.ActiveCfg = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ED382B91-9930-40B6-B3D7-362304C78680} + EndGlobalSection +EndGlobal diff --git a/tct-suite-vs/Tizen.WebView.Tests/res/add_js_interface_sample.html b/tct-suite-vs/Tizen.WebView.Tests/res/add_js_interface_sample.html new file mode 100755 index 000000000..e175d42c7 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/res/add_js_interface_sample.html @@ -0,0 +1,44 @@ + + + + Testing Sample Page for Add JavaScript Interface + + + +

Sample HTML for Add JavaScript Interface

+
+

+ + diff --git a/tct-suite-vs/Tizen.WebView.Tests/res/sample.html b/tct-suite-vs/Tizen.WebView.Tests/res/sample.html new file mode 100755 index 000000000..abdaacd5c --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/res/sample.html @@ -0,0 +1,13 @@ + + + + Testing Sample Page + + +

Sample HTML

+

This is sample html page to be used in test suite when loading of a page is required.

+

test content

+ + diff --git a/tct-suite-vs/Tizen.WebView.Tests/res/sample_1.html b/tct-suite-vs/Tizen.WebView.Tests/res/sample_1.html new file mode 100755 index 000000000..d407ab12f --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/res/sample_1.html @@ -0,0 +1,11 @@ + + + + Testing Sample Page 1 + + +

Sample HTML 1

+ + diff --git a/tct-suite-vs/Tizen.WebView.Tests/res/sample_2.html b/tct-suite-vs/Tizen.WebView.Tests/res/sample_2.html new file mode 100755 index 000000000..c11b4ba2a --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/res/sample_2.html @@ -0,0 +1,11 @@ + + + + Testing Sample Page 2 + + +

Sample HTML 2

+ + diff --git a/tct-suite-vs/Tizen.WebView.Tests/shared/res/Tizen.WebView.Tests.png b/tct-suite-vs/Tizen.WebView.Tests/shared/res/Tizen.WebView.Tests.png new file mode 100755 index 000000000..9765b1bda Binary files /dev/null and b/tct-suite-vs/Tizen.WebView.Tests/shared/res/Tizen.WebView.Tests.png differ diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSChromium.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSChromium.cs new file mode 100755 index 000000000..e1229a07f --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSChromium.cs @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; + +namespace Tizen.WebView.Tests +{ + + [TestFixture] + [Description("Tizen.WebView.Chromium Tests")] + public class ChromiumTests { + private static int _init = 0; + private static int _shutdown = 0; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.Chromium Tests"); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.WebView.Chromium Tests"); + } + + [Test] + [Category("P1")] + [Description("Initializes Chromium's instance")] + [Property("SPEC", "Tizen.WebView.Chromium.Initialize M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void Initialize_RETURN_VALUE() + { + _init = Chromium.Initialize(); + Assert.IsTrue(_init > 0, "Initialize method failed, reference count: " + _init); + + _shutdown = Chromium.Shutdown(); + Assert.AreEqual(_shutdown, _init - 1, "Shutdown method failed, Initialize: " + _init + " Shutdown: " + _shutdown); + } + + [Test] + [Category("P1")] + [Description("Shutdown Chromium's instance")] + [Property("SPEC", "Tizen.WebView.Chromium.Shutdown M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void Shutdown_RETURN_VALUE() + { + /* TEST CODE */ + _init = Chromium.Initialize(); + Assert.IsTrue(_init > 0, "Initialize method failed, reference count: " + _init); + + _shutdown = Chromium.Shutdown(); + Assert.AreEqual(_shutdown, _init - 1, "Shutdown method failed, Initialize: " + _init + " Shutdown: " + _shutdown); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSContext.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSContext.cs new file mode 100755 index 000000000..ad106bb6e --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSContext.cs @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; + +namespace Tizen.WebView.Tests +{ + + [TestFixture] + [Description("Tizen.WebView.Context Tests")] + public class ContextTests { + private WebView _webView; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.Context Tests"); + _webView = new WebView(WebViewCommon.GetMainWindow()); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.WebView.Context Tests"); + _webView = null; + } + + [Test] + [Category("P1")] + [Description("Checks default cache model for the context")] + [Property("SPEC", "Tizen.WebView.Context.CacheModel A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PDV")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void CacheModel_CHECK_DEFAULT() + { + /* TEST CODE */ + var context = _webView.GetContext(); + Assert.IsInstanceOf(context, "GetContext method failed"); + + Assert.IsInstanceOf(context.CacheModel); + Assert.AreEqual((int)CacheModel.DocumentViewer, (int)context.CacheModel, "Default cache model should be DocumentViewer"); + } + + [Test] + [Category("P1")] + [Description("Gets and sets cache model for the context")] + [Property("SPEC", "Tizen.WebView.Context.CacheModel A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW, PRE")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void CacheModel_GET_SET_ALL() + { + /* TEST CODE */ + var context = _webView.GetContext(); + Assert.IsInstanceOf(context, "GetContext method failed"); + + context.CacheModel = CacheModel.DocumentViewer; + Assert.IsInstanceOf(context.CacheModel); + Assert.AreEqual((int)CacheModel.DocumentViewer, (int)context.CacheModel, "CacheModel should be DocumentViewer"); + + context.CacheModel = CacheModel.DocumentBrowser; + Assert.IsInstanceOf(context.CacheModel); + Assert.AreEqual((int)CacheModel.DocumentBrowser, (int)context.CacheModel, "CacheModel should be DocumentBrowser"); + + context.CacheModel = CacheModel.PrimaryWebBrowser; + Assert.IsInstanceOf(context.CacheModel); + Assert.AreEqual((int)CacheModel.PrimaryWebBrowser, (int)context.CacheModel, "CacheModel should be PrimaryWebBrowser"); + } + + [Test] + [Category("P1")] + [Description("Gets cookie manager instance for the context")] + [Property("SPEC", "Tizen.WebView.Context.GetCookieManager M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void GetCookieManager_RETURN_VALUE() + { + /* TEST CODE */ + var context = _webView.GetContext(); + Assert.IsInstanceOf(context, "GetContext method failed"); + + var cookieManager = context.GetCookieManager(); + Assert.IsInstanceOf(cookieManager, "GetCookieManager method failed"); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSCookieManager.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSCookieManager.cs new file mode 100755 index 000000000..1a4e8c5e7 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSCookieManager.cs @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using System.Threading.Tasks; + +namespace Tizen.WebView.Tests +{ + [TestFixture] + [Description("Tizen.WebView.CookieManager Tests")] + public class CookieManagerTests + { + private WebView _webView; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.CookieManager Tests"); + _webView = new WebView(WebViewCommon.GetMainWindow()); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.WebView.CookieManager Tests"); + _webView = null; + } + + [Test] + [Category("P1")] + [Description("Sets the cookie acceptance policy")] + [Property("SPEC", "Tizen.WebView.CookieManager.SetCookieAcceptPolicy M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MAE")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void SetCookieAcceptPolicy_ENUM_ALL() + { + /* TEST CODE */ + var cookieManager = _webView.GetContext().GetCookieManager(); + Assert.IsNotNull(cookieManager, "GetCookieManager returns NULL"); + Assert.IsInstanceOf(cookieManager, "GetCookieManager method failed"); + + // TODO: GetCookieAcceptPolicyAsync is not implemented yet. + // Need verification after we've implemented it. + try + { + cookieManager.SetCookieAcceptPolicy(CookieAcceptPolicy.Always); + + cookieManager.SetCookieAcceptPolicy(CookieAcceptPolicy.Never); + + cookieManager.SetCookieAcceptPolicy(CookieAcceptPolicy.NoThirdParty); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + + [Test] + [Category("P1")] + [Description("Deletes all the cookies of a manager")] + [Property("SPEC", "Tizen.WebView.CookieManager.ClearCookies M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task ClearCookies_CHANGE_STATUS() + { + /* PRECONDITION */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.TestUrl); + await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(tcs.Task.Result, "LoadUrl method failed"); + + /* TEST CODE */ + var cookieManager = _webView.GetContext().GetCookieManager(); + Assert.IsNotNull(cookieManager, "GetCookieManager returns NULL"); + Assert.IsInstanceOf(cookieManager, "GetCookieManager method failed"); + + try + { + cookieManager.ClearCookies(); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + + [Test] + [Category("P1")] + [Description("Sets the storage where non-session cookies are stored persistently")] + [Property("SPEC", "Tizen.WebView.CookieManager.SetPersistentStorage M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MAE")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void SetPersistentStorage_ENUM_ALL() + { + /* TEST CODE */ + var cookieManager = _webView.GetContext().GetCookieManager(); + Assert.IsInstanceOf(cookieManager, "GetCookieManager method failed"); + string path = Applications.Application.Current.DirectoryInfo.Data + "mycookiestoragedir"; + + try + { + cookieManager.SetPersistentStorage(path, CookiePersistentStorage.Text); + + cookieManager.SetPersistentStorage(path, CookiePersistentStorage.SqlLite); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSJavaScriptMessage.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSJavaScriptMessage.cs new file mode 100755 index 000000000..6fb14cc92 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSJavaScriptMessage.cs @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using System.Threading.Tasks; + +namespace Tizen.WebView.Tests +{ + + [TestFixture] + [Description("Tizen.WebView.JavaScriptMessage Tests")] + public class JavaScriptMessageTests + { + private WebView _webView; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.JavaScriptMessage Tests"); + _webView = new WebView(WebViewCommon.GetMainWindow()); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.WebView.JavaScriptMessage Tests"); + _webView = null; + } + + [Test] + [Category("P1")] + [Description("Gets the name of JavaScript message")] + [Property("SPEC", "Tizen.WebView.JavaScriptMessage.Name A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Name_READ_ONLY() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + TaskCompletionSource tcsForCallback = new TaskCompletionSource(false); + JavaScriptMessageHandler handler = (message) => + { + if (message.Name is string && message.Name.Equals("MyJavaScriptInterfaceForName")) + { + tcsForCallback.TrySetResult(true); + } + tcsForCallback.TrySetResult(false); + }; + _webView.AddJavaScriptMessageHandler("MyJavaScriptInterfaceForName", handler); + + _webView.LoadUrl(WebViewCommon.AddJavaScriptInterfaceSampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + _webView.Eval("callForName();"); + result = await tcsForCallback.Task; + + Assert.IsTrue(result, "JavaScript handler should be invoked with valid name"); + } + + [Test] + [Category("P1")] + [Description("Gets the body of JavaScript message as integer type")] + [Property("SPEC", "Tizen.WebView.JavaScriptMessage.GetBodyAsInteger M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetBodyAsInteger_RETURN_VALUE() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + TaskCompletionSource tcsForCallback = new TaskCompletionSource(false); + JavaScriptMessageHandler handler = (message) => + { + if (message.Name.Equals("MyJavaScriptInterfaceWithInteger")) + { + var body = message.GetBodyAsInteger(); + if (body.GetType() == typeof(int) && body == 10) + { + tcsForCallback.TrySetResult(true); + } + } + tcsForCallback.TrySetResult(false); + }; + _webView.AddJavaScriptMessageHandler("MyJavaScriptInterfaceWithInteger", handler); + + _webView.LoadUrl(WebViewCommon.AddJavaScriptInterfaceSampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + _webView.Eval("callWithInteger();"); + result = await tcsForCallback.Task; + + Assert.IsTrue(result, "GetBodyAsInteger should return valid body value"); + } + + [Test] + [Category("P1")] + [Description("Gets the body of JavaScript message as double type")] + [Property("SPEC", "Tizen.WebView.JavaScriptMessage.GetBodyAsDouble M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetBodyAsDouble_RETURN_VALUE() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + TaskCompletionSource tcsForCallback = new TaskCompletionSource(false); + JavaScriptMessageHandler handler = (message) => + { + if (message.Name.Equals("MyJavaScriptInterfaceWithDouble")) + { + var body = message.GetBodyAsDouble(); + if (body.GetType() == typeof(double) && body == 0.1) + { + tcsForCallback.TrySetResult(true); + } + } + tcsForCallback.TrySetResult(false); + }; + _webView.AddJavaScriptMessageHandler("MyJavaScriptInterfaceWithDouble", handler); + + _webView.LoadUrl(WebViewCommon.AddJavaScriptInterfaceSampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + _webView.Eval("callWithDouble();"); + result = await tcsForCallback.Task; + + Assert.IsTrue(result, "GetBodyAsDouble should return valid body value"); + } + + [Test] + [Category("P1")] + [Description("Gets the body of JavaScript message as boolean type")] + [Property("SPEC", "Tizen.WebView.JavaScriptMessage.GetBodyAsBoolean M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetBodyAsBoolean_RETURN_VALUE() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + TaskCompletionSource tcsForCallback = new TaskCompletionSource(false); + JavaScriptMessageHandler handler = (message) => + { + if (message.Name.Equals("MyJavaScriptInterfaceWithBoolean")) + { + var body = message.GetBodyAsBoolean(); + if (body.GetType() == typeof(bool) && body == true) + { + tcsForCallback.TrySetResult(true); + } + } + tcsForCallback.TrySetResult(false); + }; + _webView.AddJavaScriptMessageHandler("MyJavaScriptInterfaceWithBoolean", handler); + + _webView.LoadUrl(WebViewCommon.AddJavaScriptInterfaceSampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + _webView.Eval("callWithBoolean();"); + result = await tcsForCallback.Task; + + Assert.IsTrue(result, "GetBodyAsBoolean should return valid body value"); + } + + [Test] + [Category("P1")] + [Description("Gets the body of JavaScript message as string type")] + [Property("SPEC", "Tizen.WebView.JavaScriptMessage.GetBodyAsString M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetBodyAsString_RETURN_VALUE() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + TaskCompletionSource tcsForCallback = new TaskCompletionSource(false); + JavaScriptMessageHandler handler = (message) => + { + if (message.Name.Equals("MyJavaScriptInterfaceWithString")) + { + var body = message.GetBodyAsString(); + if (body.GetType() == typeof(string) && body.Equals("Test message")) + { + tcsForCallback.TrySetResult(true); + } + } + tcsForCallback.TrySetResult(false); + }; + _webView.AddJavaScriptMessageHandler("MyJavaScriptInterfaceWithString", handler); + + _webView.LoadUrl(WebViewCommon.AddJavaScriptInterfaceSampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + _webView.Eval("callWithString();"); + result = await tcsForCallback.Task; + + Assert.IsTrue(result, "GetBodyAsString should return valid body value"); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSettings.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSettings.cs new file mode 100755 index 000000000..4f5c85c01 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSettings.cs @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; + +namespace Tizen.WebView.Tests +{ + + [TestFixture] + [Description("Tizen.WebView.Settings Tests")] + public class SettingsTests + { + private WebView _webView; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.Settings Tests"); + _webView = new WebView(WebViewCommon.GetMainWindow()); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.WebView.Settings Tests"); + _webView = null; + } + + [Test] + [Category("P1")] + [Description("Gets and sets whether JavaScript can be executable")] + [Property("SPEC", "Tizen.WebView.Settings.JavaScriptEnabled A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void JavaScriptEnabled_READ_WRITE() + { + /* TEST CODE */ + var settings = _webView.GetSettings(); + Assert.IsInstanceOf(settings, "GetSettings method failed"); + + + settings.JavaScriptEnabled = false; + Assert.IsFalse(settings.JavaScriptEnabled, "Fail to get/set JavaScriptEnabled as false"); + + settings.JavaScriptEnabled = true; + Assert.IsTrue(settings.JavaScriptEnabled, "Fail to get/set JavaScriptEnabled as true"); + } + + [Test] + [Category("P1")] + [Description("Gets and sets whether images can be loaded automatically")] + [Property("SPEC", "Tizen.WebView.Settings.LoadImageAutomatically A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void LoadImageAutomatically_READ_WRITE() + { + /* TEST CODE */ + var settings = _webView.GetSettings(); + Assert.IsInstanceOf(settings, "GetSettings method failed"); + + settings.LoadImageAutomatically = true; + Assert.IsTrue(settings.LoadImageAutomatically, "Fail to get/set LoadImageAutomatically"); + + settings.LoadImageAutomatically = false; + Assert.IsFalse(settings.LoadImageAutomatically, "Fail to get/set LoadImageAutomatically"); + } + + [Test] + [Category("P1")] + [Description("Gets and sets default text encoding name")] + [Property("SPEC", "Tizen.WebView.Settings.DefaultTextEncodingName A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void DefaultTextEncodingName_READ_WRITE() + { + /* TEST CODE */ + var settings = _webView.GetSettings(); + Assert.IsInstanceOf(settings, "GetSettings method failed"); + + const string encodingName = "utf-8"; + settings.DefaultTextEncodingName = encodingName; + Assert.True(settings.DefaultTextEncodingName.Length > 0, "Fail to get/set DefaultTextEncodingName"); + Assert.AreEqual(encodingName, settings.DefaultTextEncodingName, "Fail to get/set DefaultTextEncodingName"); + } + + [Test] + [Category("P1")] + [Description("Gets and sets default font size of a pixel")] + [Property("SPEC", "Tizen.WebView.Settings.DefaultFontSize A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void DefaultFontSize_READ_WRITE() + { + /* TEST CODE */ + var settings = _webView.GetSettings(); + Assert.IsInstanceOf(settings, "GetSettings method failed"); + + const int fontSize = 10; + settings.DefaultFontSize = fontSize; + Assert.AreEqual(fontSize, settings.DefaultFontSize, "Fail to get/set DefaultFontSize"); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSmartCallbackArgs.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSmartCallbackArgs.cs new file mode 100755 index 000000000..6438ee179 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSmartCallbackArgs.cs @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using System.Threading.Tasks; + +namespace Tizen.WebView.Tests +{ + + [TestFixture] + [Description("Tizen.WebView.SmartCallbackArgs Tests")] + public class SmartCallbackArgsTests + { + private WebView _webView; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.SmartCallbackArgs Tests"); + _webView = new WebView(WebViewCommon.GetMainWindow()); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.WebView.SmartCallbackArgs Tests"); + _webView = null; + } + + [Test] + [Category("P1")] + [Description("Gets the parameter of callback as boolean type")] + [Property("SPEC", "Tizen.WebView.SmartCallbackArgs.GetAsBoolean M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetAsBoolean_RETURN_VALUE() + { + /* TEST CODE */ + bool arg = false; + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onTitleChanged = (s, e) => { + arg = e.GetAsBoolean(); + }; + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.TitleChanged += onTitleChanged; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.TitleChanged -= onTitleChanged; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + Assert.IsTrue(arg, "GetAsBoolean should return valid value"); + } + + [Test] + [Category("P1")] + [Description("Gets the parameter of callback as double type")] + [Property("SPEC", "Tizen.WebView.SmartCallbackArgs.GetAsDouble M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetAsDouble_RETURN_VALUE() + { + /* TEST CODE */ + double arg = 0d; + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onTitleChanged = (s, e) => { + arg = e.GetAsDouble(); + }; + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.TitleChanged += onTitleChanged; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.TitleChanged -= onTitleChanged; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + Assert.AreNotEqual(0d, arg, "GetAsDouble should return valid value"); + } + + [Test] + [Category("P1")] + [Description("Gets the parameter of callback as integer type")] + [Property("SPEC", "Tizen.WebView.SmartCallbackArgs.GetAsInteger M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetAsInteger_RETURN_VALUE() + { + /* TEST CODE */ + int arg = 0; + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onTitleChanged = (s, e) => { + arg = e.GetAsInteger(); + }; + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.TitleChanged += onTitleChanged; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.TitleChanged -= onTitleChanged; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + Assert.AreNotEqual(0, arg, "GetAsInteger should return valid value"); + } + + [Test] + [Category("P1")] + [Description("Gets the parameter of callback as string type")] + [Property("SPEC", "Tizen.WebView.SmartCallbackArgs.GetAsString M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GetAsString_RETURN_VALUE() + { + /* TEST CODE */ + string arg = string.Empty; + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onTitleChanged = (s, e) => { + arg = e.GetAsString(); + }; + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.TitleChanged += onTitleChanged; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.TitleChanged -= onTitleChanged; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + Assert.AreEqual(WebViewCommon.SampleHtmlTitle, arg, "GetAsString should return valid value"); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSmartCallbackLoadErrorArgs.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSmartCallbackLoadErrorArgs.cs new file mode 100755 index 000000000..28d4da55a --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSSmartCallbackLoadErrorArgs.cs @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using System.Threading.Tasks; + +namespace Tizen.WebView.Tests +{ + + [TestFixture] + [Description("Tizen.WebView.SmartCallbackLoadErrorArgs Tests")] + public class SmartCallbackLoadErrorArgsTests + { + private WebView _webView; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.SmartCallbackLoadErrorArgs Tests"); + _webView = new WebView(WebViewCommon.GetMainWindow()); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.WebView.SmartCallbackLoadErrorArgs Tests"); + _webView = null; + } + + [Test] + [Category("P1")] + [Description("Gets the URL of load error callback")] + [Property("SPEC", "Tizen.WebView.SmartCallbackLoadErrorArgs.Url A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Url_READ_ONLY() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(false); }; + EventHandler onLoadError = (s, e) => + { + var url = e.Url; + if (url is string && url.Equals(WebViewCommon.TestUrlForError)) + { + tcs.TrySetResult(true); + } + tcs.TrySetResult(false); + }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.TestUrlForError); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "Url should be valid value"); + } + + [Test] + [Category("P1")] + [Description("Gets the error code of load error callback")] + [Property("SPEC", "Tizen.WebView.SmartCallbackLoadErrorArgs.Code A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Code_READ_ONLY() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(false); }; + EventHandler onLoadError = (s, e) => + { + var code = e.Code; + if (code.GetType() == typeof(LoadErrorCode) && code.Equals(LoadErrorCode.CantLookupHost)) + { + tcs.TrySetResult(true); + } + tcs.TrySetResult(false); + }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.TestUrlForError); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "Code should be valid value"); + } + + [Test] + [Category("P1")] + [Description("Gets the description of load error callback")] + [Property("SPEC", "Tizen.WebView.SmartCallbackLoadErrorArgs.Description A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Description_READ_ONLY() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(false); }; + EventHandler onLoadError = (s, e) => + { + var description = e.Description; + if (description is string) + { + tcs.TrySetResult(true); + } + tcs.TrySetResult(false); + }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.TestUrlForError); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "Description should be valid value"); + } + + [Test] + [Category("P1")] + [Description("Gets the cancellation or not of load error callback")] + [Property("SPEC", "Tizen.WebView.SmartCallbackLoadErrorArgs.Cancellation A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Cancellation_READ_ONLY() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(false); }; + EventHandler onLoadError = (s, e) => + { + var cancellation = e.Cancellation; + if (cancellation.GetType() == typeof(bool)) + { + tcs.TrySetResult(true); + } + tcs.TrySetResult(false); + }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.TestUrlForError); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "Cancellation should be valid value"); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs new file mode 100755 index 000000000..6f5a948a9 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs @@ -0,0 +1,870 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using System.Threading.Tasks; + +namespace Tizen.WebView.Tests +{ + [TestFixture] + [Description("Tizen.WebView.WebView Tests")] + public class WebViewTests + { + private WebView _webView; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.WebView.WebView Tests"); + _webView = new WebView(WebViewCommon.GetMainWindow()); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions forTizen.WebView.WebView Tests"); + _webView = null; + } + + [Test] + [Category("P1")] + [Description("Event that occurs when load started")] + [Property("SPEC", "Tizen.WebView.WebView.LoadStarted E")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "EVL")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task LoadStarted_CHECK_EVENT() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadStarted = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(false); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadStarted += onLoadStarted; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadStarted -= onLoadStarted; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadStarted event should be invoked"); + } + + [Test] + [Category("P1")] + [Description("Event that occurs when load finished")] + [Property("SPEC", "Tizen.WebView.WebView.LoadFinished E")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "EVL")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task LoadFinished_CHECK_EVENT() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadFinished event should be invoked"); + } + + [Test] + [Category("P1")] + [Description("Event that occurs when load error")] + [Property("SPEC", "Tizen.WebView.WebView.LoadError E")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "EVL")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task LoadError_CHECK_EVENT() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(false); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(true); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.TestUrlForError); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadError event should be invoked"); + } + + [Test] + [Category("P1")] + [Description("Event that occurs when title of main frame was changed")] + [Property("SPEC", "Tizen.WebView.WebView.TitleChanged E")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "EVL")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task TitleChanged_CHECK_EVENT() + { + /* TEST CODE */ + string title = string.Empty; + EventHandler onTitleChanged = (s, e) => { + title = e.GetAsString(); + }; + + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.TitleChanged += onTitleChanged; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.TitleChanged -= onTitleChanged; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + Assert.AreEqual(_webView.Title, title, "Received title should be same with WebView.Title"); + } + + [Test] + [Category("P1")] + [Description("Event that occurs when URL of main frame was changed")] + [Property("SPEC", "Tizen.WebView.WebView.UrlChanged E")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "EVL")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task UrlChanged_CHECK_EVENT() + { + /* TEST CODE */ + string url = string.Empty; + EventHandler onUrlChanged = (s, e) => { + url = e.GetAsString(); + }; + + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.UrlChanged += onUrlChanged; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.UrlChanged -= onUrlChanged; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + Assert.AreEqual(_webView.Url, url, "Received URL should be same with WebView.Url"); + } + + [Test] + [Category("P1")] + [Description("Gets current URL of the main frame")] + [Property("SPEC", "Tizen.WebView.WebView.Url A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Url_READ_ONLY() + { + /* PRECONDITION */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + /* TEST CODE */ + var url = _webView.Url; + Assert.IsInstanceOf(url, "Get Url should return object string"); + Assert.AreEqual(WebViewCommon.SampleHtml, url, "Fail to get Url should return valid url"); + } + + [Test] + [Category("P1")] + [Description("Gets current title of the main frame")] + [Property("SPEC", "Tizen.WebView.WebView.Title A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Title_READ_ONLY() + { + /* PRECONDITION */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + /* TEST CODE */ + var title = _webView.Title; + Assert.IsInstanceOf(title, "Get Title should return object string"); + Assert.AreEqual(WebViewCommon.SampleHtmlTitle, title, "Get Title should return valid title"); + } + + [Test] + [Category("P1")] + [Description("Gets and sets user agent string of this view")] + [Property("SPEC", "Tizen.WebView.WebView.UserAgent A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRW")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void UserAgent_READ_WRITE() + { + /* TEST CODE */ + _webView.UserAgent = WebViewCommon.TestUserAgent; + var userAgent = _webView.UserAgent; + Assert.IsInstanceOf(userAgent, "Get UserAgent should return object string"); + Assert.AreEqual(WebViewCommon.TestUserAgent, userAgent, "Get UserAgent should return valid user agent"); + } + + [Test] + [Category("P1")] + [Description("Checks whether a view has the focus")] + [Property("SPEC", "Tizen.WebView.WebView.HasFocus A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task HasFocus_READ_ONLY() + { + /* PRECONDITION */ + + + /* TEST CODE */ + var hasFocus = _webView.HasFocus; + Assert.IsInstanceOf(hasFocus, "Get HasFocus should return object bool"); + Assert.IsFalse(hasFocus, "HasFocus should be false before load content"); + + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => + { + _webView.SetFocus(true); + tcs.TrySetResult(true); + }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + hasFocus = _webView.HasFocus; + Assert.IsInstanceOf(hasFocus, "Get HasFocus should return object bool"); + Assert.IsTrue(hasFocus, "HasFocus should be true after load content"); + } + + [Test] + [Category("P1")] + [Description("Create a WebView object")] + [Property("SPEC", "Tizen.WebView.WebView.WebView C")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "CONSTR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void WebView_INIT_WITH_PARENT() + { + /* TEST CODE */ + var webView = new WebView(WebViewCommon.GetMainWindow()); + Assert.IsNotNull(webView, "WebView object is null after initialization"); + Assert.IsInstanceOf(webView, "Should return WebView instance"); + } + + [Test] + [Category("P1")] + [Description("Gets the Context object of this view")] + [Property("SPEC", "Tizen.WebView.WebView.GetContext M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void GetContext_RETURN_VALUE() + { + /* TEST CODE */ + var context = _webView.GetContext(); + Assert.IsInstanceOf(context, "GetContext method failed"); + } + + [Test] + [Category("P1")] + [Description("Gets the Settings object of this view")] + [Property("SPEC", "Tizen.WebView.WebView.GetSettings M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public void GetSettings_RETURN_VALUE() + { + /* TEST CODE */ + var settings = _webView.GetSettings(); + Assert.IsInstanceOf(settings, "GetSettings method failed"); + } + + [Test] + [Category("P1")] + [Description("Asks the object to load the given URL")] + [Property("SPEC", "Tizen.WebView.WebView.LoadUrl M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task LoadUrl_CHANGE_STATUS() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + } + + [Test] + [Category("P1")] + [Description("Loads the specified html string as the content of the view")] + [Property("SPEC", "Tizen.WebView.WebView.LoadHtml M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task LoadHtml_CHANGE_STATUS() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadHtml(WebViewCommon.TestHtml, WebViewCommon.TestUrl); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadHtml method failed"); + Assert.AreEqual(WebViewCommon.TestUrl, _webView.Title, "Title should be same with base URL"); + } + + [Test] + [Category("P1")] + [Description("Asks the main frame to stop loading")] + [Property("SPEC", "Tizen.WebView.WebView.StopLoading M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task StopLoading_CHANGE_STATUS() + { + /* TEST CODE */ + var isCancellation = false; + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadStarted = (s, e) => { _webView.StopLoading(); }; + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(false); }; + EventHandler onLoadError = (s, e) => { + isCancellation = e.Cancellation; + tcs.TrySetResult(true); + }; + + _webView.LoadStarted += onLoadStarted; + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.TestUrl); + var result = await tcs.Task; + + _webView.LoadStarted -= onLoadStarted; + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadError should be invoked"); + Assert.IsTrue(isCancellation, "Cancellation should be true"); + } + + [Test] + [Category("P1")] + [Description("Asks the main frame to reload the current document")] + [Property("SPEC", "Tizen.WebView.WebView.Reload M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Reload_CHANGE_STATUS() + { + /* PRECONDITION */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + /* TEST CODE */ + TaskCompletionSource tcsReload = new TaskCompletionSource(false); + EventHandler onLoadFinishedReload = (s, e) => { tcsReload.TrySetResult(true); }; + EventHandler onLoadErrorReload = (s, e) => { tcsReload.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedReload; + _webView.LoadError += onLoadErrorReload; + + _webView.Reload(); + result = await tcsReload.Task; + + _webView.LoadFinished -= onLoadFinishedReload; + _webView.LoadError -= onLoadErrorReload; + + Assert.IsTrue(result, "Reload method failed"); + } + + [Test] + [Category("P1")] + [Description("Asks the main frame to navigate back in history")] + [Property("SPEC", "Tizen.WebView.WebView.GoBack M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GoBack_CHANGE_STATUS() + { + /* PRECONDITION */ + TaskCompletionSource tcsFisrt = new TaskCompletionSource(false); + EventHandler onLoadFinishedFirst = (s, e) => { tcsFisrt.TrySetResult(true); }; + EventHandler onLoadErrorFirst = (s, e) => { tcsFisrt.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedFirst; + _webView.LoadError += onLoadErrorFirst; + + _webView.LoadUrl(WebViewCommon.SampleHtml1); + var result = await tcsFisrt.Task; + + _webView.LoadFinished -= onLoadFinishedFirst; + _webView.LoadError -= onLoadErrorFirst; + + Assert.IsTrue(result, "LoadUrl method failed for the first page"); + + TaskCompletionSource tcsSecond = new TaskCompletionSource(false); + EventHandler onLoadFinishedSecond = (s, e) => { tcsSecond.TrySetResult(true); }; + EventHandler onLoadErrorSecond = (s, e) => { tcsSecond.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedSecond; + _webView.LoadError += onLoadErrorSecond; + + _webView.LoadUrl(WebViewCommon.SampleHtml2); + result = await tcsSecond.Task; + + _webView.LoadFinished -= onLoadFinishedSecond; + _webView.LoadError -= onLoadErrorSecond; + + Assert.IsTrue(result, "LoadUrl method failed for the second page"); + + /* TEST CODE */ + TaskCompletionSource tcsGoBack = new TaskCompletionSource(false); + EventHandler onLoadFinishedGoBack = (s, e) => { tcsGoBack.TrySetResult(true); }; + EventHandler onLoadErrorGoBack = (s, e) => { tcsGoBack.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedGoBack; + _webView.LoadError += onLoadErrorGoBack; + + _webView.GoBack(); + result = await tcsGoBack.Task; + + _webView.LoadFinished -= onLoadFinishedGoBack; + _webView.LoadError -= onLoadErrorGoBack; + + Assert.IsTrue(result, "GoBack method failed"); + Assert.AreEqual(WebViewCommon.SampleHtml1, _webView.Url, "URL should be same with the first page"); + } + + [Test] + [Category("P1")] + [Description("Asks the main frame to navigate forward in history")] + [Property("SPEC", "Tizen.WebView.WebView.GoForward M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task GoForward_CHANGE_STATUS() + { + /* PRECONDITION */ + TaskCompletionSource tcsFisrt = new TaskCompletionSource(false); + EventHandler onLoadFinishedFirst = (s, e) => { tcsFisrt.TrySetResult(true); }; + EventHandler onLoadErrorFirst = (s, e) => { tcsFisrt.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedFirst; + _webView.LoadError += onLoadErrorFirst; + + _webView.LoadUrl(WebViewCommon.SampleHtml1); + var result = await tcsFisrt.Task; + + _webView.LoadFinished -= onLoadFinishedFirst; + _webView.LoadError -= onLoadErrorFirst; + + Assert.IsTrue(result, "LoadUrl method failed for the first page"); + + TaskCompletionSource tcsSecond = new TaskCompletionSource(false); + EventHandler onLoadFinishedSecond = (s, e) => { tcsSecond.TrySetResult(true); }; + EventHandler onLoadErrorSecond = (s, e) => { tcsSecond.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedSecond; + _webView.LoadError += onLoadErrorSecond; + + _webView.LoadUrl(WebViewCommon.SampleHtml2); + result = await tcsSecond.Task; + + _webView.LoadFinished -= onLoadFinishedSecond; + _webView.LoadError -= onLoadErrorSecond; + + Assert.IsTrue(result, "LoadUrl method failed for the second page"); + + TaskCompletionSource tcsGoBack = new TaskCompletionSource(false); + EventHandler onLoadFinishedGoBack = (s, e) => { tcsGoBack.TrySetResult(true); }; + EventHandler onLoadErrorGoBack = (s, e) => { tcsGoBack.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedGoBack; + _webView.LoadError += onLoadErrorGoBack; + + _webView.GoBack(); + result = await tcsGoBack.Task; + + _webView.LoadFinished -= onLoadFinishedGoBack; + _webView.LoadError -= onLoadErrorGoBack; + + Assert.IsTrue(result, "GoBack method failed"); + + /* TEST CODE */ + TaskCompletionSource tcsGoForward = new TaskCompletionSource(false); + EventHandler onLoadFinishedGoForward = (s, e) => { tcsGoForward.TrySetResult(true); }; + EventHandler onLoadErrorGoForward = (s, e) => { tcsGoForward.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedGoForward; + _webView.LoadError += onLoadErrorGoForward; + + _webView.GoForward(); + result = await tcsGoForward.Task; + + _webView.LoadFinished -= onLoadFinishedGoForward; + _webView.LoadError -= onLoadErrorGoForward; + + Assert.IsTrue(result, "GoForward method failed"); + Assert.AreEqual(WebViewCommon.SampleHtml2, _webView.Url, "URL should be same with the second page"); + } + + [Test] + [Category("P1")] + [Description("Checks whether it is possible to navigate backwards one item in history")] + [Property("SPEC", "Tizen.WebView.WebView.CanGoBack M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task CanGoBack_RETURN_VALUE() + { + /* PRECONDITION */ + TaskCompletionSource tcsFisrt = new TaskCompletionSource(false); + EventHandler onLoadFinishedFirst = (s, e) => { tcsFisrt.TrySetResult(true); }; + EventHandler onLoadErrorFirst = (s, e) => { tcsFisrt.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedFirst; + _webView.LoadError += onLoadErrorFirst; + + _webView.LoadUrl(WebViewCommon.SampleHtml1); + var result = await tcsFisrt.Task; + + _webView.LoadFinished -= onLoadFinishedFirst; + _webView.LoadError -= onLoadErrorFirst; + + Assert.IsTrue(result, "LoadUrl method failed for the first page"); + + TaskCompletionSource tcsSecond = new TaskCompletionSource(false); + EventHandler onLoadFinishedSecond = (s, e) => { tcsSecond.TrySetResult(true); }; + EventHandler onLoadErrorSecond = (s, e) => { tcsSecond.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedSecond; + _webView.LoadError += onLoadErrorSecond; + + _webView.LoadUrl(WebViewCommon.SampleHtml2); + result = await tcsSecond.Task; + + _webView.LoadFinished -= onLoadFinishedSecond; + _webView.LoadError -= onLoadErrorSecond; + + Assert.IsTrue(result, "LoadUrl method failed for the second page"); + + /* TEST CODE */ + var canGoBack = _webView.CanGoBack(); + Assert.IsInstanceOf(canGoBack, "CanGoBack should return object boolean"); + Assert.IsTrue(canGoBack, "CanGoBack should return valid value"); + } + + [Test] + [Category("P1")] + [Description("Checks whether it is possible to navigate forwards one item in history")] + [Property("SPEC", "Tizen.WebView.WebView.CanGoForward M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task CanGoForward_RETURN_VALUE() + { + /* PRECONDITION */ + TaskCompletionSource tcsFisrt = new TaskCompletionSource(false); + EventHandler onLoadFinishedFirst = (s, e) => { tcsFisrt.TrySetResult(true); }; + EventHandler onLoadErrorFirst = (s, e) => { tcsFisrt.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedFirst; + _webView.LoadError += onLoadErrorFirst; + + _webView.LoadUrl(WebViewCommon.SampleHtml1); + var result = await tcsFisrt.Task; + + _webView.LoadFinished -= onLoadFinishedFirst; + _webView.LoadError -= onLoadErrorFirst; + + Assert.IsTrue(result, "LoadUrl method failed for the first page"); + + TaskCompletionSource tcsSecond = new TaskCompletionSource(false); + EventHandler onLoadFinishedSecond = (s, e) => { tcsSecond.TrySetResult(true); }; + EventHandler onLoadErrorSecond = (s, e) => { tcsSecond.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedSecond; + _webView.LoadError += onLoadErrorSecond; + + _webView.LoadUrl(WebViewCommon.SampleHtml2); + result = await tcsSecond.Task; + + _webView.LoadFinished -= onLoadFinishedSecond; + _webView.LoadError -= onLoadErrorSecond; + + Assert.IsTrue(result, "LoadUrl method failed for the second page"); + + TaskCompletionSource tcsGoBack = new TaskCompletionSource(false); + EventHandler onLoadFinishedGoBack = (s, e) => { tcsGoBack.TrySetResult(true); }; + EventHandler onLoadErrorGoBack = (s, e) => { tcsGoBack.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinishedGoBack; + _webView.LoadError += onLoadErrorGoBack; + + _webView.GoBack(); + result = await tcsGoBack.Task; + + _webView.LoadFinished -= onLoadFinishedGoBack; + _webView.LoadError -= onLoadErrorGoBack; + + Assert.IsTrue(result, "GoBack method failed"); + + /* TEST CODE */ + var canGoForward = _webView.CanGoForward(); + Assert.IsInstanceOf(canGoForward, "CanGoForward should return object boolean"); + Assert.IsTrue(canGoForward, "CanGoForward should return valid value"); + } + + [Test] + [Category("P1")] + [Description("Injects the supplied javascript message handler into the view")] + [Property("SPEC", "Tizen.WebView.WebView.AddJavaScriptMessageHandler M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR, MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task AddJavaScriptMessageHandler_RETURN_VALUE_CHANGE_STATUS() + { + /* TEST CODE */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + TaskCompletionSource tcsForCallback = new TaskCompletionSource(false); + JavaScriptMessageHandler handler = (message) => + { + if (message.Name.Equals("MyJavaScriptInterfaceForCommon") && message.GetBodyAsString().Equals("Test message")) + { + tcsForCallback.TrySetResult(true); + } + tcsForCallback.TrySetResult(false); + }; + var ret = _webView.AddJavaScriptMessageHandler("MyJavaScriptInterfaceForCommon", handler); + Assert.IsInstanceOf(ret, "AddJavaScriptMessageHandler should return object bool"); + Assert.IsTrue(ret, "AddJavaScriptMessageHandler method failed"); + + _webView.LoadUrl(WebViewCommon.AddJavaScriptInterfaceSampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + _webView.Eval("callForCommon();"); + result = await tcsForCallback.Task; + + Assert.IsTrue(result, "JavaScript handler should be invoked with valid name"); + } + + [Test] + [Category("P1")] + [Description("Requests the execution of given name and result to the JavaScript runtime")] + [Property("SPEC", "Tizen.WebView.WebView.EvalWithResult M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task EvalWithResult_CHANGE_STATUS() + { + /* PRECONDITION */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.AddJavaScriptInterfaceSampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + /* TEST CODE */ + try + { + _webView.EvalWithResult("sendResult", "Result"); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + + [Test] + [Category("P1")] + [Description("Requests the execution of the given script")] + [Property("SPEC", "Tizen.WebView.WebView.Eval M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task Eval_CHANGE_STATUS() + { + /* PRECONDITION */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + /* TEST CODE */ + try + { + _webView.Eval(WebViewCommon.TestScript); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + + [Test] + [Category("P1")] + [Description("Requests to set or unset a view as the currently focused one")] + [Property("SPEC", "Tizen.WebView.WebView.SetFocus M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MCST")] + [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")] + public async Task SetFocus_CHANGE_STATUS() + { + /* PRECONDITION */ + TaskCompletionSource tcs = new TaskCompletionSource(false); + EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); }; + EventHandler onLoadError = (s, e) => { tcs.TrySetResult(false); }; + + _webView.LoadFinished += onLoadFinished; + _webView.LoadError += onLoadError; + + _webView.LoadUrl(WebViewCommon.SampleHtml); + var result = await tcs.Task; + + _webView.LoadFinished -= onLoadFinished; + _webView.LoadError -= onLoadError; + + Assert.IsTrue(result, "LoadUrl method failed"); + + /* TEST CODE */ + _webView.SetFocus(true); + Assert.IsTrue(_webView.HasFocus, "Fail to set focus as true"); + _webView.SetFocus(false); + Assert.IsFalse(_webView.HasFocus, "Fail to set focus as false"); + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs new file mode 100755 index 000000000..93599c387 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using ElmSharp; + +namespace Tizen.WebView.Tests +{ + internal static class WebViewCommon + { + public const string SampleHtml = "file:///opt/usr/home/owner/share/res/sample.html"; + public const string SampleHtml1 = "file:///opt/usr/home/owner/share/res/sample_1.html"; + public const string SampleHtml2 = "file:///opt/usr/home/owner/share/res/sample_2.html"; + public const string AddJavaScriptInterfaceSampleHtml = "file:///opt/usr/home/owner/share/res/add_js_interface_sample.html"; + public const string SampleHtmlTitle = "Testing Sample Page"; + + public const string TestUrl = "https://www.tizen.org/"; + public const string TestUrlForError = "http://page_that_does_not_exist/"; + public const string TestUserAgent = "Mozilla/5.0 (Unknown; Linux armv7l) AppleWebKit/538.1 (KHTML, like Gecko) Version/5.0 Safari/538.1"; + public const string TestHtml = ""; + public const string TestScript = "document.getElementById('getParaContent').innerHTML"; + + private static Window _instance; + + public static Window GetMainWindow() + { + if (_instance == null) + { + _instance = new Window("WebView Auto Tests"); + } + return _instance; + } + } +} diff --git a/tct-suite-vs/Tizen.WebView.Tests/tizen-manifest.xml b/tct-suite-vs/Tizen.WebView.Tests/tizen-manifest.xml new file mode 100755 index 000000000..0be9c5fa4 --- /dev/null +++ b/tct-suite-vs/Tizen.WebView.Tests/tizen-manifest.xml @@ -0,0 +1,15 @@ + + + + + Tizen.WebView.Tests.png + + + + + + http://tizen.org/privilege/appmanager.launch + http://tizen.org/privilege/internet + + +