tor-browser

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

browser_homeDrop.js (3329B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 add_task(async function setupHomeButton() {
      5  // Put the home button in the pre-proton placement to test focus states.
      6  CustomizableUI.addWidgetToArea(
      7    "home-button",
      8    "nav-bar",
      9    CustomizableUI.getPlacementOfWidget("stop-reload-button").position + 1
     10  );
     11  CustomizableUI.addWidgetToArea("sidebar-button", "nav-bar");
     12  registerCleanupFunction(async function resetToolbar() {
     13    await CustomizableUI.reset();
     14  });
     15 });
     16 
     17 add_task(async function () {
     18  let HOMEPAGE_PREF = "browser.startup.homepage";
     19 
     20  await pushPrefs([HOMEPAGE_PREF, "about:mozilla"]);
     21 
     22  // Since synthesizeDrop triggers the srcElement, need to use another button
     23  // that should be visible.
     24  let dragSrcElement = document.getElementById("sidebar-button");
     25  ok(dragSrcElement, "Sidebar button exists");
     26  let homeButton = document.getElementById("home-button");
     27  ok(homeButton, "home button present");
     28 
     29  async function drop(dragData, homepage) {
     30    let setHomepageDialogPromise =
     31      BrowserTestUtils.promiseAlertDialogOpen("accept");
     32    let setHomepagePromise = TestUtils.waitForPrefChange(
     33      HOMEPAGE_PREF,
     34      newVal => newVal == homepage
     35    );
     36 
     37    EventUtils.synthesizeDrop(
     38      dragSrcElement,
     39      homeButton,
     40      dragData,
     41      "copy",
     42      window
     43    );
     44 
     45    // Ensure dnd suppression is cleared.
     46    EventUtils.synthesizeMouseAtCenter(homeButton, { type: "mouseup" }, window);
     47 
     48    await setHomepageDialogPromise;
     49    ok(true, "dialog appeared in response to home button drop");
     50 
     51    await setHomepagePromise;
     52 
     53    let modified = Services.prefs.getStringPref(HOMEPAGE_PREF);
     54    is(modified, homepage, "homepage is set correctly");
     55    Services.prefs.setStringPref(HOMEPAGE_PREF, "about:mozilla;");
     56  }
     57 
     58  function dropInvalidURI() {
     59    return new Promise(resolve => {
     60      let consoleListener = {
     61        observe(m) {
     62          if (m.message.includes("NS_ERROR_DOM_BAD_URI")) {
     63            ok(true, "drop was blocked");
     64            resolve();
     65          }
     66        },
     67      };
     68      Services.console.registerListener(consoleListener);
     69      registerCleanupFunction(function () {
     70        Services.console.unregisterListener(consoleListener);
     71      });
     72 
     73      executeSoon(function () {
     74        info("Attempting second drop, of a javascript: URI");
     75        // The drop handler throws an exception when dragging URIs that inherit
     76        // principal, e.g. javascript:
     77        expectUncaughtException();
     78        EventUtils.synthesizeDrop(
     79          dragSrcElement,
     80          homeButton,
     81          [[{ type: "text/plain", data: "javascript:8888" }]],
     82          "copy",
     83          window
     84        );
     85        // Ensure dnd suppression is cleared.
     86        EventUtils.synthesizeMouseAtCenter(
     87          homeButton,
     88          { type: "mouseup" },
     89          window
     90        );
     91      });
     92    });
     93  }
     94 
     95  await drop(
     96    [[{ type: "text/plain", data: "http://mochi.test:8888/" }]],
     97    "http://mochi.test:8888/"
     98  );
     99  await drop(
    100    [
    101      [
    102        {
    103          type: "text/plain",
    104          data: "http://mochi.test:8888/\nhttp://mochi.test:8888/b\nhttp://mochi.test:8888/c",
    105        },
    106      ],
    107    ],
    108    "http://mochi.test:8888/|http://mochi.test:8888/b|http://mochi.test:8888/c"
    109  );
    110  await dropInvalidURI();
    111 });