tor-browser

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

browser_background_zoom.js (4140B)


      1 var gTestPage =
      2  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      3  "http://example.org/browser/browser/base/content/test/zoom/zoom_test.html";
      4 var gTestImage =
      5  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      6  "http://example.org/browser/browser/base/content/test/general/moz.png";
      7 var gTab1, gTab2, gTab3;
      8 var gLevel;
      9 
     10 function test() {
     11  waitForExplicitFinish();
     12  registerCleanupFunction(async () => {
     13    await new Promise(resolve => {
     14      ContentPrefService2.removeByName(FullZoom.name, Cu.createLoadContext(), {
     15        handleCompletion: resolve,
     16      });
     17    });
     18  });
     19 
     20  (async function () {
     21    gTab1 = BrowserTestUtils.addTab(gBrowser, gTestPage);
     22    gTab2 = BrowserTestUtils.addTab(gBrowser);
     23    gTab3 = BrowserTestUtils.addTab(gBrowser);
     24 
     25    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab1);
     26    await FullZoomHelper.load(gTab1, gTestPage);
     27    await FullZoomHelper.load(gTab2, gTestPage);
     28  })().then(secondPageLoaded, FullZoomHelper.failAndContinue(finish));
     29 }
     30 
     31 function secondPageLoaded() {
     32  (async function () {
     33    FullZoomHelper.zoomTest(gTab1, 1, "Initial zoom of tab 1 should be 1");
     34    FullZoomHelper.zoomTest(gTab2, 1, "Initial zoom of tab 2 should be 1");
     35    FullZoomHelper.zoomTest(gTab3, 1, "Initial zoom of tab 3 should be 1");
     36 
     37    // Now have three tabs, two with the test page, one blank. Tab 1 is selected
     38    // Zoom tab 1
     39    FullZoom.enlarge();
     40    gLevel = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab1));
     41 
     42    Assert.greater(gLevel, 1, "New zoom for tab 1 should be greater than 1");
     43    FullZoomHelper.zoomTest(gTab2, 1, "Zooming tab 1 should not affect tab 2");
     44    FullZoomHelper.zoomTest(gTab3, 1, "Zooming tab 1 should not affect tab 3");
     45 
     46    await FullZoomHelper.load(gTab3, gTestPage);
     47  })().then(thirdPageLoaded, FullZoomHelper.failAndContinue(finish));
     48 }
     49 
     50 function thirdPageLoaded() {
     51  (async function () {
     52    FullZoomHelper.zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
     53    FullZoomHelper.zoomTest(gTab2, 1, "Tab 2 should still not be affected");
     54    FullZoomHelper.zoomTest(
     55      gTab3,
     56      gLevel,
     57      "Tab 3 should have zoomed as it was loading in the background"
     58    );
     59 
     60    // Switching to tab 2 should update its zoom setting.
     61    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab2);
     62    FullZoomHelper.zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
     63    FullZoomHelper.zoomTest(gTab2, gLevel, "Tab 2 should be zoomed now");
     64    FullZoomHelper.zoomTest(gTab3, gLevel, "Tab 3 should still be zoomed");
     65 
     66    await FullZoomHelper.load(gTab1, gTestImage);
     67  })().then(imageLoaded, FullZoomHelper.failAndContinue(finish));
     68 }
     69 
     70 function imageLoaded() {
     71  (async function () {
     72    FullZoomHelper.zoomTest(
     73      gTab1,
     74      1,
     75      "Zoom should be 1 when image was loaded in the background"
     76    );
     77    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab1);
     78    FullZoomHelper.zoomTest(
     79      gTab1,
     80      1,
     81      "Zoom should still be 1 when tab with image is selected"
     82    );
     83  })().then(imageZoomSwitch, FullZoomHelper.failAndContinue(finish));
     84 }
     85 
     86 function imageZoomSwitch() {
     87  (async function () {
     88    await FullZoomHelper.navigate(FullZoomHelper.BACK);
     89    await FullZoomHelper.navigate(FullZoomHelper.FORWARD);
     90    FullZoomHelper.zoomTest(
     91      gTab1,
     92      1,
     93      "Tab 1 should not be zoomed when an image loads"
     94    );
     95 
     96    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab2);
     97    FullZoomHelper.zoomTest(
     98      gTab1,
     99      1,
    100      "Tab 1 should still not be zoomed when deselected"
    101    );
    102  })().then(finishTest, FullZoomHelper.failAndContinue(finish));
    103 }
    104 
    105 var finishTestStarted = false;
    106 function finishTest() {
    107  (async function () {
    108    ok(!finishTestStarted, "finishTest called more than once");
    109    finishTestStarted = true;
    110    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab1);
    111    await FullZoomHelper.removeTabAndWaitForLocationChange(gTab1);
    112    await FullZoomHelper.removeTabAndWaitForLocationChange(gTab2);
    113    await FullZoomHelper.removeTabAndWaitForLocationChange(gTab3);
    114  })().then(finish, FullZoomHelper.failAndContinue(finish));
    115 }