summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_import.js
blob: c630dcd5085cdfe02945b2d575ea801710a8a58c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test that the import button in the UI works.

// http rather than chrome to improve coverage
const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";

const FILENAME = "styleeditor-import-test.css";
const SOURCE = "body{background:red;}";

add_task(async function () {
  const { panel, ui } = await openStyleEditorForURL(TESTCASE_URI);

  const added = ui.once("test:editor-updated");
  importSheet(ui, panel.panelWindow);

  info("Waiting for editor to be added for the imported sheet.");
  const editor = await added;

  is(
    editor.savedFile.leafName,
    FILENAME,
    "imported stylesheet will be saved directly into the same file"
  );
  is(
    editor.friendlyName,
    FILENAME,
    "imported stylesheet has the same name as the filename"
  );
});

function importSheet(ui, panelWindow) {
  // create file to import first
  const file = new FileUtils.File(
    PathUtils.join(PathUtils.profileDir, FILENAME)
  );
  const ostream = FileUtils.openSafeFileOutputStream(file);
  const istream = getInputStream(SOURCE);

  NetUtil.asyncCopy(istream, ostream, function () {
    FileUtils.closeSafeFileOutputStream(ostream);

    // click the import button now that the file to import is ready
    ui._mockImportFile = file;

    waitForFocus(function () {
      const document = panelWindow.document;
      const importButton = document.querySelector(".style-editor-importButton");
      ok(importButton, "import button exists");

      EventUtils.synthesizeMouseAtCenter(importButton, {}, panelWindow);
    }, panelWindow);
  });
}