tor-browser

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

yield-scripted-subframe-propagation.html (4095B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 
      5 <script>
      6  async function getResultsInOrder(promises) {
      7    const results = [];
      8    const tasks = promises.map(p => p.then(r => results.push(r)));
      9    await Promise.all(tasks);
     10    return results;
     11  }
     12 
     13  promise_test(async t => {
     14    await new Promise(resolve => window.onload = resolve);
     15    const iframe = document.createElement('iframe');
     16    iframe.srcdoc = `
     17      <script>
     18        window.task = async function() {
     19          await scheduler.yield();
     20          return "inner";
     21        }
     22 
     23        window.task2 = async function(callback) {
     24          Promise.resolve().then(callback);
     25        }
     26      </scr`+`ipt>
     27    `;
     28 
     29    window.parentTask = async function() {
     30      await scheduler.yield();
     31      return "inner";
     32    };
     33 
     34    const p = new Promise(resolve => iframe.onload = resolve);
     35    document.body.appendChild(iframe);
     36    await p;
     37 
     38    // task1: user-blocking, main frame scheduler, child frame task.
     39    //   task 1 continuation: child frame yield().
     40    // task2: user-blocking, main frame scheduler, main frame task.
     41    //
     42    // Expected: no inheritance, task1 continuation has default continuation
     43    // priority and runs last.
     44    let task1 = scheduler.postTask(
     45        iframe.contentWindow.task, {priority: 'user-blocking'});
     46    let task2 = scheduler.postTask(() => "outer", {priority: 'user-blocking'});
     47    let result = await getResultsInOrder([task1, task2]);
     48    assert_equals(result.toString(), "outer,inner",
     49        "Expected outer before inner for iframe task with main frame scheduler");
     50 
     51    // task1: user-blocking, child frame scheduler, child frame task.
     52    //   task 1 continuation: child frame yield().
     53    // task2: user-blocking, main frame scheduler, main frame task.
     54    //
     55    // Expected: continuation inherits user-blocking priority and runs before
     56    // task2.
     57    task1 = iframe.contentWindow.scheduler.postTask(
     58        iframe.contentWindow.task, {priority: 'user-blocking'});
     59    task2 = scheduler.postTask(() => "outer", {priority: 'user-blocking'});
     60    result = await getResultsInOrder([task1, task2]);
     61    assert_equals(result.toString(), "inner,outer",
     62        "Expected inner before outer for iframe task with iframe scheduler");
     63 
     64    // task1: user-blocking, main frame scheduler, main frame task.
     65    //   task 1 continuation: child frame yield() called from main frame task.
     66    // task2: user-blocking, main frame scheduler, main frame task.
     67    //
     68    // Expected: no inheritance, task1 continuation has default continuation
     69    // priority and runs last.
     70    task1 = scheduler.postTask(
     71        async () => await iframe.contentWindow.task(), {priority: 'user-blocking'});
     72    task2 = scheduler.postTask(() => "outer", {priority: 'user-blocking'});
     73    result = await getResultsInOrder([task1, task2]);
     74    assert_equals(result.toString(), "outer,inner",
     75        "Expected outer before inner for iframe task called from main frame task");
     76 
     77    // This tests that priority is inherited in the main frame if hopping
     78    // through a child frame task.
     79    //
     80    // task1: user-blocking; main frame scheduler; main frame task, which calls
     81    //        back into the main frame in a microtask.
     82    //   task 1 continuation: main frame yield, called from child frame.
     83    // task2: user-blocking, main frame scheduler, main frame task.
     84    //
     85    // Expected: continuation inherits user-blocking priority and runs before
     86    // task2.
     87    task1 = scheduler.postTask(() => new Promise(resolve => {
     88      iframe.contentWindow.task2(async () => {
     89        await scheduler.yield();
     90        resolve("inner");
     91      });
     92    }), {priority: 'user-blocking'});
     93    task2 = scheduler.postTask(() => "outer", {priority: 'user-blocking'});
     94    result = await getResultsInOrder([task1, task2]);
     95    assert_equals(result.toString(), "inner,outer",
     96        "Expected inner before outer for iframe task calling back to main frame task");
     97  }, 'Test scheduler.yield() does not use propagated state in same origin frames');
     98 </script>