chromium/third_party/blink/web_tests/app_banner/before-install-prompt-event-constructor.html

<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>

test(function() {
    assert_false(new BeforeInstallPromptEvent('eventType').bubbles, 'bubbles');
    assert_false(new BeforeInstallPromptEvent('eventType').cancelable, 'cancelable');
}, 'No initializer passed');

test(function() {
    assert_true(new BeforeInstallPromptEvent('eventType', { bubbles: true } ).bubbles, 'bubbles');
    assert_true(new BeforeInstallPromptEvent('eventType', { cancelable: true } ).cancelable, 'cancelable');
}, 'Initializer values not respected');

test(function() {
    var event = new BeforeInstallPromptEvent('eventType', { platforms: ['a'] });
    assert_array_equals(['a'], event.platforms, 'platforms');
}, 'platforms is passed');

test(function() {
    var event = new BeforeInstallPromptEvent('eventType', { platforms: ['a'] });
    event.preventDefault();
}, 'preventDefault called');

async_test(function(t) {
    var event = new BeforeInstallPromptEvent('eventType', { platforms: ['a'] });
    var thrown = false;
    var rejected = false;
    event.prompt()
        .then(t.unreached_func('prompt() should not resolve'), function(){
            rejected = true;
        })
        .catch(function(reason) { thrown = true; });
    t.done();

    assert_true(rejected);
    assert_true(thrown);
}, 'prompt() called and rejected');

async_test(function(t) {
    var event = new BeforeInstallPromptEvent('eventType', { platforms: ['a'] });
    var thrown = false;
    var rejected = false;
    event.userChoice
        .then(t.unreached_func('userChoice should not resolve'), function(){
            rejected = true;
        })
        .catch(function(reason) { thrown = true; });
    t.done();

    assert_true(rejected);
    assert_true(thrown);
}, 'userChoice accessed, throws and rejects');
</script>