tor-browser

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

include-frames-helper.js (1658B)


      1 const verifyEntries = (entries, filterOptions) => {
      2  for (const filterOption of filterOptions) {
      3    let countBeforeFiltering = entries.length;
      4 
      5    // Using negate of the condition so that the next filtering is applied on less entries.
      6    entries = entries.filter(
      7      e => !(e.entryType == filterOption['entryType'] && e.name.includes(filterOption['name'])));
      8 
      9    assert_equals(
     10      countBeforeFiltering - entries.length, filterOption['expectedCount'], filterOption['failureMsg']);
     11  }
     12 }
     13 
     14 const createFilterOption = (name, entryType, expectedCount, msgPrefix, description = '') => {
     15  if (description) {
     16    description = ' ' + description;
     17  }
     18 
     19  let failureMsg =
     20    `${msgPrefix} should have ${expectedCount} ${entryType} entries for name ${name}` + description;
     21 
     22  return {
     23    name: name,
     24    entryType: entryType,
     25    expectedCount: expectedCount,
     26    failureMsg: failureMsg
     27  };
     28 }
     29 
     30 const loadChildFrame = (src) => {
     31  return new Promise(resolve => {
     32 
     33    const childFrame = document.createElement('iframe');
     34 
     35    childFrame.addEventListener("load", resolve);
     36 
     37    childFrame.src = src;
     38 
     39    document.body.appendChild(childFrame);
     40  });
     41 }
     42 
     43 const loadChildFrameAndGrandchildFrame = (src) => {
     44  return new Promise(resolve => {
     45 
     46    const crossOriginChildFrame = document.createElement('iframe');
     47 
     48    // Wait for the child frame to send a message. The child frame would send a message
     49    // when it loads its child frame.
     50    window.addEventListener('message', e => {
     51      if (e.data == 'Load completed') {
     52        resolve();
     53      }
     54    });
     55 
     56    crossOriginChildFrame.src = src;
     57 
     58    document.body.appendChild(crossOriginChildFrame)
     59  });
     60 }