michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0:
michael@0: function test() {
michael@0: let inspector, doc, toolbox;
michael@0: let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
michael@0: let {require} = devtools;
michael@0: let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
michael@0: let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
michael@0:
michael@0: waitForExplicitFinish();
michael@0:
michael@0: gBrowser.selectedTab = gBrowser.addTab();
michael@0: gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0: gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0: doc = content.document;
michael@0: waitForFocus(setupTest, content);
michael@0: }, true);
michael@0:
michael@0: content.location = "data:text/html;charset=utf-8,
foo
bar";
michael@0:
michael@0: function setupTest() {
michael@0: openInspector((aInspector, aToolbox) => {
michael@0: toolbox = aToolbox;
michael@0: inspector = aInspector;
michael@0: inspector.selection.setNode(doc.querySelector("span"), "test");
michael@0: inspector.toolbox.once("highlighter-ready", runTests);
michael@0: });
michael@0: }
michael@0:
michael@0: function runTests() {
michael@0: Task.spawn(function() {
michael@0: yield hoverH1InMarkupView();
michael@0: yield assertH1Highlighted();
michael@0:
michael@0: finishUp();
michael@0: }).then(null, Cu.reportError);
michael@0: }
michael@0:
michael@0: function hoverH1InMarkupView() {
michael@0: let deferred = promise.defer();
michael@0: let container = getContainerForRawNode(inspector.markup, doc.querySelector("h1"));
michael@0:
michael@0: inspector.toolbox.once("highlighter-ready", deferred.resolve);
michael@0: EventUtils.synthesizeMouseAtCenter(container.tagLine, {type: "mousemove"},
michael@0: inspector.markup.doc.defaultView);
michael@0:
michael@0: return deferred.promise;
michael@0: }
michael@0:
michael@0: function assertH1Highlighted() {
michael@0: ok(isHighlighting(), "The highlighter is shown on a markup container hover");
michael@0: is(getHighlitNode(), doc.querySelector("h1"), "The highlighter highlights the right node");
michael@0: }
michael@0:
michael@0: function finishUp() {
michael@0: inspector = doc = toolbox = null;
michael@0: gBrowser.removeCurrentTab();
michael@0: finish();
michael@0: }
michael@0: }