tor-browser

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

test_WeakMapMap.js (1862B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test WeakMapMap.
      5 
      6 "use strict";
      7 
      8 const WeakMapMap = require("resource://devtools/client/shared/WeakMapMap.js");
      9 
     10 const myWeakMapMap = new WeakMapMap();
     11 const key = { randomObject: true };
     12 
     13 // eslint-disable-next-line
     14 function run_test() {
     15  test_set();
     16  test_has();
     17  test_get();
     18  test_delete();
     19  test_clear();
     20 }
     21 
     22 function test_set() {
     23  // myWeakMapMap.set
     24  myWeakMapMap.set(key, "text1", "value1");
     25  myWeakMapMap.set(key, "text2", "value2");
     26  myWeakMapMap.set(key, "text3", "value3");
     27 }
     28 
     29 function test_has() {
     30  // myWeakMapMap.has
     31  ok(myWeakMapMap.has(key, "text1"), "text1 exists");
     32  ok(myWeakMapMap.has(key, "text2"), "text2 exists");
     33  ok(myWeakMapMap.has(key, "text3"), "text3 exists");
     34  ok(!myWeakMapMap.has(key, "notakey"), "notakey does not exist");
     35 }
     36 
     37 function test_get() {
     38  // myWeakMapMap.get
     39  const value1 = myWeakMapMap.get(key, "text1");
     40  equal(value1, "value1", "test value1");
     41 
     42  const value2 = myWeakMapMap.get(key, "text2");
     43  equal(value2, "value2", "test value2");
     44 
     45  const value3 = myWeakMapMap.get(key, "text3");
     46  equal(value3, "value3", "test value3");
     47 
     48  const value4 = myWeakMapMap.get(key, "notakey");
     49  equal(value4, undefined, "test value4");
     50 }
     51 
     52 function test_delete() {
     53  // myWeakMapMap.delete
     54  myWeakMapMap.delete(key, "text2");
     55 
     56  // Check that the correct entry was deleted
     57  ok(myWeakMapMap.has(key, "text1"), "text1 exists");
     58  ok(!myWeakMapMap.has(key, "text2"), "text2 no longer exists");
     59  ok(myWeakMapMap.has(key, "text3"), "text3 exists");
     60 }
     61 
     62 function test_clear() {
     63  // myWeakMapMap.clear
     64  myWeakMapMap.clear();
     65 
     66  // Ensure myWeakMapMap was properly cleared
     67  ok(!myWeakMapMap.has(key, "text1"), "text1 no longer exists");
     68  ok(!myWeakMapMap.has(key, "text3"), "text3 no longer exists");
     69 }