tor-browser

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

test-helper.js (1552B)


      1 async function assertSimplestScriptRuns(remoteContextWrapper) {
      2  assert_equals(
      3      await remoteContextWrapper.executeScript(() => {
      4        return 1;
      5      }),
      6      1, 'simplest script runs');
      7 }
      8 
      9 async function assertFunctionRuns(
     10    remoteContextWrapper, functionToRun, expectedReturn) {
     11  assert_equals(
     12      await remoteContextWrapper.executeScript(functionToRun), expectedReturn,
     13      'function runs');
     14 }
     15 
     16 async function assertOriginIsAsExpected(remoteContextWrapper, expectedOrigin) {
     17  assert_equals(
     18      await remoteContextWrapper.executeScript(() => {
     19        return location.origin;
     20      }),
     21      expectedOrigin, 'verify origin');
     22 }
     23 
     24 async function assertWindowNameEquals(remoteContextWrapper, expectedName) {
     25  assert_equals(
     26      await remoteContextWrapper.executeScript(() => {
     27        return window.name;
     28      }),
     29      expectedName, 'verify name');
     30 }
     31 
     32 async function assertWindowHasOpenerEquals(remoteContextWrapper, hasParent) {
     33  assert_equals(
     34      await remoteContextWrapper.executeScript(() => {
     35        return !!window.opener;
     36      }),
     37      hasParent, 'verify opener');
     38 }
     39 
     40 async function assertHeaderIsAsExpected(
     41    remoteContextWrapper, headerName, headerValue) {
     42  assert_equals(
     43      headerValue,
     44      await remoteContextWrapper.executeScript(async (headerName) => {
     45        const res = await fetch(location);
     46        return res.headers.get(headerName);
     47      }, [headerName]), 'header is set');
     48 }
     49 
     50 function getUrlType(location) {
     51  const url = new URL(location);
     52  return url.searchParams.get('urlType');
     53 }