Beispiel #1
0
function testSetTheme() {
  const originalTheme = getTheme();
  // Put this in a variable rather than hardcoding it because the default
  // changes between aurora and nightly
  const otherTheme = originalTheme == "dark" ? "light" : "dark";

  const prefObserver = new PrefObserver("devtools.");
  prefObserver.once("devtools.theme", () => {
    const newValue = Services.prefs.getCharPref("devtools.theme");
    is(newValue, otherTheme,
      "A preference event triggered by setTheme comes after the value is set.");
  });
  setTheme(otherTheme);
  is(Services.prefs.getCharPref("devtools.theme"), otherTheme,
     "setTheme() correctly sets another theme.");
  setTheme(originalTheme);
  is(Services.prefs.getCharPref("devtools.theme"), originalTheme,
     "setTheme() correctly sets the original theme.");
  setTheme("unknown");
  is(Services.prefs.getCharPref("devtools.theme"), "unknown",
     "setTheme() correctly sets an unknown theme.");
  Services.prefs.setCharPref("devtools.theme", originalTheme);

  prefObserver.destroy();
}
function* testSelect(select) {
  let pref = select.getAttribute("data-pref");
  let options = Array.from(select.options);
  info("Checking select for: " + pref);

  is(select.options[select.selectedIndex].value, GetPref(pref),
    "select starts out selected");

  for (let option of options) {
    if (options.indexOf(option) === select.selectedIndex) {
      continue;
    }

    let observer = new PrefObserver("devtools.");

    let deferred = defer();
    let changeSeen = false;
    observer.once(pref, () => {
      changeSeen = true;
      is(GetPref(pref), option.value, "Preference been switched for " + pref);
      deferred.resolve();
    });

    select.selectedIndex = options.indexOf(option);
    let changeEvent = new Event("change");
    select.dispatchEvent(changeEvent);

    yield deferred.promise;

    ok(changeSeen, "Correct pref was changed");
    observer.destroy();
  }
}
function* testMouseClick(node, prefValue) {
  let deferred = defer();

  let observer = new PrefObserver("devtools.");

  let pref = node.getAttribute("data-pref");
  let changeSeen = false;
  observer.once(pref, () => {
    changeSeen = true;
    is(GetPref(pref), !prefValue, "New value is correct for " + pref);
    deferred.resolve();
  });

  node.scrollIntoView();

  // We use executeSoon here to ensure that the element is in view and
  // clickable.
  executeSoon(function () {
    info("Click event synthesized for pref " + pref);
    EventUtils.synthesizeMouseAtCenter(node, {}, panelWin);
  });

  yield deferred.promise;

  ok(changeSeen, "Correct pref was changed");
  observer.destroy();
}
add_task(function* () {
  let hud = yield openNewTabAndConsole(TEST_URI);

  info("Call the log function defined in the test page");
  yield ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
    content.wrappedJSObject.logMessage();
  });

  yield testPrefDefaults(hud);

  let observer = new PrefObserver("");
  let toolbox = gDevTools.getToolbox(hud.target);
  let optionsPanel = yield toolbox.selectTool("options");
  yield togglePref(optionsPanel, observer);
  observer.destroy();

  yield testChangedPref(hud);

  Services.prefs.clearUserPref(PREF_MESSAGE_TIMESTAMP);
});
Beispiel #5
0
add_task(async function() {
  const observer = new PrefObserver("");
  let onPrefUpdated = observer.once(PREF_MESSAGE_TIMESTAMP, () => {});
  Services.prefs.setBoolPref(PREF_MESSAGE_TIMESTAMP, true);
  await onPrefUpdated;

  const hud = await openNewTabAndConsole(TEST_URI);
  hud.ui.clearOutput();

  info("Call the log function defined in the test page");
  await ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
    content.wrappedJSObject.logStuff();
  });

  info("Test copy menu item for the simple log");
  let message = await waitFor(() => findMessage(hud, "simple text message"));
  let clipboardText = await copyMessageContent(hud, message);
  ok(true, "Clipboard text was found and saved");

  info("Check copied text for simple log message");
  let lines = clipboardText.split("\n");
  is(lines.length, 2, "There are 2 lines in the copied text");
  is(lines[1], "", "The last line is an empty new line");
  ok(LOG_FORMAT_WITH_TIMESTAMP.test(lines[0]),
    "Log line has the right format:\n" + lines[0]);

  info("Test copy menu item for the stack trace message");
  message = await waitFor(() => findMessage(hud, "console.trace"));
  // Wait for the stacktrace to be rendered.
  await waitFor(() => message.querySelector(".frames"));
  clipboardText = await copyMessageContent(hud, message);
  ok(true, "Clipboard text was found and saved");

  info("Check copied text for stack trace message");
  lines = clipboardText.split("\n");
  is(lines.length, 4, "There are 4 lines in the copied text");
  is(lines[3], "", "The last line is an empty new line");
  ok(LOG_FORMAT_WITH_TIMESTAMP.test(lines[0]),
    "Log line has the right format:\n" + lines[0]);
  ok(TRACE_FORMAT.test(lines[1]), "Stacktrace line has the right format:\n" + lines[1]);
  ok(TRACE_FORMAT.test(lines[2]), "Stacktrace line has the right format:\n" + lines[2]);

  info("Test copy menu item without timestamp");

  onPrefUpdated = observer.once(PREF_MESSAGE_TIMESTAMP, () => {});
  Services.prefs.setBoolPref(PREF_MESSAGE_TIMESTAMP, false);
  await onPrefUpdated;

  info("Test copy menu item for the simple log");
  message = await waitFor(() => findMessage(hud, "simple text message"));
  clipboardText = await copyMessageContent(hud, message);
  ok(true, "Clipboard text was found and saved");

  info("Check copied text for simple log message");
  lines = clipboardText.split("\n");
  is(lines.length, 2, "There are 2 lines in the copied text");
  is(lines[1], "", "The last line is an empty new line");
  ok(LOG_FORMAT_WITHOUT_TIMESTAMP.test(lines[0]),
    "Log line has the right format:\n" + lines[0]);

  info("Test copy menu item for the stack trace message");
  message = await waitFor(() => findMessage(hud, "console.trace"));
  clipboardText = await copyMessageContent(hud, message);
  ok(true, "Clipboard text was found and saved");

  info("Check copied text for stack trace message");
  lines = clipboardText.split("\n");
  is(lines.length, 4, "There are 4 lines in the copied text");
  is(lines[3], "", "The last line is an empty new line");
  ok(LOG_FORMAT_WITHOUT_TIMESTAMP.test(lines[0]),
    "Log line has the right format:\n" + lines[0]);
  ok(TRACE_FORMAT.test(lines[1]), "Stacktrace line has the right format:\n" + lines[1]);
  ok(TRACE_FORMAT.test(lines[2]), "Stacktrace line has the right format:\n" + lines[2]);

  info("Test copy menu item for the error message");
  message = await waitFor(() => findMessage(hud, "Error:"));
  clipboardText = await copyMessageContent(hud, message);
  ok(true, "Clipboard text was found and saved");
  lines = clipboardText.split("\n");
  is(lines[0], `Error: "error object"`, "Error object first line has expected text");
  ok(lines[1].startsWith(`\twrapper data:text/html`),
    "Error stacktrace first line starts with expected value:\n" + lines[1]);
  ok(lines[2].startsWith(`\tlogStuff data:text/html`),
    "Error stacktrace second line starts with expected value:\n" + lines[2]);

  observer.destroy();
  Services.prefs.clearUserPref(PREF_MESSAGE_TIMESTAMP);
});