tor-browser

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

test_bug369370.html (5783B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=369370
      5 -->
      6 <head>
      7  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      8  <title>Test for Bug 369370</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13  <script type="text/javascript">
     14    /*
     15     * Test strategy:
     16     */
     17    function makeClickFor(x, y) {
     18        var event = kidDoc.createEvent("mouseevent");
     19        event.initMouseEvent("click",
     20            true, true, kidWin, 1,      // bubbles, cancelable, view, single-click
     21            x, y, x, y,                 // screen X/Y, client X/Y
     22            false, false, false, false, // no key modifiers
     23            0, null);                   // left click, not relatedTarget
     24        return event;
     25    }
     26 
     27    function childLoaded() {
     28        kidDoc = kidWin.document;
     29        ok(true, "Child window loaded");
     30 
     31        var elements = kidDoc.getElementsByTagName("img");
     32        is(elements.length, 1, "looking for imagedoc img");
     33        var img = elements[0];
     34 
     35        // Need to use innerWidth/innerHeight of the window
     36        // since the containing image is absolutely positioned,
     37        // causing clientHeight to be zero.
     38        is(kidWin.innerWidth, 400, "Checking doc width");
     39        is(kidWin.innerHeight, 300, "Checking doc height");
     40 
     41        // Image just loaded and is scaled to window size.
     42        is(img.width,  400, "image width");
     43        is(img.height, 300, "image height");
     44        is(kidDoc.body.scrollLeft,  0, "Checking scrollLeft");
     45        is(kidDoc.body.scrollTop,   0, "Checking scrollTop");
     46 
     47        // ========== test 1 ==========
     48        // Click in the upper left to zoom in
     49        var event = makeClickFor(25,25);
     50        img.dispatchEvent(event);
     51        ok(true, "----- click 1 -----");
     52 
     53        is(img.width,  800, "image width");
     54        is(img.height, 600, "image height");
     55        is(kidDoc.body.scrollLeft,  0, "Checking scrollLeft");
     56        is(kidDoc.body.scrollTop,   0, "Checking scrollTop");
     57 
     58        // ========== test 2 ==========
     59        // Click there again to zoom out
     60        event = makeClickFor(25,25);
     61        img.dispatchEvent(event);
     62        ok(true, "----- click 2 -----");
     63 
     64        is(img.width,  400, "image width");
     65        is(img.height, 300, "image height");
     66        is(kidDoc.body.scrollLeft,  0, "Checking scrollLeft");
     67        is(kidDoc.body.scrollTop,   0, "Checking scrollTop");
     68 
     69        // ========== test 3 ==========
     70        // Click in the lower right to zoom in
     71        event = makeClickFor(350, 250);
     72        img.dispatchEvent(event);
     73        ok(true, "----- click 3 -----");
     74 
     75        is(img.width,  800, "image width");
     76        is(img.height, 600, "image height");
     77        is(kidDoc.body.scrollLeft,
     78           kidDoc.body.scrollLeftMax, "Checking scrollLeft");
     79        is(kidDoc.body.scrollTop,
     80           kidDoc.body.scrollTopMax, "Checking scrollTop");
     81 
     82        // ========== test 4 ==========
     83        // Click there again to zoom out
     84        event = makeClickFor(350, 250);
     85        img.dispatchEvent(event);
     86        ok(true, "----- click 4 -----");
     87 
     88        is(img.width,  400, "image width");
     89        is(img.height, 300, "image height");
     90        is(kidDoc.body.scrollLeft,  0, "Checking scrollLeft");
     91        is(kidDoc.body.scrollTop,   0, "Checking scrollTop");
     92 
     93        // ========== test 5 ==========
     94        // Click in the upper left to zoom in again
     95        event = makeClickFor(25, 25);
     96        img.dispatchEvent(event);
     97        ok(true, "----- click 5 -----");
     98        is(img.width,  800, "image width");
     99        is(img.height, 600, "image height");
    100        is(kidDoc.body.scrollLeft,  0, "Checking scrollLeft");
    101        is(kidDoc.body.scrollTop,   0, "Checking scrollTop");
    102        is(img.getBoundingClientRect().top, 0, "Image is in view vertically");
    103 
    104        // ========== test 6 ==========
    105        // Now try resizing the window so the image fits vertically.
    106        function test6() {
    107          kidWin.addEventListener("resize", function() {
    108            // Give the image document time to respond
    109            SimpleTest.executeSoon(function() {
    110              is(img.height, 600, "image height");
    111              var bodyHeight = kidDoc.documentElement.scrollHeight;
    112              var imgRect = img.getBoundingClientRect();
    113              is(imgRect.top, bodyHeight - imgRect.bottom, "Image is vertically centered");
    114              test7();
    115            });
    116          }, {once: true});
    117 
    118          var decorationSize = kidWin.outerHeight - kidWin.innerHeight;
    119          kidWin.resizeTo(400, 600 + 50 + decorationSize);
    120        }
    121 
    122        // ========== test 7 ==========
    123        // Now try resizing the window so the image no longer fits vertically.
    124        function test7() {
    125          kidWin.addEventListener("resize", function() {
    126            // Give the image document time to respond
    127            SimpleTest.executeSoon(function() {
    128              is(img.height, 600, "image height");
    129              is(img.getBoundingClientRect().top, 0, "Image is at top again");
    130              kidWin.close();
    131              SimpleTest.finish();
    132            });
    133          }, {once: true});
    134 
    135          var decorationSize = kidWin.outerHeight - kidWin.innerHeight;
    136          kidWin.resizeTo(400, 300 + decorationSize);
    137        }
    138 
    139        test6();
    140    }
    141    var kidWin;
    142    var kidDoc;
    143 
    144    SimpleTest.waitForExplicitFinish();
    145    SpecialPowers.pushPrefEnv({"set":[["browser.enable_automatic_image_resizing", true]]}, function() {
    146       kidWin = window.open("bug369370-popup.png", "bug369370", "width=400,height=300");
    147       // will init onload
    148       ok(kidWin, "opened child window");
    149       kidWin.onload = childLoaded;
    150    });
    151  </script>
    152 </body>
    153 </html>