Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: LayoutTests/app_banner/app-banner-event-prompt.html

Issue 1202043002: Adding tests for the prompt() method on the beforeinstallprompt event (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressing reviewer comments and adding additional test Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/app_banner/app-banner-event-prompt.html
diff --git a/LayoutTests/app_banner/app-banner-event-prompt.html b/LayoutTests/app_banner/app-banner-event-prompt.html
new file mode 100644
index 0000000000000000000000000000000000000000..b5edae164c381abd3475a70c2f4f61f631bfeee5
--- /dev/null
+++ b/LayoutTests/app_banner/app-banner-event-prompt.html
@@ -0,0 +1,133 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script>
+
+var prompt_test_cases = [
+ {
+ name: 'prompt-accept',
+ cancel: true,
+ late: false,
+ platform: 'foo',
+ outcome: 'accepted'
+ }, {
+ name: 'prompt-dismiss',
+ cancel: true,
+ late: false,
+ platform: '',
+ outcome: 'dismissed'
+ }, {
+ name: 'prompt-before-preventDefault',
+ cancel: false,
+ late: false,
+ platform: 'foo',
+ outcome: 'accepted'
+ }, {
+ name: 'prompt-late-accept',
+ cancel: true,
+ late: true,
+ platform: 'foo',
+ outcome: 'accepted'
+ }, {
+ name: 'prompt-late-dismiss',
+ cancel: true,
+ late: true,
+ platform: '',
+ outcome: 'dismissed'
+ }, {
+ name: 'prompt-late-without-preventDefault',
+ cancel: false,
+ late: true,
+ platform: '',
+ outcome: 'dismissed'
+ }
+];
+
+function verify_prompt_resolve(e, t) {
+ e.prompt().then(function() { }, t.unreached_func("prompt() promise should resolve."));
+}
+
+function verify_prompt_reject(e, t) {
+ e.prompt().then(t.unreached_func("prompt() promise should reject."),
+ t.step_func(function(error) {
+ assert_true(
+ error instanceof DOMException,
+ "Rejected promise should throw a DOMException."
+ );
+ assert_equals(
+ error.message,
+ "The prompt() method may only be called once, following preventDefault().",
+ "Rejected promise does not provide expected message."
+ );
+ })
+ );
+}
+
+function verify_userChoice(e, t, test_case, index) {
+ e.userChoice.then(t.step_func(function(result) {
+ assert_equals(result.platform, test_case.platform, 'Resolved platform');
+ assert_equals(result.outcome, test_case.outcome, 'Outcome');
+ })).then(t.step_func(function() {
+ verify_prompt_reject(e, t);
+ })).then(t.step_func(function() {
+ prompt_test(index + 1);
+ t.done();
+ }), t.unreached_func("userChoice promise should resolve."));
+}
+
+function prompt_test(index) {
+ if (index >= prompt_test_cases.length)
+ return;
+
+ var test_case = prompt_test_cases[index];
+ async_test(function(t) {
+ var event = null;
+ var event_handler = t.step_func(function(e) {
+ // Remove the event handler to prevent it being used in subsequent
+ // invocations of prompt_test(). Save event object for call outside handler.
+ window.removeEventListener('beforeinstallprompt', event_handler);
+ event = e;
+
+ assert_equals(e.platforms.length, 2, 'Number of platforms');
+ assert_equals(e.platforms[0], 'foo', 'First platform');
+ assert_equals(e.platforms[1], 'bar', 'Second platform');
+
+ if (test_case.late) {
+ return;
+ }
+
+ if (test_case.cancel) {
+ // Cancel the event, then call prompt() to restart the display pipeline.
+ e.preventDefault();
+ verify_prompt_resolve(e, t);
+ } else {
+ // A call to prompt() before preventDefault should reject.
+ verify_prompt_reject(e, t);
+ }
+
+ // prompt() has been fired or the event has not been canceled, so check
+ // the userChoice promise and call the next test.
+ verify_userChoice(e, t, test_case, index);
+ });
+ window.addEventListener('beforeinstallprompt', event_handler);
+
+ testRunner.dispatchBeforeInstallPromptEvent(index, ['foo', 'bar'], t.step_func(function(result) {
+ testRunner.resolveBeforeInstallPromptPromise(index, test_case.platform);
+ }));
+
+ // Test that firing prompt() outside of the handler resolves or rejects correctly.
+ if (test_case.late) {
+ if (test_case.cancel) {
+ event.preventDefault();
+ verify_prompt_resolve(event, t);
+ } else {
+ verify_prompt_reject(event, t);
+ }
+ // Check userChoice and call the next test.
+ verify_userChoice(event, t, test_case, index);
+ }
+ }, test_case.name);
+}
+
+prompt_test(0);
+</script>
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698