tor-browser

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

browser_dbg-layout-changes.js (2369B)


      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
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 /**
      6 * This if the debugger's layout is correctly modified when the toolbox's
      7 * host changes.
      8 */
      9 
     10 "use strict";
     11 
     12 requestLongerTimeout(2);
     13 
     14 let gDefaultHostType = Services.prefs.getCharPref("devtools.toolbox.host");
     15 
     16 add_setup(async function () {
     17  // Disable window occlusion. See bug 1733955 / bug 1779559.
     18  if (navigator.platform.indexOf("Win") == 0) {
     19    await SpecialPowers.pushPrefEnv({
     20      set: [["widget.windows.window_occlusion_tracking.enabled", false]],
     21    });
     22  }
     23 });
     24 
     25 add_task(async function () {
     26  // test is too slow on some platforms due to the number of test cases
     27  const dbg = await initDebugger("doc-iframes.html");
     28 
     29  const layouts = [
     30    ["vertical", "window:small"],
     31    ["horizontal", "bottom"],
     32    ["vertical", "right"],
     33    ["horizontal", "window:big"],
     34  ];
     35 
     36  for (const layout of layouts) {
     37    const [orientation, host] = layout;
     38    await testLayout(dbg, orientation, host);
     39  }
     40 
     41  ok(true, "Orientations are correct");
     42 });
     43 
     44 async function testLayout(dbg, orientation, host) {
     45  info(`Switching to ${host} ${orientation}.`);
     46 
     47  await switchHost(dbg, host);
     48  await resizeToolboxWindow(dbg, host);
     49  return waitForState(dbg, () => dbg.selectors.getOrientation() == orientation);
     50 }
     51 
     52 function getHost(host) {
     53  if (host.indexOf("window") == 0) {
     54    return "window";
     55  }
     56  return host;
     57 }
     58 
     59 async function switchHost(dbg, hostType) {
     60  const { toolbox } = dbg;
     61  await toolbox.switchHost(getHost(hostType));
     62 }
     63 
     64 function resizeToolboxWindow(dbg, host) {
     65  const { toolbox } = dbg;
     66  const sizeOption = host.split(":")[1];
     67  if (!sizeOption) {
     68    return;
     69  }
     70 
     71  const win = toolbox.win.parent;
     72 
     73  let breakpoint = 800;
     74  if (sizeOption == "big" && win.outerWidth <= breakpoint) {
     75    breakpoint += 300;
     76  } else if (sizeOption == "small" && win.outerWidth >= breakpoint) {
     77    breakpoint -= 300;
     78  }
     79  resizeWindow(dbg, breakpoint);
     80 }
     81 
     82 function resizeWindow(dbg, width) {
     83  const { toolbox } = dbg;
     84  const win = toolbox.win.parent;
     85  win.resizeTo(width, window.screen.availHeight);
     86 }
     87 
     88 registerCleanupFunction(function () {
     89  Services.prefs.setCharPref("devtools.toolbox.host", gDefaultHostType);
     90  gDefaultHostType = null;
     91 });