tor-browser

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

browser_sitespecific_video_zoom.js (4114B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 "use strict";
      5 
      6 const TEST_PAGE =
      7  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      8  "http://example.org/browser/browser/base/content/test/zoom/zoom_test.html";
      9 const TEST_VIDEO =
     10  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     11  "http://example.org/browser/browser/base/content/test/general/video.webm";
     12 
     13 var gTab1, gTab2, gLevel1;
     14 
     15 function test() {
     16  waitForExplicitFinish();
     17 
     18  (async function () {
     19    gTab1 = BrowserTestUtils.addTab(gBrowser);
     20    gTab2 = BrowserTestUtils.addTab(gBrowser);
     21 
     22    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab1);
     23    await FullZoomHelper.load(gTab1, TEST_PAGE);
     24    await FullZoomHelper.load(gTab2, TEST_VIDEO);
     25  })().then(zoomTab1, FullZoomHelper.failAndContinue(finish));
     26 }
     27 
     28 function zoomTab1() {
     29  (async function () {
     30    is(gBrowser.selectedTab, gTab1, "Tab 1 is selected");
     31 
     32    // Reset zoom level if we run this test > 1 time in same browser session.
     33    var level1 = ZoomManager.getZoomForBrowser(
     34      gBrowser.getBrowserForTab(gTab1)
     35    );
     36    if (level1 > 1) {
     37      FullZoom.reduce();
     38    }
     39 
     40    FullZoomHelper.zoomTest(gTab1, 1, "Initial zoom of tab 1 should be 1");
     41    FullZoomHelper.zoomTest(gTab2, 1, "Initial zoom of tab 2 should be 1");
     42 
     43    FullZoom.enlarge();
     44    gLevel1 = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab1));
     45 
     46    Assert.greater(gLevel1, 1, "New zoom for tab 1 should be greater than 1");
     47    FullZoomHelper.zoomTest(gTab2, 1, "Zooming tab 1 should not affect tab 2");
     48 
     49    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab2);
     50    FullZoomHelper.zoomTest(
     51      gTab2,
     52      1,
     53      "Tab 2 is still unzoomed after it is selected"
     54    );
     55    FullZoomHelper.zoomTest(gTab1, gLevel1, "Tab 1 is still zoomed");
     56  })().then(zoomTab2, FullZoomHelper.failAndContinue(finish));
     57 }
     58 
     59 function zoomTab2() {
     60  (async function () {
     61    is(gBrowser.selectedTab, gTab2, "Tab 2 is selected");
     62 
     63    FullZoom.reduce();
     64    let level2 = ZoomManager.getZoomForBrowser(
     65      gBrowser.getBrowserForTab(gTab2)
     66    );
     67 
     68    Assert.less(level2, 1, "New zoom for tab 2 should be less than 1");
     69    FullZoomHelper.zoomTest(
     70      gTab1,
     71      gLevel1,
     72      "Zooming tab 2 should not affect tab 1"
     73    );
     74 
     75    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab1);
     76    FullZoomHelper.zoomTest(
     77      gTab1,
     78      gLevel1,
     79      "Tab 1 should have the same zoom after it's selected"
     80    );
     81  })().then(testNavigation, FullZoomHelper.failAndContinue(finish));
     82 }
     83 
     84 function testNavigation() {
     85  (async function () {
     86    await FullZoomHelper.load(gTab1, TEST_VIDEO);
     87    FullZoomHelper.zoomTest(
     88      gTab1,
     89      1,
     90      "Zoom should be 1 when a video was loaded"
     91    );
     92    await waitForNextTurn(); // trying to fix orange bug 806046
     93    await FullZoomHelper.navigate(FullZoomHelper.BACK);
     94    FullZoomHelper.zoomTest(
     95      gTab1,
     96      gLevel1,
     97      "Zoom should be restored when a page is loaded"
     98    );
     99    await waitForNextTurn(); // trying to fix orange bug 806046
    100    await FullZoomHelper.navigate(FullZoomHelper.FORWARD);
    101    FullZoomHelper.zoomTest(
    102      gTab1,
    103      1,
    104      "Zoom should be 1 again when navigating back to a video"
    105    );
    106  })().then(finishTest, FullZoomHelper.failAndContinue(finish));
    107 }
    108 
    109 function waitForNextTurn() {
    110  return new Promise(resolve => {
    111    setTimeout(() => resolve(), 0);
    112  });
    113 }
    114 
    115 var finishTestStarted = false;
    116 function finishTest() {
    117  (async function () {
    118    ok(!finishTestStarted, "finishTest called more than once");
    119    finishTestStarted = true;
    120 
    121    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab1);
    122    await FullZoom.reset();
    123    await FullZoomHelper.removeTabAndWaitForLocationChange(gTab1);
    124    await FullZoomHelper.selectTabAndWaitForLocationChange(gTab2);
    125    await FullZoom.reset();
    126    await FullZoomHelper.removeTabAndWaitForLocationChange(gTab2);
    127  })().then(finish, FullZoomHelper.failAndContinue(finish));
    128 }