summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/infrastructure/testdriver/bless.html
blob: 12257df01b7193c2a70bde1bedaa8e1d7e1ff2f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <title>TestDriver bless method</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/resources/testdriver.js"></script>
  <script src="/resources/testdriver-vendor.js"></script>
  <script>
promise_test(() => {
  return test_driver.bless('empty', () => {});
}, 'functions in the absence of a `body` element');
  </script>
</head>
<body>
<script>
// At the time of this writing, the only standard requirement for user
// activation concerns the interaction between iframe elements and their parent
// browsing contexts [1]. Because testdriver.js currently cannot operate within
// an iframe, the standard requirement cannot be used to verify the correctness
// of the `bless` method. Instead, rely on the optional behavior of early exit
// and rejecting in `video.play()` if the media is not "allowed to play". [2]
// Browsers which don't implement this will pass this test spuriously.
//
// [1] https://html.spec.whatwg.org/multipage/origin.html#attr-iframe-sandbox-allow-top-navigation-by-user-activation
// [2] https://html.spec.whatwg.org/multipage/media.html#allowed-to-play
promise_test(t => {
  const video = document.createElement('video');
  document.body.appendChild(video);
  t.add_cleanup(() => video.remove());
  return test_driver.bless('start video playback', () => {
    // `paused` changes before `play()` returns when "allowed to play", so the
    // promise, if any, is ignored.
    assert_true(video.paused);
    const playPromise = video.play();
    assert_false(video.paused);
    if (playPromise) {
      playPromise.catch(() => {});
    }
  });
}, 'user activation');

promise_test(() => {
  return test_driver.bless('demonstrates return value without action')
    .then((value) => {
      assert_equals(value, null);
    });
}, 'no action function provided');

promise_test(() => {
  const expectedValue = {};

  return test_driver.bless('demonstrate a synchronous return value', () => {
      return expectedValue;
    }).then((actualValue) => {
      assert_equals(
        actualValue,
        expectedValue,
        'the promise should be fulfilled with the returned value'
      );
    });

}, 'synchronous return value');

promise_test(() => {
  const expectedError = new Error();

  return test_driver.bless('demonstrates a synchronous error', () => {
     throw expectedError;
    })
    .then(() => {
      assert_unreached('the promise should be rejected');
    }, (actualError) => {
      assert_equals(
        actualError,
        expectedError,
        'the promise should be rejected with the thrown value'
      );
    });
}, 'synchronous error');

promise_test(() => {
  const expectedValue = {};

  return test_driver.bless('demonstrate an asynchronous return value', () => {
      return Promise.resolve(expectedValue);
    }).then((actualValue) => {
      assert_equals(
        actualValue,
        expectedValue,
        'the promise should be fulfilled with the fulfillment value'
      );
    });

}, 'asynchronous return value');

promise_test(() => {
  const expectedError = new Error();

  return test_driver.bless('demonstrates an asynchronous error', () => {
     return Promise.reject(expectedError);
    })
    .then(() => {
      assert_unreached('the promise should be rejected');
    }, (actualError) => {
      assert_equals(
        actualError,
        expectedError,
        'the promise should be rejected with the rejected value'
      );
    });
}, 'asynchronous error');
</script>
</body>