tor-browser

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

detached.https.window.js (4720B)


      1 // META: script=/common/get-host-info.sub.js
      2 // META: script=./resources/checker.js
      3 // META: script=./resources/common.js
      4 // META: timeout=long
      5 'use strict';
      6 
      7 
      8 promise_test(async testCase => {
      9  assert_true(self.crossOriginIsolated);
     10 
     11  const {iframes, windows} = await build([
     12    {
     13      id: 'cross-site-1',
     14      children: [
     15        {
     16          id: 'same-origin-2',
     17        },
     18        {
     19          id: 'same-origin-11',
     20          window_open: true,
     21        },
     22      ],
     23    },
     24    {
     25      id: 'same-origin-3',
     26      children: [
     27        {
     28          id: 'same-origin-4',
     29        },
     30        {
     31          id: 'same-origin-12',
     32          window_open: true,
     33        },
     34      ],
     35    },
     36    {
     37      id: 'cross-origin-5',
     38      children: [
     39        {
     40          id: 'same-origin-6',
     41        },
     42        {
     43          id: 'same-origin-13',
     44          window_open: true,
     45        },
     46      ],
     47    },
     48    {
     49      id: 'same-origin-7',
     50      window_open: true,
     51      children: [
     52        {
     53          id: 'same-origin-8',
     54        }
     55      ],
     56    },
     57    {
     58      id: 'cross-origin-9',
     59      window_open: true,
     60      children: [
     61        {
     62          id: 'same-origin-10',
     63        }
     64      ],
     65    },
     66  ]);
     67  const expected = [
     68    {
     69      url: window.location.href,
     70      scope: 'Window',
     71      container: null,
     72    },
     73    {
     74      url: 'cross-origin-url',
     75      scope: 'cross-origin-aggregated',
     76      container: {
     77        id: 'cross-site-1',
     78        src: iframes['cross-site-1'].src,
     79      },
     80    },
     81    {
     82      url: windows['same-origin-2'].location.href,
     83      scope: 'Window',
     84      container: {
     85        id: 'cross-site-1',
     86        src: iframes['cross-site-1'].src,
     87      },
     88    },
     89    {
     90      url: windows['same-origin-3'].location.href,
     91      scope: 'Window',
     92      container: {
     93        id: 'same-origin-3',
     94        src: iframes['same-origin-3'].src,
     95      },
     96    },
     97    {
     98      url: windows['same-origin-4'].location.href,
     99      scope: 'Window',
    100      container: {
    101        id: 'same-origin-4',
    102        src: iframes['same-origin-4'].src,
    103      },
    104    },
    105    {
    106      url: 'cross-origin-url',
    107      scope: 'cross-origin-aggregated',
    108      container: {
    109        id: 'cross-origin-5',
    110        src: iframes['cross-origin-5'].src,
    111      },
    112    },
    113    {
    114      url: windows['same-origin-6'].location.href,
    115      scope: 'Window',
    116      container: {
    117        id: 'cross-origin-5',
    118        src: iframes['cross-origin-5'].src,
    119      },
    120    },
    121    {
    122      url: windows['same-origin-8'].location.href,
    123      scope: 'Window',
    124      container: {
    125        id: 'same-origin-8',
    126        src: iframes['same-origin-8'].src,
    127      },
    128    },
    129    {
    130      url: windows['same-origin-7'].location.href,
    131      scope: 'Window',
    132      container: null,
    133    },
    134    {
    135      url: windows['same-origin-11'].location.href,
    136      scope: 'Window',
    137      container: null,
    138    },
    139    {
    140      url: windows['same-origin-12'].location.href,
    141      scope: 'Window',
    142      container: null,
    143    },
    144    {
    145      url: windows['same-origin-13'].location.href,
    146      scope: 'Window',
    147      container: null,
    148    },
    149  ];
    150  const keep = sameOriginContexts(frames).concat(sameOriginContexts(windows));
    151  // Detach iframes:
    152  // 1) By setting src attribute:
    153  iframes['cross-site-1'].src =
    154      iframes['cross-site-1'].src.replace('iframe.sub', 'iframe.secret.sub');
    155  // 2) By setting location attribute:
    156  let url = iframes['same-origin-3'].contentWindow.location.href;
    157  url = url.replace('iframe.sub', 'iframe.secret.sub');
    158  iframes['same-origin-3'].contentWindow.location.href = url;
    159  // 3) By removing from the DOM tree:
    160  iframes['cross-origin-5'].parentNode.removeChild(iframes['cross-origin-5']);
    161 
    162  // Detach windows:
    163  // 1) By setting document.location attribute:
    164  url = windows['same-origin-7'].location.href;
    165  url = url.replace('window.sub', 'window.secret.sub');
    166  windows['same-origin-7'].location.href = url;
    167  // 2) By closing the window:
    168  windows['same-origin-10'].parent.close();
    169 
    170  await waitForMessage('cross-site-1');
    171  await waitForMessage('same-origin-3');
    172  await waitForMessage('same-origin-7');
    173 
    174  expected.push({
    175    url: 'cross-origin-url',
    176    scope: 'cross-origin-aggregated',
    177    container: {
    178      id: 'cross-site-1',
    179      src: iframes['cross-site-1'].src,
    180    },
    181  });
    182 
    183  expected.push({
    184    url: windows['same-origin-3'].location.href,
    185    scope: 'Window',
    186    container: {
    187      id: 'same-origin-3',
    188      src: iframes['same-origin-3'].src,
    189    },
    190  });
    191  expected.push({
    192    url: windows['same-origin-7'].location.href,
    193    scope: 'Window',
    194    container: null,
    195  });
    196  const result = await performance.measureUserAgentSpecificMemory();
    197  checkMeasureMemory(result, expected);
    198 }, 'performance.measureUserAgentSpecificMemory URLs within a cross-site iframe.');