browser/devtools/inspector/test/browser_inspector_basic_highlighter.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/inspector/test/browser_inspector_basic_highlighter.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function test() {
     1.9 +  let inspector, doc, toolbox;
    1.10 +  let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    1.11 +  let {require} = devtools;
    1.12 +  let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
    1.13 +  let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
    1.14 +
    1.15 +  waitForExplicitFinish();
    1.16 +
    1.17 +  gBrowser.selectedTab = gBrowser.addTab();
    1.18 +  gBrowser.selectedBrowser.addEventListener("load", function onload() {
    1.19 +    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
    1.20 +    doc = content.document;
    1.21 +    waitForFocus(setupTest, content);
    1.22 +  }, true);
    1.23 +
    1.24 +  content.location = "data:text/html;charset=utf-8,<h1>foo</h1><span>bar</span>";
    1.25 +
    1.26 +  function setupTest() {
    1.27 +    openInspector((aInspector, aToolbox) => {
    1.28 +      toolbox = aToolbox;
    1.29 +      inspector = aInspector;
    1.30 +      inspector.selection.setNode(doc.querySelector("span"), "test");
    1.31 +      inspector.toolbox.once("highlighter-ready", runTests);
    1.32 +    });
    1.33 +  }
    1.34 +
    1.35 +  function runTests() {
    1.36 +    Task.spawn(function() {
    1.37 +      yield hoverH1InMarkupView();
    1.38 +      yield assertH1Highlighted();
    1.39 +
    1.40 +      finishUp();
    1.41 +    }).then(null, Cu.reportError);
    1.42 +  }
    1.43 +
    1.44 +  function hoverH1InMarkupView() {
    1.45 +    let deferred = promise.defer();
    1.46 +    let container = getContainerForRawNode(inspector.markup, doc.querySelector("h1"));
    1.47 +
    1.48 +    inspector.toolbox.once("highlighter-ready", deferred.resolve);
    1.49 +    EventUtils.synthesizeMouseAtCenter(container.tagLine, {type: "mousemove"},
    1.50 +                                       inspector.markup.doc.defaultView);
    1.51 +
    1.52 +    return deferred.promise;
    1.53 +  }
    1.54 +
    1.55 +  function assertH1Highlighted() {
    1.56 +    ok(isHighlighting(), "The highlighter is shown on a markup container hover");
    1.57 +    is(getHighlitNode(), doc.querySelector("h1"), "The highlighter highlights the right node");
    1.58 +  }
    1.59 +
    1.60 +  function finishUp() {
    1.61 +    inspector = doc = toolbox = null;
    1.62 +    gBrowser.removeCurrentTab();
    1.63 +    finish();
    1.64 +  }
    1.65 +}

mercurial