tor-browser

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

browser_touch_device.js (2588B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests changing viewport touch simulation
      7 const TEST_URL = "data:text/html;charset=utf-8,touch simulation test";
      8 const Types = require("resource://devtools/client/responsive/types.js");
      9 
     10 const testDevice = {
     11  name: "Fake Phone RDM Test",
     12  width: 320,
     13  height: 470,
     14  pixelRatio: 5.5,
     15  userAgent: "Mozilla/5.0 (Mobile; rv:39.0) Gecko/39.0 Firefox/39.0",
     16  touch: true,
     17  firefoxOS: true,
     18  os: "custom",
     19  featured: true,
     20 };
     21 
     22 // Add the new device to the list
     23 addDeviceForTest(testDevice);
     24 
     25 addRDMTask(
     26  TEST_URL,
     27  async function ({ ui }) {
     28    reloadOnTouchChange(true);
     29 
     30    await waitStartup(ui);
     31 
     32    await testDefaults(ui);
     33    await testChangingDevice(ui);
     34    await testResizingViewport(ui, { hasDevice: true, touch: true });
     35    await testDisableTouchSimulation(ui);
     36    await testResizingViewport(ui, { hasDevice: false, touch: false });
     37    await testEnableTouchSimulation(ui);
     38    await testDisableTouchSimulation(ui);
     39 
     40    reloadOnTouchChange(false);
     41  },
     42  { waitForDeviceList: true }
     43 );
     44 
     45 async function waitStartup(ui) {
     46  const { store } = ui.toolWindow;
     47 
     48  // Wait until the viewport has been added and the device list has been loaded
     49  await waitUntilState(
     50    store,
     51    state =>
     52      state.viewports.length == 1 &&
     53      state.devices.listState == Types.loadableState.LOADED
     54  );
     55 }
     56 
     57 async function testDefaults(ui) {
     58  info("Test Defaults");
     59 
     60  testTouchEventsOverride(ui, false);
     61  testViewportDeviceMenuLabel(ui, "Responsive");
     62 }
     63 
     64 async function testChangingDevice(ui) {
     65  info("Test Changing Device");
     66 
     67  await selectDevice(ui, testDevice.name);
     68  await waitForViewportResizeTo(ui, testDevice.width, testDevice.height);
     69  testTouchEventsOverride(ui, true);
     70  testViewportDeviceMenuLabel(ui, testDevice.name);
     71 }
     72 
     73 async function testResizingViewport(ui, { hasDevice, touch }) {
     74  info(`Test resizing the viewport, device ${hasDevice}, touch ${touch}`);
     75 
     76  await testViewportResize(
     77    ui,
     78    ".viewport-vertical-resize-handle",
     79    [-10, -10],
     80    [0, -10],
     81    {
     82      hasDevice,
     83    }
     84  );
     85  testTouchEventsOverride(ui, touch);
     86  testViewportDeviceMenuLabel(ui, "Responsive");
     87 }
     88 
     89 async function testEnableTouchSimulation(ui) {
     90  info("Test enabling touch simulation via button");
     91 
     92  await toggleTouchSimulation(ui);
     93  testTouchEventsOverride(ui, true);
     94 }
     95 
     96 async function testDisableTouchSimulation(ui) {
     97  info("Test disabling touch simulation via button");
     98 
     99  await toggleTouchSimulation(ui);
    100  testTouchEventsOverride(ui, false);
    101 }