Test: Add testClearFormData to lollipop-mr1-cts-dev

Bug: 33286048

Change-Id: Ie469cefbb90bbc996ee5d7f2b0e30f0b923105d8
diff --git a/tests/tests/webkit/assets/webkit/test_loginForm.html b/tests/tests/webkit/assets/webkit/test_loginForm.html
new file mode 100644
index 0000000..0935cf1
--- /dev/null
+++ b/tests/tests/webkit/assets/webkit/test_loginForm.html
@@ -0,0 +1,23 @@
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     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.
+-->
+
+<html>
+    <body>
+        <form>
+            <input type='text' name='username' value='Cts Test'/>
+            <input type='submit' name='submit' value='Submit'/>
+        </form>
+    </body>
+</html>
diff --git a/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java b/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java
index 30b8210..4ca33b8 100644
--- a/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java
+++ b/tests/tests/webkit/src/android/webkit/cts/TestHtmlConstants.java
@@ -55,6 +55,8 @@
     public static final String BLANK_PAGE_URL = "webkit/test_blankPage.html";
     public static final String ADD_JAVA_SCRIPT_INTERFACE_URL = "webkit/test_jsInterface.html";
 
+    public static final String LOGIN_FORM_URL = "webkit/test_loginForm.html";
+
     public static final String EXT_WEB_URL1 = "http://www.example.com/";
 
     public static final String LOCAL_FILESYSTEM_URL = "file:///etc/hosts";
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index c3fdb49..919add2 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -1151,6 +1151,39 @@
         }.run();
     }
 
+    public void testClearFormData() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+        try {
+            startWebServer(false);
+            WebSettings settings = mOnUiThread.getSettings();
+            settings.setDatabaseEnabled(true);
+            settings.setJavaScriptEnabled(true);
+            WebViewDatabase webViewDatabase = WebViewDatabase.getInstance(getActivity());
+            webViewDatabase.clearFormData();
+            final String url = mWebServer.getAssetUrl(TestHtmlConstants.LOGIN_FORM_URL);
+            mOnUiThread.loadUrlAndWaitForCompletion(url);
+            new PollingCheck(TEST_TIMEOUT) {
+                @Override
+                public boolean check() {
+                    return !WebViewDatabase.getInstance(getActivity()).hasFormData();
+                }
+            }.run();
+            // Click submit (using JS, rather than simulated key presses, to avoid IME
+            // inconsistencies).
+            mOnUiThread.evaluateJavascript("document.getElementsByName('submit')[0].click()", null);
+            new PollingCheck(TEST_TIMEOUT) {
+                @Override
+                public boolean check() {
+                    return WebViewDatabase.getInstance(getActivity()).hasFormData();
+                }
+            }.run();
+        } finally {
+            WebViewDatabase.getInstance(getActivity()).clearFormData();
+        }
+    }
+
     @UiThreadTest
     public void testAccessHttpAuthUsernamePassword() {
         if (!NullWebViewUtils.isWebViewAvailable()) {