tor-browser

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

domparts-utils.js (1814B)


      1 function assertEqualParts(parts,partDescriptions,expectedParts,description) {
      2  assert_equals(parts.length,partDescriptions.length,`${description}: lengths differ`);
      3  let nodePartIndx = 0, childNodePartIndx = 0;
      4  for(let i=0;i<parts.length;++i) {
      5    assert_true(parts[i] instanceof Part,`${description}: not a Part`);
      6    assert_true(parts[i] instanceof window[partDescriptions[i].type],`${description}: index ${i} expected ${partDescriptions[i].type}`);
      7    // TODO(crbug.com/40271855): While developing alternative syntax, we aren't comparing the metadata:
      8    // assert_array_equals(parts[i].metadata,partDescriptions[i].metadata,`${description}: index ${i} wrong metadata`);
      9    if (expectedParts) {
     10      // TODO(crbug.com/40271855): While developing alternative syntax, we aren't comparing equality of the Part objects:
     11      // assert_equals(parts[i],expectedParts[i],`${description}: index ${i} object equality`);
     12      if ('getNodePartNodes' in parts[i].root) {
     13        switch (partDescriptions[i].type) {
     14          case 'NodePart':
     15            assert_equals(parts[i].root.getNodePartNodes()[nodePartIndx],parts[i].node,`getNodePartNodes() indx ${nodePartIndx} should match node from NodePart`);
     16            nodePartIndx++;
     17            break;
     18          case 'ChildNodePart':
     19            assert_equals(parts[i].root.getChildNodePartNodes()[childNodePartIndx],parts[i].previousSibling,`getChildNodePartNodes() indx ${childNodePartIndx} should match previousSibling from ChildNodePart`);
     20            childNodePartIndx++;
     21            assert_equals(parts[i].root.getChildNodePartNodes()[childNodePartIndx],parts[i].nextSibling,`getChildNodePartNodes() indx ${childNodePartIndx} should match nextSibling from ChildNodePart`);
     22            childNodePartIndx++;
     23            break;
     24        }
     25      }
     26    }
     27  }
     28 }