tor-browser

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

browser_styleeditor_inline_friendly_names.js (2860B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that inline style sheets get correct names if they are saved to disk and
      6 // that those names survice a reload but not navigation to another page.
      7 
      8 const FIRST_TEST_PAGE = TEST_BASE_HTTPS + "inline-1.html";
      9 const SECOND_TEST_PAGE = TEST_BASE_HTTPS + "inline-2.html";
     10 const SAVE_PATH = "test.css";
     11 
     12 add_task(async function () {
     13  const { ui } = await openStyleEditorForURL(FIRST_TEST_PAGE);
     14 
     15  testIndentifierGeneration(ui);
     16 
     17  await saveFirstInlineStyleSheet(ui);
     18  await testFriendlyNamesAfterSave(ui);
     19  await reloadPageAndWaitForStyleSheets(ui, 2);
     20  await testFriendlyNamesAfterSave(ui);
     21  await navigateToAndWaitForStyleSheets(SECOND_TEST_PAGE, ui, 2);
     22  await testFriendlyNamesAfterNavigation(ui);
     23 });
     24 
     25 function testIndentifierGeneration(ui) {
     26  const fakeStyleSheetFile = {
     27    href: "http://example.com/test.css",
     28    nodeHref: "http://example.com/",
     29    styleSheetIndex: 1,
     30  };
     31 
     32  const fakeInlineStyleSheet = {
     33    href: null,
     34    nodeHref: "http://example.com/",
     35    styleSheetIndex: 2,
     36  };
     37 
     38  is(
     39    ui.getStyleSheetIdentifier(fakeStyleSheetFile),
     40    "http://example.com/test.css",
     41    "URI is the identifier of style sheet file."
     42  );
     43 
     44  is(
     45    ui.getStyleSheetIdentifier(fakeInlineStyleSheet),
     46    "inline-2-at-http://example.com/",
     47    "Inline sheets are identified by their page and position in the page."
     48  );
     49 }
     50 
     51 function saveFirstInlineStyleSheet(ui) {
     52  return new Promise(resolve => {
     53    const editor = ui.editors[0];
     54    const destFile = new FileUtils.File(
     55      PathUtils.join(PathUtils.profileDir, SAVE_PATH)
     56    );
     57 
     58    editor.saveToFile(destFile, function (file) {
     59      ok(file, "File was correctly saved.");
     60      resolve();
     61    });
     62  });
     63 }
     64 
     65 function testFriendlyNamesAfterSave(ui) {
     66  const firstEditor = ui.editors[0];
     67  const secondEditor = ui.editors[1];
     68 
     69  // The friendly name of first sheet should've been remembered, the second
     70  // should not be the same (bug 969900).
     71  is(
     72    firstEditor.friendlyName,
     73    SAVE_PATH,
     74    "Friendly name is correct for the saved inline style sheet."
     75  );
     76  isnot(
     77    secondEditor.friendlyName,
     78    SAVE_PATH,
     79    "Friendly name for the second inline sheet isn't the same as the first."
     80  );
     81 
     82  return Promise.resolve(null);
     83 }
     84 
     85 function testFriendlyNamesAfterNavigation(ui) {
     86  const firstEditor = ui.editors[0];
     87  const secondEditor = ui.editors[1];
     88 
     89  // Inline style sheets shouldn't have the name of previously saved file as the
     90  // page is different.
     91  isnot(
     92    firstEditor.friendlyName,
     93    SAVE_PATH,
     94    "The first editor doesn't have the save path as a friendly name."
     95  );
     96  isnot(
     97    secondEditor.friendlyName,
     98    SAVE_PATH,
     99    "The second editor doesn't have the save path as a friendly name."
    100  );
    101 
    102  return Promise.resolve(null);
    103 }