tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bless.html (3584B)


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