diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2019-09-27 18:13:52 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-09-27 18:13:52 +0000 |
commit | 8719ff4006e7327f53fa603dc331af7ab75b95ab (patch) | |
tree | ccfb7838e1b8c1e390fabe0d88251776c83ab3b6 | |
parent | 7adf756b7ce3f1d52b83f4e751af89ac1ea6c5af (diff) | |
parent | 7bb4432ce64f0ee135c13f3a07356715157a14e8 (diff) | |
download | cts-8719ff4006e7327f53fa603dc331af7ab75b95ab.tar.gz |
Merge "Update ServiceWorkerClientTest CTS test to make sure SW is unregistered." into nougat-cts-dev
-rw-r--r-- | tests/tests/webkit/src/android/webkit/cts/ServiceWorkerClientTest.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/tests/webkit/src/android/webkit/cts/ServiceWorkerClientTest.java b/tests/tests/webkit/src/android/webkit/cts/ServiceWorkerClientTest.java index a77d648f069..9a703ebe5c3 100644 --- a/tests/tests/webkit/src/android/webkit/cts/ServiceWorkerClientTest.java +++ b/tests/tests/webkit/src/android/webkit/cts/ServiceWorkerClientTest.java @@ -55,13 +55,22 @@ public class ServiceWorkerClientTest extends ActivityInstrumentationTestCase2<We + " <script>\n" + " navigator.serviceWorker.register('sw.js').then(function(reg) {\n" + " " + JS_INTERFACE_NAME + ".registrationSuccess();\n" - + " }).catch(function(err) { \n" + + " }).catch(function(err) {\n" + " console.error(err);\n" + " });\n" + " </script>\n" + " </body>\n" + "</html>\n"; private static final String SW_RAW_HTML = "fetch('fetch.html');"; + private static final String SW_UNREGISTER_RAW_JS = + "navigator.serviceWorker.getRegistration().then(function(r) {" + + " r.unregister().then(function(success) {" + + " if (success) " + JS_INTERFACE_NAME + ".unregisterSuccess();" + + " else console.error('unregister() was not successful');" + + " });" + + "}).catch(function(err) {" + + " console.error(err);" + + "});"; private JavascriptStatusReceiver mJavascriptStatusReceiver; private WebViewOnUiThread mOnUiThread; @@ -165,17 +174,34 @@ public class ServiceWorkerClientTest extends ActivityInstrumentationTestCase2<We assertEquals(2, requests.size()); assertEquals(SW_URL, requests.get(0).getUrl().toString()); assertEquals(FETCH_URL, requests.get(1).getUrl().toString()); + + // Clean-up, make sure to unregister the Service Worker. + mOnUiThread.evaluateJavascript(SW_UNREGISTER_RAW_JS, null); + Callable<Boolean> unregisterSuccess = new Callable<Boolean>() { + @Override + public Boolean call() { + return mJavascriptStatusReceiver.mUnregisterSuccess; + } + }; + PollingCheck.check("JS could not unregister Service Worker", POLLING_TIMEOUT, + unregisterSuccess); } // Object added to the page via AddJavascriptInterface() that is used by the test Javascript to // notify back to Java if the Service Worker registration was successful. public final static class JavascriptStatusReceiver { public volatile boolean mRegistrationSuccess = false; + public volatile boolean mUnregisterSuccess = false; @JavascriptInterface public void registrationSuccess() { mRegistrationSuccess = true; } + + @JavascriptInterface + public void unregisterSuccess() { + mUnregisterSuccess = true; + } } } |