tor-browser

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

open-features-negative-width-height.html (3166B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>HTML: window.open `features`: negative values for `width`, `height`</title>
      4 <meta name=timeout content=long>
      5 <link rel="help" href="https://html.spec.whatwg.org/multipage/#apis-for-creating-and-navigating-browsing-contexts-by-name">
      6 
      7 <!-- user agents are not required to support open features other than `noopener`
      8     and on some platforms position and size features don't make sense -->
      9 <meta name="flags" content="may" />
     10 
     11 <script src="/resources/testharness.js"></script>
     12 <script src="/resources/testharnessreport.js"></script>
     13 <script src="/common/PrefixedPostMessage.js"></script>
     14 <script>
     15 var featuresPrefix = `top=0,left=0,`;
     16 var windowURL = 'resources/message-opener.html';
     17 
     18 // https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-integers
     19 
     20 setup (() => {
     21  // Before running tests, open a window using features that mimic
     22  // what would happen if the features tested here were set to invalid
     23  // values in later tests.
     24  // In cases where the value for `width` or `height` is
     25  // is less than the browser's minimum allowed value for that dimension,
     26  // but NOT 0, the value affected will become the browser's minimum allowed value.
     27 
     28  // This should result in a minimally-sized window for later comparison
     29  var featureString = `${featuresPrefix}width=1,height=1`;
     30  var prefixedMessage = new PrefixedMessageTest();
     31  prefixedMessage.onMessage((data, e) => {
     32    e.source.close();
     33    runWindowTests(data);
     34  });
     35  var win = window.open(prefixedMessage.url(windowURL), '', featureString);
     36 });
     37 
     38 function runWindowTests (baselineDimensions) {
     39 
     40  // Negative values for `width` should result in a window with minimum
     41  // valid allowed width
     42  [ 'width=-404',
     43    'width=-404.5',
     44    'width=-404e1'
     45  ].forEach(feature => {
     46    async_test(t => {
     47      var prefixedMessage = new PrefixedMessageTest();
     48      var featureString = `${featuresPrefix}height=405,${feature}`;
     49      prefixedMessage.onMessage(t.step_func_done((data, e) => {
     50        e.source.close();
     51        assert_equals(data.width, baselineDimensions.width, `"${feature} is negative and should result in a minimally-wide window"`);
     52      }));
     53      var win = window.open(prefixedMessage.url(windowURL) + '&expected_innerWidth=' + baselineDimensions.width, '', featureString);
     54    }, `features "${feature}" should NOT set "width=404"`);
     55  });
     56 
     57  // Negative values for `height` should result in a window with minimum
     58  // valid allowed height
     59  [ 'height=-404',
     60    'height=-404.5',
     61    'height=-404e1'
     62  ].forEach(feature => {
     63    async_test(t => {
     64      var prefixedMessage = new PrefixedMessageTest();
     65      var featureString = `${featuresPrefix}width=404,${feature}`;
     66      prefixedMessage.onMessage(t.step_func_done((data, e) => {
     67        e.source.close();
     68        assert_equals(data.height, baselineDimensions.height, `"${feature} is negative and should result in a minimal-height window"`);
     69      }));
     70      var win = window.open(prefixedMessage.url(windowURL) + '&expected_innerHeight=' + baselineDimensions.height, '', featureString);
     71    }, `features "${feature}" should NOT set "height=404"`);
     72  });
     73 }
     74 
     75 </script>