From: yh106.jung Date: Wed, 22 Apr 2020 02:36:38 +0000 (+0900) Subject: [WebView][TCSACR-316] Add TCs for new API, Tizen.WebView.EvalAsync X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F231421%2F4;p=test%2Ftct%2Fcsharp%2Fapi.git [WebView][TCSACR-316] Add TCs for new API, Tizen.WebView.EvalAsync This patch adds TCs for new API, Tizen.WebView.EvalAsync. Change-Id: Ib876a22a76339ad0090be7c056d077c6b37d84b4 Signed-off-by: yh106.jung --- diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs index 1a561f69d..8b1ba3387 100755 --- a/tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/TSWebView.cs @@ -1045,6 +1045,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 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 */ + 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 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 */ + Assert.ThrowsAsync(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 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 */ + Assert.ThrowsAsync(async () => await _webView.EvalAsync(""), "ArgumentException should be thrown"); + } + [Test] [Category("P1")] [Description("Requests to set or unset a view as the currently focused one")] diff --git a/tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs b/tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs index 1ab8734c8..49239ea92 100755 --- a/tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs +++ b/tct-suite-vs/Tizen.WebView.Tests/testcase/support/WebViewCommon.cs @@ -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 = ""; 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;