browser/devtools/webconsole/test/browser_bug_638949_copy_link_location.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_bug_638949_copy_link_location.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/" +
    1.10 +  "test/test-console.html?_date=" + Date.now();
    1.11 +const COMMAND_NAME = "consoleCmd_copyURL";
    1.12 +const CONTEXT_MENU_ID = "#menu_copyURL";
    1.13 +
    1.14 +let HUD = null;
    1.15 +let output = null;
    1.16 +let menu = null;
    1.17 +
    1.18 +function test() {
    1.19 +  let originalNetPref = Services.prefs.getBoolPref("devtools.webconsole.filter.networkinfo");
    1.20 +  registerCleanupFunction(() => {
    1.21 +    Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", originalNetPref);
    1.22 +    HUD = output = menu = null;
    1.23 +  });
    1.24 +
    1.25 +  Services.prefs.setBoolPref("devtools.webconsole.filter.networkinfo", true);
    1.26 +
    1.27 +  addTab(TEST_URI);
    1.28 +  browser.addEventListener("load", function onLoad() {
    1.29 +    browser.removeEventListener("load", onLoad, true);
    1.30 +
    1.31 +    openConsole(null, function (aHud) {
    1.32 +      HUD = aHud;
    1.33 +      output = aHud.outputNode;
    1.34 +      menu = HUD.iframeWindow.document.getElementById("output-contextmenu");
    1.35 +
    1.36 +      executeSoon(testWithoutNetActivity);
    1.37 +    });
    1.38 +  }, true);
    1.39 +}
    1.40 +
    1.41 +// Return whether "Copy Link Location" command is enabled or not.
    1.42 +function isEnabled() {
    1.43 +  let controller = top.document.commandDispatcher
    1.44 +                   .getControllerForCommand(COMMAND_NAME);
    1.45 +  return controller && controller.isCommandEnabled(COMMAND_NAME);
    1.46 +}
    1.47 +
    1.48 +function testWithoutNetActivity() {
    1.49 +  HUD.jsterm.clearOutput();
    1.50 +  content.console.log("bug 638949");
    1.51 +
    1.52 +  // Test that the "Copy Link Location" command is disabled for non-network
    1.53 +  // messages.
    1.54 +  waitForMessages({
    1.55 +    webconsole: HUD,
    1.56 +    messages: [{
    1.57 +      text: "bug 638949",
    1.58 +      category: CATEGORY_WEBDEV,
    1.59 +      severity: SEVERITY_LOG,
    1.60 +    }],
    1.61 +  }).then(onConsoleMessage);
    1.62 +}
    1.63 +
    1.64 +function onConsoleMessage(aResults) {
    1.65 +  output.focus();
    1.66 +  let message = [...aResults[0].matched][0];
    1.67 +
    1.68 +  goUpdateCommand(COMMAND_NAME);
    1.69 +  ok(!isEnabled(), COMMAND_NAME + "is disabled");
    1.70 +
    1.71 +  // Test that the "Copy Link Location" menu item is hidden for non-network
    1.72 +  // messages.
    1.73 +  message.scrollIntoView();
    1.74 +  waitForContextMenu(menu, message, () => {
    1.75 +    let isHidden = menu.querySelector(CONTEXT_MENU_ID).hidden;
    1.76 +    ok(isHidden, CONTEXT_MENU_ID + " is hidden");
    1.77 +  }, testWithNetActivity);
    1.78 +}
    1.79 +
    1.80 +function testWithNetActivity() {
    1.81 +  HUD.jsterm.clearOutput();
    1.82 +  content.location.reload(); // Reloading will produce network logging
    1.83 +
    1.84 +  // Test that the "Copy Link Location" command is enabled and works
    1.85 +  // as expected for any network-related message.
    1.86 +  // This command should copy only the URL.
    1.87 +  waitForMessages({
    1.88 +    webconsole: HUD,
    1.89 +    messages: [{
    1.90 +      text: "test-console.html",
    1.91 +      category: CATEGORY_NETWORK,
    1.92 +      severity: SEVERITY_LOG,
    1.93 +    }],
    1.94 +  }).then(onNetworkMessage);
    1.95 +}
    1.96 +
    1.97 +function onNetworkMessage(aResults) {
    1.98 +  output.focus();
    1.99 +  let message = [...aResults[0].matched][0];
   1.100 +  HUD.ui.output.selectMessage(message);
   1.101 +
   1.102 +  goUpdateCommand(COMMAND_NAME);
   1.103 +  ok(isEnabled(), COMMAND_NAME + " is enabled");
   1.104 +
   1.105 +  info("expected clipboard value: " + message.url);
   1.106 +
   1.107 +  waitForClipboard((aData) => { return aData.trim() == message.url; },
   1.108 +    () => { goDoCommand(COMMAND_NAME) },
   1.109 +    testMenuWithNetActivity, testMenuWithNetActivity);
   1.110 +
   1.111 +  function testMenuWithNetActivity() {
   1.112 +    // Test that the "Copy Link Location" menu item is visible for network-related
   1.113 +    // messages.
   1.114 +    message.scrollIntoView();
   1.115 +    waitForContextMenu(menu, message, () => {
   1.116 +      let isVisible = !menu.querySelector(CONTEXT_MENU_ID).hidden;
   1.117 +      ok(isVisible, CONTEXT_MENU_ID + " is visible");
   1.118 +    }, finishTest);
   1.119 +  }
   1.120 +}
   1.121 +

mercurial