diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/subapps | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/subapps')
9 files changed, 561 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..defe4743c6 --- /dev/null +++ b/testing/web-platform/tests/subapps/add-error.tentative.https.html @@ -0,0 +1,123 @@ +<!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(); + + // 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({})); +}, "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.add({})); +}, "API is only supported in top-level browsing contexts."); + +promise_test(async t => { + const url = '/sub-app'; + + let subapp = { + [url]: { "installURL": url } + }; + + await promise_rejects_dom(t, 'NotAllowedError', navigator.subApps.add(subapp)); +}, 'Missing user activation.'); + +promise_test(async t => { + const base_url = '/sub-app-'; + + let add_call_params = {}; + for (let i = 0; i < 8; i++) { + const url = base_url + i; + add_call_params[url] = { "installURL": url }; + } + + await test_driver.bless("installing subapps", async function () { + await promise_rejects_dom(t, 'DataError', navigator.subApps.add(add_call_params)); + }); +}, 'Too many subapps at once.'); + +promise_test(async t => { + const full_url = document.location.origin + '/sub-app'; + + let add_call_params = { + [full_url]: { installURL: full_url }, + }; + + await test_driver.bless("installing subapps", async function () { + await promise_rejects_dom(t, 'NotSupportedError', navigator.subApps.add(add_call_params)); + }); +}, 'API supports only root-relative paths.'); + +promise_test(async t => { + const url_1 = '/sub-app-1'; + const url_2 = '/sub-app-2'; + + let add_call_params = { + [url_1]: {installURL: url_1}, + [url_2]: {installURL: url_2}, + }; + + let mocked_response = [ + { "manifestIdPath": url_1, "resultCode": Status.FAILURE }, + { "manifestIdPath": url_2, "resultCode": Status.FAILURE } + ]; + + let expected_results = { + [url_1]: "failure", + [url_2]: "failure", + }; + + 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 => { + const url_1 = '/sub-app-1'; + const url_2 = '/sub-app-2'; + + let add_call_params = { + [url_1]: {installURL: url_1}, + [url_2]: {installURL: url_2}, + }; + + let mocked_response = [ + { "manifestIdPath": url_1, "resultCode": Status.SUCCESS }, + { "manifestIdPath": url_2, "resultCode": Status.FAILURE } + ]; + + let expected_results = { + [url_1]: "success", + [url_2]: "failure", + }; + + 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..a9a439b36a --- /dev/null +++ b/testing/web-platform/tests/subapps/add-success.tentative.https.html @@ -0,0 +1,56 @@ +<!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 install_url = '/sub-app'; + + let add_call_params = { + [install_url]: {installURL: install_url} + }; + + let mocked_response = [ + { "manifestIdPath": install_url, "resultCode": Status.SUCCESS } + ]; + + let expected_results = { + [install_url]: "success" + }; + + 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 => { + const url_1 = '/sub-app-1'; + const url_2 = '/sub-app-2'; + + let add_call_params = { + [url_1]: {installURL: url_1}, + [url_2]: {installURL: url_2}, + }; + + let mocked_response = [ + { "manifestIdPath": url_1, "resultCode": Status.SUCCESS }, + { "manifestIdPath": url_2, "resultCode": Status.SUCCESS } + ]; + + let expected_results = { + [url_1]: "success", + [url_2]: "success", + }; + + + 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..ea4f96124a --- /dev/null +++ b/testing/web-platform/tests/subapps/list-success.tentative.https.html @@ -0,0 +1,58 @@ +<!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 = '/sub-app-1'; + const url_2 = '/sub-app-2'; + + const mocked_response = [ + { "manifestIdPath": url_1, "appName": "App 1" }, + { "manifestIdPath": url_2, "appName": "App 2" }, + ]; + + let expected_results = { + [url_1]: { "app_name": "App 1" }, + [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..a7271905dc --- /dev/null +++ b/testing/web-platform/tests/subapps/remove-error.tentative.https.html @@ -0,0 +1,87 @@ +<!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 => { + const full_url = document.location.origin + '/sub-app-id'; + + await promise_rejects_dom(t, 'NotSupportedError', navigator.subApps.remove([full_url])); +}, 'API supports only root-relative paths.'); + +promise_test(async t => { + const url_1 = '/sub-app-1'; + const url_2 = '/sub-app-2'; + const url_3 = '/sub-app-3'; + + let remove_call_params = [url_1, url_2, url_3]; + + let mocked_response = [ + { "manifestIdPath": url_1, "resultCode": Status.FAILURE }, + { "manifestIdPath": url_2, "resultCode": Status.FAILURE }, + { "manifestIdPath": url_3, "resultCode": Status.FAILURE } + ]; + + let expected_results = { + [url_1]: "failure", + [url_2]: "failure", + [url_3]: "failure" + }; + + await subapps_remove_expect_reject_with_result(t, remove_call_params, mocked_response, expected_results); +}, 'Remove call fails.'); + +promise_test(async t => { + const url_1 = '/sub-app-1'; + const url_2 = '/sub-app-2'; + const url_3 = '/sub-app-3'; + + let remove_call_params = [url_1, url_2, url_3]; + + let mocked_response = [ + { "manifestIdPath": url_1, "resultCode": Status.SUCCESS }, + { "manifestIdPath": url_2, "resultCode": Status.SUCCESS }, + { "manifestIdPath": url_3, "resultCode": Status.FAILURE } + ]; + + let expected_results = { + [url_1]: "success", + [url_2]: "success", + [url_3]: "failure" + }; + + await subapps_remove_expect_reject_with_result(t, remove_call_params, mocked_response, expected_results); +}, 'Remove call fails with mixed results.'); + +</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..ad60d6398d --- /dev/null +++ b/testing/web-platform/tests/subapps/remove-success.tentative.https.html @@ -0,0 +1,41 @@ +<!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> + +promise_test(async t => { + +const url = '/sub-app'; +let remove_call_params = [url]; +let mocked_response = [{ "manifestIdPath": url, "resultCode": Status.SUCCESS }]; +let expected_results = {[url]: "success"}; + +await subapps_remove_expect_success_with_result(t, remove_call_params, mocked_response, expected_results); +}, 'Remove API call works with one app.'); + +promise_test(async t => { + +const url_1 = '/sub-app-1'; +const url_2 = '/sub-app-2'; +const url_3 = '/sub-app-3'; + +let remove_call_params = [url_1, url_2, url_3]; + +let mocked_response = [ + { "manifestIdPath": url_1, "resultCode": Status.SUCCESS }, + { "manifestIdPath": url_2, "resultCode": Status.SUCCESS }, + { "manifestIdPath": url_3, "resultCode": Status.SUCCESS } +]; + +let expected_results = { + [url_1]: "success", + [url_2]: "success", + [url_3]: "success" +}; + +await subapps_remove_expect_success_with_result(t, remove_call_params, mocked_response, expected_results); +}, 'Remove API call works with several apps.'); + +</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..38b8d11466 --- /dev/null +++ b/testing/web-platform/tests/subapps/resources/subapps-helpers.js @@ -0,0 +1,123 @@ +// 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; + +// TODO(crbug.com/1408101): Figure out how to export SubAppsServiceResult (and +// get rid of this). +const Status = { + SUCCESS: 0, + FAILURE: 1, +}; + +async function createMockSubAppsService(service_result_code, add_call_return_value, list_call_return_value, remove_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, remove_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: ", result); + }, + error => { + for (const app_id in expected_results) { + assert_own_property(error, app_id, "Return results are missing entry for subapp.") + assert_equals(error[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.") + } + }); +} + +async function subapps_remove_expect_reject_with_result(t, remove_call_params, mocked_response, expected_results) { + t.add_cleanup(async () => { + await mockSubAppsService.reset(); + mockSubAppsService = null; + }); + + await createMockSubAppsService(Status.FAILURE, [], [], mocked_response); + await navigator.subApps.remove(remove_call_params).then( + result => { + assert_unreached("Should have rejected: ", result); + }, + error => { + for (const app_id in expected_results) { + assert_own_property(error, app_id, "Return results are missing entry for subapp.") + assert_equals(error[app_id], expected_results[app_id], "Return results are not as expected.") + } + }); +} + +async function subapps_remove_expect_success_with_result(t, remove_call_params, mocked_response, expected_results) { + t.add_cleanup(async () => { + await mockSubAppsService.reset(); + mockSubAppsService = null; + }); + + await createMockSubAppsService(Status.SUCCESS, [], [], mocked_response); + await navigator.subApps.remove(remove_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.") + } + }); +} |