summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/subapps
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/subapps')
-rw-r--r--testing/web-platform/tests/subapps/add-error.tentative.https.html143
-rw-r--r--testing/web-platform/tests/subapps/add-success.tentative.https.html57
-rw-r--r--testing/web-platform/tests/subapps/idlharness.tentative.https.window.js15
-rw-r--r--testing/web-platform/tests/subapps/insecure-context-error.tentative.html12
-rw-r--r--testing/web-platform/tests/subapps/list-error.tentative.https.html46
-rw-r--r--testing/web-platform/tests/subapps/list-success.tentative.https.html53
-rw-r--r--testing/web-platform/tests/subapps/remove-error.tentative.https.html46
-rw-r--r--testing/web-platform/tests/subapps/remove-success.tentative.https.html12
-rw-r--r--testing/web-platform/tests/subapps/resources/subapps-helpers.js99
9 files changed, 483 insertions, 0 deletions
diff --git a/testing/web-platform/tests/subapps/add-error.tentative.https.html b/testing/web-platform/tests/subapps/add-error.tentative.https.html
new file mode 100644
index 0000000000..d049268af9
--- /dev/null
+++ b/testing/web-platform/tests/subapps/add-error.tentative.https.html
@@ -0,0 +1,143 @@
+<!DOCTYPE html>
+<title>Sub Apps: Error cases for add()</title>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/subapps-helpers.js"></script>
+
+<body></body>
+
+<script>
+
+promise_test(async t => {
+ const iframe = document.createElement('iframe');
+ document.body.appendChild(iframe);
+
+ const iframeNavigator = iframe.contentWindow.navigator;
+ const iframeDOMException = iframe.contentWindow.DOMException;
+
+ // Detach the frame.
+ iframe.remove();
+
+ const same_origin_url = document.location.origin + '/sub-app';
+ let subapp = {};
+ let install_options = {};
+ install_options["install_url"] = same_origin_url;
+ subapp[same_origin_url] = install_options;
+
+ // At this point the iframe is detached and unloaded, and its execution
+ // context is gone.
+ await promise_rejects_dom(t, 'NotFoundError', iframeDOMException, iframeNavigator.subApps.add(subapp));
+}, "The object is no longer associated to a document.");
+
+promise_test(async t => {
+ const iframe = document.createElement('iframe');
+ document.body.appendChild(iframe);
+
+ const iframeNavigator = iframe.contentWindow.navigator;
+ const iframeDOMException = iframe.contentWindow.DOMException;
+ t.add_cleanup(() => iframe.remove());
+
+ const same_origin_url = document.location.origin + '/sub-app';
+ let subapp = {};
+ let install_options = {};
+ install_options["install_url"] = same_origin_url;
+ subapp[same_origin_url] = install_options;
+
+ await promise_rejects_dom(t, 'InvalidStateError', iframeDOMException, iframeNavigator.subApps.add(subapp));
+}, "API is only supported in top-level browsing contexts.");
+
+promise_test(async t => {
+ const wrong_origin_url = 'https://some.other.origin/sub-app';
+ let subapp = {};
+ let install_options = {};
+ install_options["install_url"] = wrong_origin_url;
+ subapp[wrong_origin_url] = install_options;
+
+ await test_driver.bless("installing a subapp", async function () {
+ await promise_rejects_dom(t, 'URLMismatchError', navigator.subApps.add(subapp));
+ });
+}, 'Wrong origin URL argument.');
+
+promise_test(async t => {
+ const same_origin_url = document.location.origin + '/sub-app';
+
+ let add_call_params = {};
+ let install_options = {};
+ install_options["install_url"] = same_origin_url;
+ add_call_params[same_origin_url] = install_options;
+
+ let mocked_response = [
+ { unhashedAppId: same_origin_url, resultCode: AddCallResultCode.EXPECTED_APP_ID_CHECK_FAILED }
+ ]
+ let expected_results = {};
+ expected_results[same_origin_url] = "expected-app-id-check-failed";
+
+ await test_driver.bless("installing a subapp", async function () {
+ await subapps_add_expect_reject_with_result(t, add_call_params, mocked_response, expected_results);
+ });
+}, 'Service failed to add single sub-app.');
+
+promise_test(async t => {
+ const same_origin_url = document.location.origin + '/sub-app';
+
+ let subapp = {
+ [same_origin_url]: { install_url: same_origin_url }
+ };
+
+ await promise_rejects_dom(t, 'NotAllowedError', navigator.subApps.add(subapp));
+}, 'Missing user activation.');
+
+promise_test(async t => {
+ let add_call_params = {};
+
+ const url_1 = document.location.origin + '/sub-app-1';
+ let install_options_1 = {};
+ install_options_1["install_url"] = url_1;
+ add_call_params[url_1] = install_options_1;
+
+ const url_2 = document.location.origin + '/sub-app-2';
+ let install_options_2 = {};
+ install_options_2["install_url"] = url_2;
+ add_call_params[url_2] = install_options_2;
+
+ let mocked_response = [
+ { unhashedAppId: url_1, resultCode: AddCallResultCode.EXPECTED_APP_ID_CHECK_FAILED },
+ { unhashedAppId: url_2, resultCode: AddCallResultCode.INSTALL_URL_INVALID }
+ ]
+ let expected_results = {};
+ expected_results[url_1] = "expected-app-id-check-failed";
+ expected_results[url_2] = "install-url-invalid";
+
+ await test_driver.bless("installing a subapp", async function () {
+ await subapps_add_expect_reject_with_result(t, add_call_params, mocked_response, expected_results);
+ });
+}, 'Service failed to add two sub-apps.');
+
+promise_test(async t => {
+ let add_call_params = {};
+
+ const url_1 = document.location.origin + '/sub-app-1';
+ let install_options_1 = {};
+ install_options_1["install_url"] = url_1;
+ add_call_params[url_1] = install_options_1;
+
+ const url_2 = document.location.origin + '/sub-app-2';
+ let install_options_2 = {};
+ install_options_2["install_url"] = url_2;
+ add_call_params[url_2] = install_options_2;
+
+ let mocked_response = [
+ { unhashedAppId: url_1, resultCode: AddCallResultCode.SUCCESS_NEW_INSTALL },
+ { unhashedAppId: url_2, resultCode: AddCallResultCode.EXPECTED_APP_ID_CHECK_FAILED }
+ ]
+ let expected_results = {};
+ expected_results[url_1] = "success-new-install";
+ expected_results[url_2] = "expected-app-id-check-failed";
+
+ await test_driver.bless("installing a subapp", async function () {
+ await subapps_add_expect_reject_with_result(t, add_call_params, mocked_response, expected_results);
+ });
+}, 'Service added one sub-app failed to add another sub-app.');
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/subapps/add-success.tentative.https.html b/testing/web-platform/tests/subapps/add-success.tentative.https.html
new file mode 100644
index 0000000000..b2751adcb8
--- /dev/null
+++ b/testing/web-platform/tests/subapps/add-success.tentative.https.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<title>Sub Apps: Valid calls for add()</title>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/subapps-helpers.js"></script>
+
+<script>
+
+promise_test(async t => {
+ const same_origin_url = document.location.origin + '/sub-app';
+
+ let add_call_params = {};
+ let install_options = {};
+ install_options["install_url"] = same_origin_url;
+ add_call_params[same_origin_url] = install_options;
+
+ let mocked_response = [
+ { unhashedAppId: same_origin_url, resultCode: AddCallResultCode.SUCCESS_NEW_INSTALL }
+ ]
+ let expected_results = {};
+ expected_results[same_origin_url] = "success-new-install";
+
+ await test_driver.bless("installing a subapp", async function () {
+ await subapps_add_expect_success_with_result(t, add_call_params, mocked_response, expected_results);
+ });
+}, 'Add API call works with single sub app.');
+
+promise_test(async t => {
+ let add_call_params = {};
+
+ const url_1 = document.location.origin + '/sub-app-1';
+ let install_options_1 = {};
+ install_options_1["install_url"] = url_1;
+ add_call_params[url_1] = install_options_1;
+
+ const url_2 = document.location.origin + '/sub-app-2';
+ let install_options_2 = {};
+ install_options_2["install_url"] = url_2;
+ add_call_params[url_2] = install_options_2;
+
+ let mocked_response = [
+ { unhashedAppId: url_1, resultCode: AddCallResultCode.SUCCESS_NEW_INSTALL },
+ { unhashedAppId: url_2, resultCode: AddCallResultCode.SUCCESS_NEW_INSTALL }
+ ]
+ let expected_results = {};
+ expected_results[url_1] = "success-new-install";
+ expected_results[url_2] = "success-new-install";
+
+
+ await test_driver.bless("installing a subapp", async function () {
+ await subapps_add_expect_success_with_result(t, add_call_params, mocked_response, expected_results);
+ });
+}, 'Add API call works with multiple sub apps.');
+
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/subapps/idlharness.tentative.https.window.js b/testing/web-platform/tests/subapps/idlharness.tentative.https.window.js
new file mode 100644
index 0000000000..65a1156188
--- /dev/null
+++ b/testing/web-platform/tests/subapps/idlharness.tentative.https.window.js
@@ -0,0 +1,15 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+
+'use strict';
+
+idl_test(
+ ['sub-apps.tentative'],
+ ['html', 'dom'],
+ idl_array => {
+ idl_array.add_objects({
+ Navigator: ['navigator'],
+ SubApps: ['navigator.subApps'],
+ });
+ }
+);
diff --git a/testing/web-platform/tests/subapps/insecure-context-error.tentative.html b/testing/web-platform/tests/subapps/insecure-context-error.tentative.html
new file mode 100644
index 0000000000..ada4a846e8
--- /dev/null
+++ b/testing/web-platform/tests/subapps/insecure-context-error.tentative.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<title>Sub Apps: subApps is undefined in insecure context (non-https)</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+test(() => {
+ assert_equals(navigator.subApps, undefined);
+ assert_equals(window.SubApps, undefined);
+}, 'subApps is not defined in insecure context.');
+
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/subapps/list-error.tentative.https.html b/testing/web-platform/tests/subapps/list-error.tentative.https.html
new file mode 100644
index 0000000000..1161318acd
--- /dev/null
+++ b/testing/web-platform/tests/subapps/list-error.tentative.https.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<title>Sub Apps: Error cases for list()</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/subapps-helpers.js"></script>
+
+<body></body>
+
+<script>
+
+promise_test(async t => {
+ const iframe = document.createElement('iframe');
+ document.body.appendChild(iframe);
+
+ const iframeNavigator = iframe.contentWindow.navigator;
+ const iframeDOMException = iframe.contentWindow.DOMException;
+
+ // Detach the frame.
+ iframe.remove();
+
+ // At this point the iframe is detached and unloaded, and its execution
+ // context is gone.
+ await promise_rejects_dom(t, 'NotFoundError', iframeDOMException, iframeNavigator.subApps.list());
+}, "The object is no longer associated to a document.");
+
+promise_test(async t => {
+ const iframe = document.createElement('iframe');
+ document.body.appendChild(iframe);
+
+ const iframeNavigator = iframe.contentWindow.navigator;
+ const iframeDOMException = iframe.contentWindow.DOMException;
+ t.add_cleanup(() => iframe.remove());
+
+ await promise_rejects_dom(t, 'InvalidStateError', iframeDOMException, iframeNavigator.subApps.list());
+}, "API is only supported in top-level browsing contexts.");
+
+promise_test(async t => {
+ t.add_cleanup(async () => {
+ await mockSubAppsService.reset();
+ mockSubAppsService = null;
+ });
+ await createMockSubAppsService(Status.FAILURE, [], []);
+ return promise_rejects_dom(t, 'OperationError', navigator.subApps.list());
+}, 'List call failed.');
+
+</script>
diff --git a/testing/web-platform/tests/subapps/list-success.tentative.https.html b/testing/web-platform/tests/subapps/list-success.tentative.https.html
new file mode 100644
index 0000000000..0ee02230e8
--- /dev/null
+++ b/testing/web-platform/tests/subapps/list-success.tentative.https.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<title>Sub Apps: Valid calls for list()</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/subapps-helpers.js"></script>
+<script>
+
+promise_test(async t => {
+ t.add_cleanup(async () => {
+ await mockSubAppsService.reset();
+ mockSubAppsService = null;
+ });
+
+ const url_1 = document.location.origin + '/sub-app-1';
+ const url_2 = document.location.origin + '/sub-app-2';
+ const mocked_response = [{ unhashedAppId: url_1, appName: "App 1" }, { unhashedAppId: url_2, appName: "App 2" }];
+
+ let expected_results = {};
+ expected_results[url_1] = { "app_name": "App 1" };
+ expected_results[url_2] = { "app_name": "App 2" };
+
+ await createMockSubAppsService(Status.SUCCESS, [], mocked_response);
+
+ await navigator.subApps.list()
+ .catch(e => {
+ assert_unreached("Should not have rejected.");
+ })
+ .then(result => {
+ for (const app_id in expected_results) {
+ assert_own_property(result, app_id, "Return results are missing entry for subapp.")
+ assert_equals(JSON.stringify(result[app_id]), JSON.stringify(expected_results[app_id]), "Return results are not as expected.")
+ }
+ })
+}, 'List API call works with 2 sub apps.');
+
+promise_test(async t => {
+ t.add_cleanup(async () => {
+ await mockSubAppsService.reset();
+ mockSubAppsService = null;
+ });
+
+ let mocked_response = [];
+ await createMockSubAppsService(Status.SUCCESS, [], mocked_response);
+ await navigator.subApps.list()
+ .catch(e => {
+ assert_unreached("Should not have rejected.");
+ })
+ .then(result => {
+ assert_equals(Object.keys(result).length, 0);
+ })
+}, 'List API call works with no sub apps.');
+
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/subapps/remove-error.tentative.https.html b/testing/web-platform/tests/subapps/remove-error.tentative.https.html
new file mode 100644
index 0000000000..05305c4faf
--- /dev/null
+++ b/testing/web-platform/tests/subapps/remove-error.tentative.https.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<title>Sub Apps: Error cases for remove()</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/subapps-helpers.js"></script>
+
+<body></body>
+
+<script>
+
+promise_test(async t => {
+ const iframe = document.createElement('iframe');
+ document.body.appendChild(iframe);
+
+ const iframeNavigator = iframe.contentWindow.navigator;
+ const iframeDOMException = iframe.contentWindow.DOMException;
+
+ // Detach the frame.
+ iframe.remove();
+
+ // At this point the iframe is detached and unloaded, and its execution
+ // context is gone.
+ await promise_rejects_dom(t, 'NotFoundError', iframeDOMException, iframeNavigator.subApps.remove('sub-app-id'));
+}, "The object is no longer associated to a document.");
+
+promise_test(async t => {
+ const iframe = document.createElement('iframe');
+ document.body.appendChild(iframe);
+
+ const iframeNavigator = iframe.contentWindow.navigator;
+ const iframeDOMException = iframe.contentWindow.DOMException;
+ t.add_cleanup(() => iframe.remove());
+
+ await promise_rejects_dom(t, 'InvalidStateError', iframeDOMException, iframeNavigator.subApps.remove('sub-app-id'));
+}, "API is only supported in top-level browsing contexts.");
+
+promise_test(async t => {
+ t.add_cleanup(async () => {
+ await mockSubAppsService.reset();
+ mockSubAppsService = null;
+ });
+ await createMockSubAppsService(Status.FAILURE, [], []);
+ return promise_rejects_dom(t, 'OperationError', navigator.subApps.remove('sub-app-id'));
+}, 'Remove call failed.');
+
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/subapps/remove-success.tentative.https.html b/testing/web-platform/tests/subapps/remove-success.tentative.https.html
new file mode 100644
index 0000000000..a4148fd869
--- /dev/null
+++ b/testing/web-platform/tests/subapps/remove-success.tentative.https.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<title>Sub Apps: Valid calls for remove()</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/subapps-helpers.js"></script>
+<script>
+
+subapps_test(async (t, mockSubAppsService) => {
+ await navigator.subApps.remove('/sub/app/id');
+}, 'Remove API call works.');
+
+</script> \ No newline at end of file
diff --git a/testing/web-platform/tests/subapps/resources/subapps-helpers.js b/testing/web-platform/tests/subapps/resources/subapps-helpers.js
new file mode 100644
index 0000000000..e923db01f3
--- /dev/null
+++ b/testing/web-platform/tests/subapps/resources/subapps-helpers.js
@@ -0,0 +1,99 @@
+// This mock provides a way to intercept renderer <-> browser mojo messages for
+// navigator.subApps.* calls eliminating the need for an actual browser.
+//
+// In Chromium-based browsers this implementation is provided by a polyfill
+// in order to reduce the amount of test-only code shipped to users.
+
+'use strict';
+
+let mockSubAppsService = null;
+
+const Status = {
+ SUCCESS: 0,
+ FAILURE: 1,
+};
+
+const AddCallResultCode = {
+ SUCCESS_NEW_INSTALL: 0,
+ SUCCESS_ALREADY_INSTALLED: 1,
+ USER_INSTALL_DECLINED: 2,
+ EXPECTED_APP_ID_CHECK_FAILED: 3,
+ PARENT_APP_UNINSTALLED: 4,
+ INSTALL_URL_INVALID: 5,
+ NOT_VALID_MANIFEST_FOR_WEB_APP: 6,
+ FAILURE: 7,
+}
+
+async function createMockSubAppsService(service_result_code, add_call_return_value, list_call_return_value) {
+ if (typeof SubAppsServiceTest === 'undefined') {
+ // Load test-only API helpers.
+ const script = document.createElement('script');
+ script.src = '/resources/test-only-api.js';
+ script.async = false;
+ const p = new Promise((resolve, reject) => {
+ script.onload = () => { resolve(); };
+ script.onerror = e => { reject(e); };
+ })
+ document.head.appendChild(script);
+ await p;
+
+ if (isChromiumBased) {
+ // Chrome setup.
+ await import('/resources/chromium/mock-subapps.js');
+ } else {
+ throw new Error('Unsupported browser.');
+ }
+ }
+ assert_implements(SubAppsServiceTest, 'SubAppsServiceTest is not loaded properly.');
+
+ if (mockSubAppsService === null) {
+ mockSubAppsService = new SubAppsServiceTest();
+ mockSubAppsService.initialize(service_result_code, add_call_return_value, list_call_return_value);
+ }
+}
+
+function subapps_test(func, description) {
+ promise_test(async test => {
+ test.add_cleanup(async () => {
+ await mockSubAppsService.reset();
+ mockSubAppsService = null;
+ });
+ await createMockSubAppsService(Status.SUCCESS, [], []);
+ await func(test, mockSubAppsService);
+ }, description);
+}
+
+async function subapps_add_expect_reject_with_result(t, add_call_params, mocked_response, expected_results) {
+ t.add_cleanup(async () => {
+ await mockSubAppsService.reset();
+ mockSubAppsService = null;
+ });
+
+ await createMockSubAppsService(Status.FAILURE, mocked_response, []);
+ await navigator.subApps.add(add_call_params)
+ .then(result => {
+ assert_unreached("Should have rejected.");
+ })
+ .catch(result => {
+ for (const app_id in expected_results) {
+ assert_own_property(result, app_id, "Return results are missing entry for subapp.")
+ assert_equals(result[app_id], expected_results[app_id], "Return results are not as expected.")
+ }
+ });
+}
+
+async function subapps_add_expect_success_with_result(t, add_call_params, mocked_response, expected_results) {
+ t.add_cleanup(async () => {
+ await mockSubAppsService.reset();
+ mockSubAppsService = null;
+ });
+
+ await createMockSubAppsService(Status.SUCCESS, mocked_response);
+ await navigator.subApps.add(add_call_params)
+ .then(result => {
+ for (const app_id in expected_results) {
+ assert_own_property(result, app_id, "Return results are missing entry for subapp.")
+ assert_equals(result[app_id], expected_results[app_id], "Return results are not as expected.")
+ }
+ })
+}