[WebView][TCSACR-316] Add TCs for new API, Tizen.WebView.EvalAsync 21/231421/4
authoryh106.jung <yh106.jung@samsung.com>
Wed, 22 Apr 2020 02:36:38 +0000 (11:36 +0900)
committeryh106.jung <yh106.jung@samsung.com>
Tue, 28 Apr 2020 23:29:25 +0000 (08:29 +0900)
This patch adds TCs for new API, Tizen.WebView.EvalAsync.

Change-Id: Ib876a22a76339ad0090be7c056d077c6b37d84b4
Signed-off-by: yh106.jung <yh106.jung@samsung.com>
tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs
tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs

index 1a561f6..8b1ba33 100755 (executable)
@@ -1047,6 +1047,103 @@ namespace Tizen.WebView.Tests
 
         [Test]
         [Category("P1")]
+        [Description("Requests the execution of the given script and gets the result of evaluation")]
+        [Property("SPEC", "Tizen.WebView.WebView.EvalAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")]
+        public async Task EvalAsync_RETURN_VALUE()
+        {
+            /* PRECONDITION */
+            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
+            EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); };
+            EventHandler<SmartCallbackLoadErrorArgs> 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 */
+            string returnValue = "";
+            try
+            {
+                returnValue = await _webView.EvalAsync(WebViewCommon.TestScript);
+            }
+            catch (Exception e)
+            {
+                Assert.True(false, e.Message);
+            }
+
+            Assert.AreEqual("test content", returnValue, WebViewCommon.ReturnOfTestScript);
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Checks whether EvalAsync throws ArgumentException when script is null")]
+        [Property("SPEC", "Tizen.WebView.WebView.EvalAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")]
+        public async Task EvalAsync_ARGUMENT_EXCEPTION_NULL_SCRIPT()
+        {
+            /* PRECONDITION */
+            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
+            EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); };
+            EventHandler<SmartCallbackLoadErrorArgs> 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 */
+            Assert.ThrowsAsync<ArgumentException>(async () => await _webView.EvalAsync(null), "ArgumentException should be thrown");
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Checks whether EvalAsync throws ArgumentException when script is empty")]
+        [Property("SPEC", "Tizen.WebView.WebView.EvalAsync M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Youngha Jung, yh106.jung@samsung.com")]
+        public async Task EvalAsync_ARGUMENT_EXCEPTION_EMPTY_SCRIPT()
+        {
+            /* PRECONDITION */
+            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
+            EventHandler onLoadFinished = (s, e) => { tcs.TrySetResult(true); };
+            EventHandler<SmartCallbackLoadErrorArgs> 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 */
+            Assert.ThrowsAsync<ArgumentException>(async () => await _webView.EvalAsync(""), "ArgumentException should be thrown");
+        }
+
+        [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", "-")]
index 1ab8734..49239ea 100755 (executable)
@@ -37,6 +37,7 @@ namespace Tizen.WebView.Tests
         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 = "<html><body onload='document.title=document.URL'></body></html>";
         public const string TestScript = "document.getElementById('getParaContent').innerHTML";
+        public const string ReturnOfTestScript = "The result of evaluation should be same with expected value";
         public const string TestCookie = "foo=bar";
 
         private static Window _instance;