tor-browser

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

browser_state_restore.js (2530B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that the previous viewport size, user agent, dppx and touch simulation properties
      7 // are restored when reopening RDM.
      8 
      9 const TEST_URL = "data:text/html;charset=utf-8,";
     10 const DEFAULT_DPPX = window.devicePixelRatio;
     11 const NEW_DPPX = DEFAULT_DPPX + 1;
     12 const NEW_USER_AGENT = "Mozilla/5.0 (Mobile; rv:39.0) Gecko/39.0 Firefox/39.0";
     13 
     14 addRDMTask(
     15  TEST_URL,
     16  async function ({ ui, manager }) {
     17    const { store } = ui.toolWindow;
     18 
     19    reloadOnTouchChange(true);
     20    reloadOnUAChange(true);
     21 
     22    await waitUntilState(store, state => state.viewports.length == 1);
     23 
     24    info("Checking the default RDM state.");
     25    testViewportDeviceMenuLabel(ui, "Responsive");
     26    testViewportDimensions(ui, 320, 480);
     27    await testUserAgent(ui, DEFAULT_UA);
     28    await testDevicePixelRatio(ui, DEFAULT_DPPX);
     29    testTouchEventsOverride(ui, false);
     30 
     31    info("Changing the RDM size, dppx, ua and toggle ON touch simulations.");
     32    await setViewportSize(ui, manager, 90, 500);
     33    await selectDevicePixelRatio(ui, NEW_DPPX);
     34    await toggleTouchSimulation(ui);
     35    await changeUserAgentInput(ui, NEW_USER_AGENT);
     36 
     37    reloadOnTouchChange(false);
     38    reloadOnUAChange(false);
     39  },
     40  { waitForDeviceList: true }
     41 );
     42 
     43 addRDMTask(
     44  TEST_URL,
     45  async function ({ ui }) {
     46    const { store } = ui.toolWindow;
     47 
     48    reloadOnTouchChange(true);
     49    reloadOnUAChange(true);
     50 
     51    info("Reopening RDM and checking that the previous state is restored.");
     52 
     53    await waitUntilState(store, state => state.viewports.length == 1);
     54 
     55    testViewportDimensions(ui, 90, 500);
     56    await testUserAgent(ui, NEW_USER_AGENT);
     57    await testDevicePixelRatio(ui, NEW_DPPX);
     58    testTouchEventsOverride(ui, true);
     59 
     60    info("Rotating the viewport.");
     61    rotateViewport(ui);
     62 
     63    reloadOnTouchChange(false);
     64    reloadOnUAChange(false);
     65  },
     66  { waitForDeviceList: true }
     67 );
     68 
     69 addRDMTask(
     70  TEST_URL,
     71  async function ({ ui }) {
     72    const { store } = ui.toolWindow;
     73 
     74    reloadOnTouchChange(true);
     75    reloadOnUAChange(true);
     76 
     77    info("Reopening RDM and checking that the previous state is restored.");
     78 
     79    await waitUntilState(store, state => state.viewports.length == 1);
     80 
     81    testViewportDimensions(ui, 500, 90);
     82    await testUserAgent(ui, NEW_USER_AGENT);
     83    await testDevicePixelRatio(ui, NEW_DPPX);
     84    testTouchEventsOverride(ui, true);
     85 
     86    reloadOnTouchChange(false);
     87    reloadOnUAChange(false);
     88  },
     89  { waitForDeviceList: true }
     90 );