[WebView][Non-ACR] Test form submit without using network 40/244740/2
authoryh106.jung <yh106.jung@samsung.com>
Thu, 24 Sep 2020 01:04:08 +0000 (10:04 +0900)
committeryh106.jung <yh106.jung@samsung.com>
Tue, 20 Oct 2020 08:34:52 +0000 (17:34 +0900)
Some web sites have been blocked by internal proxy during emulator test.
e.g. http://jkorpela.fi/cgi-bin/echo.cgi
To avoid network error, this patch tests form submit without using network.
`Form Resubmitted` event can be generated by reloading the page that has
a form.

Change-Id: Iccad8a2048e8c2eb11056d705d51c55cb693a91e
Signed-off-by: yh106.jung <yh106.jung@samsung.com>
tct-suite-vs/Tizen.WebView.Tests/res/form_submit_sample.html
tct-suite-vs/Tizen.WebView.Tests/testcase/TSNavigationPolicyEventArgs.cs

index 945f1e1..e385e28 100755 (executable)
@@ -6,26 +6,14 @@ This test file is common file and can be used by EWK APIs to load web pages.
     <title>Testing Sample Page</title>\r
     <script>\r
         function submitForm() {\r
-            document.getElementById('formContent').submit();\r
+            document.forms[0].submit();\r
         }\r
     </script>\r
 </head>\r
 <body>\r
-    <h1>Sample HTML</h1>\r
-    <p>This is sample html page to be used in test suite when loading of a page is required.</p>\r
-    <form id="formContent" action="http://jkorpela.fi/cgi-bin/echo.cgi" method="post">\r
-        <P>\r
-            Type something:<br>\r
-<textarea rows=5 cols=72 name=Comments>\r
-This is\r
-some text\r
-in several lines.\r
-</textarea>\r
-        <p>\r
-            <input type="checkbox" name="box" value="yes">Check me!\r
-        <P>\r
-            <input type="hidden" name="hidden field" value="something">\r
-            <input type="submit" value="Send">\r
+    <form action="form_submit_sample.html" method="post">\r
+        <input name="a" value="b">\r
+        <input id="mysubmit" type="submit" name="Submit" value="Submit">\r
     </form>\r
 </body>\r
-</html>
\ No newline at end of file
+</html>\r
index d14e97c..af3c43a 100755 (executable)
@@ -329,50 +329,41 @@ namespace Tizen.WebView.Tests
 
             Assert.IsTrue(result, "LoadUrl method failed");
 
-            TaskCompletionSource<bool> tcsEval = new TaskCompletionSource<bool>(false);
-            EventHandler onLoadFinishedEval = (s, e) => { tcsEval.TrySetResult(true); };
-            EventHandler<SmartCallbackLoadErrorArgs> onLoadErrorEval = (s, e) => { tcsEval.TrySetResult(false); };
+            TaskCompletionSource<bool> tcsSubmit = new TaskCompletionSource<bool>(false);
+            EventHandler<NavigationPolicyEventArgs> onNavigationPolicyDecide = (s, e) =>
+            {
+                if (e.NavigationType == NavigationType.FormSubmitted)
+                {
+                    tcsSubmit.TrySetResult(true);
+                    return;
+                }
+                tcsSubmit.TrySetResult(false);
+            };
 
-            _webView.LoadFinished += onLoadFinishedEval;
-            _webView.LoadError += onLoadErrorEval;
+            _webView.NavigationPolicyDecideRequested += onNavigationPolicyDecide;
 
             _webView.Eval("submitForm()");
-            result = await tcsEval.Task;
+            result = await tcsSubmit.Task;
 
-            _webView.LoadFinished -= onLoadFinishedEval;
-            _webView.LoadError -= onLoadErrorEval;
+            _webView.NavigationPolicyDecideRequested -= onNavigationPolicyDecide;
 
             Assert.IsTrue(result, "Eval method failed");
 
-            TaskCompletionSource<bool> tcsGoBack = new TaskCompletionSource<bool>(false);
-            EventHandler onLoadFinishedGoBack = (s, e) => { tcsGoBack.TrySetResult(true); };
-            EventHandler<SmartCallbackLoadErrorArgs> 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<bool> tcs = new TaskCompletionSource<bool>(false);
-            EventHandler<NavigationPolicyEventArgs> onNavigationPolicyDecide = (s, e) =>
+            onNavigationPolicyDecide = (s, e) =>
             {
-                Log.Debug("TCT", "NavigationType: " + e.NavigationType.ToString());
                 if (e.NavigationType == NavigationType.FormResubmitted)
                 {
                     tcs.TrySetResult(true);
+                    return;
                 }
+                tcs.TrySetResult(false);
             };
 
             _webView.NavigationPolicyDecideRequested += onNavigationPolicyDecide;
 
-            _webView.GoForward();
+            _webView.Reload();
             result = await tcs.Task;
 
             _webView.NavigationPolicyDecideRequested -= onNavigationPolicyDecide;