tor-browser

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

browser_storage_dynamic_updates_cookies.js (6043B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
      8 
      9 registerCleanupFunction(() => {
     10  Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
     11 });
     12 
     13 // Test dynamic updates in the storage inspector for cookies.
     14 
     15 add_task(async function () {
     16  await openTabAndSetupStorage(MAIN_DOMAIN_SECURED + "storage-updates.html");
     17 
     18  gUI.tree.expandAll();
     19 
     20  ok(gUI.sidebar.hidden, "Sidebar is initially hidden");
     21  const c1id = getCookieId("c1", "test1.example.org", "/browser");
     22  await selectTableItem(c1id);
     23 
     24  // test that value is something initially
     25  const initialValue = [
     26    [
     27      { name: "c1", value: "1.2.3.4.5.6.7" },
     28      { name: "c1.Path", value: "/browser" },
     29    ],
     30    [
     31      { name: "c1", value: "Array" },
     32      { name: "c1.0", value: "1" },
     33      { name: "c1.6", value: "7" },
     34    ],
     35  ];
     36 
     37  // test that value is something initially
     38  const finalValue = [
     39    [
     40      { name: "c1", value: '{"foo": 4,"bar":6}' },
     41      { name: "c1.Path", value: "/browser" },
     42    ],
     43    [
     44      { name: "c1", value: "Object" },
     45      { name: "c1.foo", value: "4" },
     46      { name: "c1.bar", value: "6" },
     47    ],
     48  ];
     49 
     50  // Check that sidebar shows correct initial value
     51  await findVariableViewProperties(initialValue[0], false);
     52 
     53  await findVariableViewProperties(initialValue[1], true);
     54 
     55  // Check if table shows correct initial value
     56  await checkState([
     57    [
     58      ["cookies", "https://test1.example.org"],
     59      [
     60        getCookieId("c1", "test1.example.org", "/browser"),
     61        getCookieId("c2", "test1.example.org", "/browser"),
     62      ],
     63    ],
     64  ]);
     65  checkCell(c1id, "value", "1.2.3.4.5.6.7");
     66 
     67  await addCookie("c1", '{"foo": 4,"bar":6}', "/browser");
     68  await gUI.once("store-objects-edit");
     69 
     70  await findVariableViewProperties(finalValue[0], false);
     71  await findVariableViewProperties(finalValue[1], true);
     72 
     73  await checkState([
     74    [
     75      ["cookies", "https://test1.example.org"],
     76      [
     77        getCookieId("c1", "test1.example.org", "/browser"),
     78        getCookieId("c2", "test1.example.org", "/browser"),
     79      ],
     80    ],
     81  ]);
     82  checkCell(c1id, "value", '{"foo": 4,"bar":6}');
     83 
     84  // Add a new entry
     85  await addCookie("c3", "booyeah");
     86 
     87  await gUI.once("store-objects-edit");
     88 
     89  await checkState([
     90    [
     91      ["cookies", "https://test1.example.org"],
     92      [
     93        getCookieId("c1", "test1.example.org", "/browser"),
     94        getCookieId("c2", "test1.example.org", "/browser"),
     95        getCookieId(
     96          "c3",
     97          "test1.example.org",
     98          "/browser/devtools/client/storage/test"
     99        ),
    100      ],
    101    ],
    102  ]);
    103  const c3id = getCookieId(
    104    "c3",
    105    "test1.example.org",
    106    "/browser/devtools/client/storage/test"
    107  );
    108  checkCell(c3id, "value", "booyeah");
    109 
    110  // Add another
    111  await addCookie("c4", "booyeah");
    112 
    113  await gUI.once("store-objects-edit");
    114 
    115  await checkState([
    116    [
    117      ["cookies", "https://test1.example.org"],
    118      [
    119        getCookieId("c1", "test1.example.org", "/browser"),
    120        getCookieId("c2", "test1.example.org", "/browser"),
    121        getCookieId(
    122          "c3",
    123          "test1.example.org",
    124          "/browser/devtools/client/storage/test"
    125        ),
    126        getCookieId(
    127          "c4",
    128          "test1.example.org",
    129          "/browser/devtools/client/storage/test"
    130        ),
    131      ],
    132    ],
    133  ]);
    134  const c4id = getCookieId(
    135    "c4",
    136    "test1.example.org",
    137    "/browser/devtools/client/storage/test"
    138  );
    139  checkCell(c4id, "value", "booyeah");
    140 
    141  // Removing cookies
    142  await removeCookie("c1", "/browser");
    143 
    144  await gUI.once("store-objects-edit");
    145 
    146  await checkState([
    147    [
    148      ["cookies", "https://test1.example.org"],
    149      [
    150        getCookieId("c2", "test1.example.org", "/browser"),
    151        getCookieId(
    152          "c3",
    153          "test1.example.org",
    154          "/browser/devtools/client/storage/test"
    155        ),
    156        getCookieId(
    157          "c4",
    158          "test1.example.org",
    159          "/browser/devtools/client/storage/test"
    160        ),
    161      ],
    162    ],
    163  ]);
    164 
    165  ok(!gUI.sidebar.hidden, "Sidebar still visible for next row");
    166 
    167  // Check if next element's value is visible in sidebar
    168  await findVariableViewProperties([{ name: "c2", value: "foobar" }]);
    169 
    170  // Keep deleting till no rows
    171  await removeCookie("c3");
    172 
    173  await gUI.once("store-objects-edit");
    174 
    175  await checkState([
    176    [
    177      ["cookies", "https://test1.example.org"],
    178      [
    179        getCookieId("c2", "test1.example.org", "/browser"),
    180        getCookieId(
    181          "c4",
    182          "test1.example.org",
    183          "/browser/devtools/client/storage/test"
    184        ),
    185      ],
    186    ],
    187  ]);
    188 
    189  // Check if next element's value is visible in sidebar
    190  await findVariableViewProperties([{ name: "c2", value: "foobar" }]);
    191 
    192  await removeCookie("c2", "/browser");
    193 
    194  await gUI.once("store-objects-edit");
    195 
    196  await checkState([
    197    [
    198      ["cookies", "https://test1.example.org"],
    199      [
    200        getCookieId(
    201          "c4",
    202          "test1.example.org",
    203          "/browser/devtools/client/storage/test"
    204        ),
    205      ],
    206    ],
    207  ]);
    208 
    209  // Check if next element's value is visible in sidebar
    210  await findVariableViewProperties([{ name: "c4", value: "booyeah" }]);
    211 
    212  await removeCookie("c4");
    213 
    214  await gUI.once("store-objects-edit");
    215 
    216  await checkState([[["cookies", "https://test1.example.org"], []]]);
    217 
    218  ok(gUI.sidebar.hidden, "Sidebar is hidden when no rows");
    219 });
    220 
    221 async function addCookie(name, value, path) {
    222  await SpecialPowers.spawn(
    223    gBrowser.selectedBrowser,
    224    [[name, value, path]],
    225    ([nam, valu, pat]) => {
    226      content.wrappedJSObject.addCookie(nam, valu, pat);
    227    }
    228  );
    229 }
    230 
    231 async function removeCookie(name, path) {
    232  await SpecialPowers.spawn(
    233    gBrowser.selectedBrowser,
    234    [[name, path]],
    235    ([nam, pat]) => {
    236      content.wrappedJSObject.removeCookie(nam, pat);
    237    }
    238  );
    239 }