tor-browser

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

storage-complex-values.html (3812B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Bug 970517 - Storage inspector front end - tests
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Storage inspector test for correct values in the sidebar</title>
      9 </head>
     10 <body>
     11 <script type="application/javascript">
     12 "use strict";
     13 const partialHostname = location.hostname.match(/^[^.]+(\..*)$/)[1];
     14 const cookieExpiresTime = 2000000000000;
     15 // Setting up some cookies to eat.
     16 document.cookie = "c1=" + JSON.stringify([
     17  "foo", "Bar", {
     18    foo: "Bar"
     19  }]) + "; expires=" + new Date(cookieExpiresTime).toGMTString() +
     20  "; path=/browser";
     21 document.cookie = "cs2=sessionCookie; path=/; domain=" + partialHostname;
     22 // URLEncoded cookie
     23 document.cookie = "c_encoded=" + encodeURIComponent(JSON.stringify({foo: {foo1: "bar"}}));
     24 
     25 // ... and some local storage items ..
     26 const es6 = "for";
     27 localStorage.setItem("ls1", JSON.stringify({
     28  es6, the: "win", baz: [0, 2, 3, {
     29    deep: "down",
     30    nobody: "cares"
     31  }]}));
     32 localStorage.setItem("ls2", "foobar-2");
     33 localStorage.setItem("ls3", "http://foobar.com/baz.php");
     34 localStorage.setItem("ls4", "0x1");
     35 // ... and finally some session storage items too
     36 sessionStorage.setItem("ss1", "This#is#an#array");
     37 sessionStorage.setItem("ss2", "This~is~another~array");
     38 sessionStorage.setItem("ss3", "this#is~an#object~foo#bar");
     39 sessionStorage.setItem("ss4", "#array##with#empty#items");
     40 // long string that is almost an object and might trigger exponential
     41 // regexp backtracking
     42 const s = "a".repeat(1000);
     43 sessionStorage.setItem("ss5", `${s}=${s}=${s}=${s}&${s}=${s}&${s}`);
     44 console.log("added cookies and stuff from main page");
     45 
     46 const idbGenerator = async function () {
     47  let request = indexedDB.open("idb1", 1);
     48  request.onerror = function() {
     49    throw new Error("error opening db connection");
     50  };
     51  const db = await new Promise(done => {
     52    request.onupgradeneeded = event => {
     53      const _db = event.target.result;
     54      const store1 = _db.createObjectStore("obj1", { keyPath: "id" });
     55      store1.createIndex("name", "name", { unique: false });
     56      store1.createIndex("email", "email", { unique: true });
     57      _db.createObjectStore("obj2", { keyPath: "id2" });
     58      store1.transaction.oncomplete = () => {
     59        done(_db);
     60      };
     61    };
     62  });
     63 
     64  // Prevents AbortError
     65  await new Promise(done => {
     66    request.onsuccess = done;
     67  });
     68 
     69  const transaction = db.transaction(["obj1", "obj2"], "readwrite");
     70  const store1 = transaction.objectStore("obj1");
     71  const store2 = transaction.objectStore("obj2");
     72 
     73  store1.add({id: 1, name: "foo", email: "foo@bar.com"});
     74  store1.add({id: 2, name: "foo2", email: "foo2@bar.com"});
     75  store1.add({id: 3, name: "foo2", email: "foo3@bar.com"});
     76  store2.add({
     77    id2: 1,
     78    name: "foo",
     79    email: "foo@bar.com",
     80    extra: "baz".repeat(10000)});
     81 
     82  db.close();
     83 
     84  request = indexedDB.open("idb2", 1);
     85  const db2 = await new Promise(done => {
     86    request.onupgradeneeded = event => {
     87      const _db2 = event.target.result;
     88      const store3 = _db2.createObjectStore("obj3", { keyPath: "id3" });
     89      store3.createIndex("name2", "name2", { unique: true });
     90      store3.transaction.oncomplete = () => {
     91        done(_db2);
     92      };
     93    };
     94  });
     95 
     96  // Prevents AbortError during close()
     97  await new Promise(done => {
     98    request.onsuccess = done;
     99  });
    100 
    101  db2.close();
    102  console.log("added cookies and stuff from main page");
    103 };
    104 
    105 function deleteDB(dbName) {
    106  return new Promise(resolve => {
    107    dump("removing database " + dbName + " from " + document.location + "\n");
    108    indexedDB.deleteDatabase(dbName).onsuccess = resolve;
    109  });
    110 }
    111 
    112 window.setup = async function () {
    113  await idbGenerator();
    114 };
    115 
    116 window.clear = async function () {
    117  await deleteDB("idb1");
    118  await deleteDB("idb2");
    119 
    120  dump("removed indexedDB data from " + document.location + "\n");
    121 };
    122 </script>
    123 </body>
    124 </html>