old_contents: /* See license.txt for terms of usage */
  
  "use strict";
  
  const { Cu } = require("chrome");
  const { loadFirebug } = require("./common.js");
  const { getMostRecentBrowserWindow } = require("sdk/window/utils");
  const { openTab, getBrowserForTab, closeTab } = require("sdk/tabs/utils");
  const { setTimeout } = require("sdk/timers");
  const { serve, host } = require("./httpd.js");
  
  const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
  
  const content =
    "<html><head></head><body><script>" +
    "console.log('hello')" +
    "</script></body></html>";
  
  exports["test Console clear button"] = function(assert, done) {
    let browser = getMostRecentBrowserWindow();
  
    let title = "testPage1";
    let url = host + title + ".html";
    let server = serve({ name: title, content: content });
  
    loadFirebug();
  
    let newTab = openTab(browser, url, {
      inBackground: false
    });
  
    let tabBrowser = getBrowserForTab(newTab);
    function onPageLoad() {
      tabBrowser.removeEventListener("load", onPageLoad, true);
  
      let panelId = "webconsole";
      let tool = browser.gDevTools.getToolDefinition(panelId);
      let target = devtools.TargetFactory.forTab(newTab);
  
      // Open toolbox with the Console panel selected.
      browser.gDevTools.showToolbox(target, panelId).then(function(toolbox) {
        let panel = toolbox.getCurrentPanel();
  
        let overlay = panel._firebugPanelOverlay;
        assert.ok(overlay, "The Console panel must be overlaid");
  
        let doc = overlay.getPanelDocument();
        let clearButton = doc.querySelector(".webconsole-clear-console-button");
        assert.ok(clearButton, "The clear button must exist");
  
        waitForMessage(panel, () => {
          let log = doc.querySelector(".message[category=console] .console-string");
          assert.ok(log, "There must be a log in the Console panel");
  
          overlay.clearConsole();
  
          log = doc.querySelector(".message[category=console] .console-string");
          assert.ok(!log, "There must not be a log in the Console panel");
  
          // Asynchronously clean up
          setTimeout(() => {
            server.stop(() => {
              closeTab(newTab);
              done();
            });
          })
        });
      });
    }
  
    tabBrowser.addEventListener("load", onPageLoad, true);
  };
  
  function waitForMessage(panel, callback) {
    let overlay = panel._firebugPanelOverlay;
    let doc = overlay.getPanelDocument();
    let log = doc.querySelector(".message[category=console] .console-string");
    if (log) {
      callback();
      return;
    }
  
    panel.hud.ui.once("new-messages", (event, messages) => {
      callback();
    });
  }
  
  require("sdk/test").run(exports);
  
new_contents: /* See license.txt for terms of usage */
  
  "use strict";
  
  const { Cu } = require("chrome");
  const { openToolbox } = require("./common.js");
  const { waitForMessage } = require("./console.js");
  
  // Content of the test page (one console log is coming from the content).
  const content =
    "<html><head></head><body><script>" +
    "console.log('hello')" +
    "</script></body></html>";
  
  exports["test Console clear button"] = function(assert, done) {
    // Configuration flags for toolbox opening.
    let config = {
      panelId: "webconsole",
      pageContent: content
    };
  
    // Start HTTP server, open new tab and the toolbox.
    openToolbox(config).then(({toolbox, cleanUp, overlay}) => {
      assert.ok(overlay, "The Console panel must be overlaid");
  
      let doc = overlay.getPanelDocument();
      let clearButton = doc.querySelector(".webconsole-clear-console-button");
      assert.ok(clearButton, "The clear button must exist");
  
      // Wait for console log.
      let config = {
        cssSelector: ".message[category=console] .console-string"
      };
  
      waitForMessage(toolbox, config).then(result => {
        assert.ok(true, "There must not be a log in the Console panel");
  
        overlay.clearConsole();
  
        let log = doc.querySelector(config.cssSelector);
        assert.ok(!log, "There must not be a log in the Console panel");
  
        cleanUp(done);
      });
    });
  };
  
  require("sdk/test").run(exports);
  
subject: simplify test for console clear (using new API)