tor-browser

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

test_pushState_structuredclone.html (1950B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8" />
      5  <title>history.pushState with serializable objects in state</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10 <p id="display"></p>
     11 <script>
     12  add_task(async function test() {
     13    let state = {
     14      b: new Blob(['1234567890']),
     15      // CryptoKey
     16      k: await crypto.subtle.generateKey({ name: "HMAC", length: 256, hash: {name: "SHA-256"} }, true, ["sign", "verify"]),
     17      mr: new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]),
     18      m: new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
     19      pr: new DOMPointReadOnly(1, 2, 3, 4),
     20      p: new DOMPoint(4, 3, 2, 1),
     21      q: new DOMQuad(new DOMRectReadOnly(1, 2, 3, 4)),
     22      rr: new DOMRectReadOnly(1, 2, 3, 4),
     23      r: new DOMRect(1, 2, 3, 4),
     24      f: new File(['9876543210'], ''),
     25      i: new ImageData(4, 4),
     26      // RTCCertificate
     27      c: await RTCPeerConnection.generateCertificate({ name: 'ECDSA', namedCurve: 'P-256' }),
     28    };
     29 
     30    history.pushState(state, "", "?withState");
     31    ok(history.state instanceof Object,
     32       "pushState with an object should set history.state.");
     33    SimpleTest.isDeeply(history.state, state,
     34                        "Check that history.state retains all serializable fields.");
     35 
     36    history.pushState(undefined, "", "?withoutState");
     37    let promisePoppedState = new Promise(resolve => {
     38      window.addEventListener('popstate', event => {
     39        resolve(event.state);
     40      }, { once: true });
     41    });
     42    history.back();
     43    let poppedState = await promisePoppedState;
     44    ok(poppedState instanceof Object,
     45       "Going back from pushState with an object should return an object in the popstate event.");
     46    SimpleTest.isDeeply(poppedState, state,
     47                        "Check that going back from pushState retains all serializable fields.");
     48  });
     49 </script>
     50 </body>
     51 </html>