tor-browser

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

browser_styleeditor_import.js (1660B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that the import button in the UI works.
      6 
      7 // http rather than chrome to improve coverage
      8 const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
      9 
     10 const FILENAME = "styleeditor-import-test.css";
     11 const SOURCE = "body{background:red;}";
     12 
     13 add_task(async function () {
     14  const { panel, ui } = await openStyleEditorForURL(TESTCASE_URI);
     15 
     16  const added = ui.once("test:editor-updated");
     17  importSheet(ui, panel.panelWindow);
     18 
     19  info("Waiting for editor to be added for the imported sheet.");
     20  const editor = await added;
     21 
     22  is(
     23    editor.savedFile.leafName,
     24    FILENAME,
     25    "imported stylesheet will be saved directly into the same file"
     26  );
     27  is(
     28    editor.friendlyName,
     29    FILENAME,
     30    "imported stylesheet has the same name as the filename"
     31  );
     32 });
     33 
     34 function importSheet(ui, panelWindow) {
     35  // create file to import first
     36  const file = new FileUtils.File(
     37    PathUtils.join(PathUtils.profileDir, FILENAME)
     38  );
     39  const ostream = FileUtils.openSafeFileOutputStream(file);
     40  const istream = getInputStream(SOURCE);
     41 
     42  NetUtil.asyncCopy(istream, ostream, function () {
     43    FileUtils.closeSafeFileOutputStream(ostream);
     44 
     45    // click the import button now that the file to import is ready
     46    ui._mockImportFile = file;
     47 
     48    waitForFocus(function () {
     49      const document = panelWindow.document;
     50      const importButton = document.querySelector(".style-editor-importButton");
     51      ok(importButton, "import button exists");
     52 
     53      EventUtils.synthesizeMouseAtCenter(importButton, {}, panelWindow);
     54    }, panelWindow);
     55  });
     56 }