browser/devtools/inspector/test/browser_inspector_basic_highlighter.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function test() {
michael@0 6 let inspector, doc, toolbox;
michael@0 7 let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
michael@0 8 let {require} = devtools;
michael@0 9 let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
michael@0 10 let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
michael@0 11
michael@0 12 waitForExplicitFinish();
michael@0 13
michael@0 14 gBrowser.selectedTab = gBrowser.addTab();
michael@0 15 gBrowser.selectedBrowser.addEventListener("load", function onload() {
michael@0 16 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
michael@0 17 doc = content.document;
michael@0 18 waitForFocus(setupTest, content);
michael@0 19 }, true);
michael@0 20
michael@0 21 content.location = "data:text/html;charset=utf-8,<h1>foo</h1><span>bar</span>";
michael@0 22
michael@0 23 function setupTest() {
michael@0 24 openInspector((aInspector, aToolbox) => {
michael@0 25 toolbox = aToolbox;
michael@0 26 inspector = aInspector;
michael@0 27 inspector.selection.setNode(doc.querySelector("span"), "test");
michael@0 28 inspector.toolbox.once("highlighter-ready", runTests);
michael@0 29 });
michael@0 30 }
michael@0 31
michael@0 32 function runTests() {
michael@0 33 Task.spawn(function() {
michael@0 34 yield hoverH1InMarkupView();
michael@0 35 yield assertH1Highlighted();
michael@0 36
michael@0 37 finishUp();
michael@0 38 }).then(null, Cu.reportError);
michael@0 39 }
michael@0 40
michael@0 41 function hoverH1InMarkupView() {
michael@0 42 let deferred = promise.defer();
michael@0 43 let container = getContainerForRawNode(inspector.markup, doc.querySelector("h1"));
michael@0 44
michael@0 45 inspector.toolbox.once("highlighter-ready", deferred.resolve);
michael@0 46 EventUtils.synthesizeMouseAtCenter(container.tagLine, {type: "mousemove"},
michael@0 47 inspector.markup.doc.defaultView);
michael@0 48
michael@0 49 return deferred.promise;
michael@0 50 }
michael@0 51
michael@0 52 function assertH1Highlighted() {
michael@0 53 ok(isHighlighting(), "The highlighter is shown on a markup container hover");
michael@0 54 is(getHighlitNode(), doc.querySelector("h1"), "The highlighter highlights the right node");
michael@0 55 }
michael@0 56
michael@0 57 function finishUp() {
michael@0 58 inspector = doc = toolbox = null;
michael@0 59 gBrowser.removeCurrentTab();
michael@0 60 finish();
michael@0 61 }
michael@0 62 }

mercurial