browser/devtools/inspector/test/browser_inspector_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 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 let doc;
michael@0 8 let h1;
michael@0 9 let inspector;
michael@0 10
michael@0 11 function createDocument() {
michael@0 12 let div = doc.createElement("div");
michael@0 13 h1 = doc.createElement("h1");
michael@0 14 let p1 = doc.createElement("p");
michael@0 15 let p2 = doc.createElement("p");
michael@0 16 let div2 = doc.createElement("div");
michael@0 17 let p3 = doc.createElement("p");
michael@0 18 doc.title = "Inspector Highlighter Meatballs";
michael@0 19 h1.textContent = "Inspector Tree Selection Test";
michael@0 20 p1.textContent = "This is some example text";
michael@0 21 p2.textContent = "Lorem ipsum dolor sit amet, consectetur adipisicing " +
michael@0 22 "elit, sed do eiusmod tempor incididunt ut labore et dolore magna " +
michael@0 23 "aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
michael@0 24 "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " +
michael@0 25 "dolor in reprehenderit in voluptate velit esse cillum dolore eu " +
michael@0 26 "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " +
michael@0 27 "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
michael@0 28 p3.textContent = "Lorem ipsum dolor sit amet, consectetur adipisicing " +
michael@0 29 "elit, sed do eiusmod tempor incididunt ut labore et dolore magna " +
michael@0 30 "aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
michael@0 31 "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " +
michael@0 32 "dolor in reprehenderit in voluptate velit esse cillum dolore eu " +
michael@0 33 "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " +
michael@0 34 "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
michael@0 35 let div3 = doc.createElement("div");
michael@0 36 div3.id = "checkOutThisWickedSpread";
michael@0 37 div3.setAttribute("style", "position: absolute; top: 20px; right: 20px; height: 20px; width: 20px; background-color: yellow; border: 1px dashed black;");
michael@0 38 let p4 = doc.createElement("p");
michael@0 39 p4.setAttribute("style", "font-weight: 200; font-size: 8px; text-align: center;");
michael@0 40 p4.textContent = "Smörgåsbord!";
michael@0 41 div.appendChild(h1);
michael@0 42 div.appendChild(p1);
michael@0 43 div.appendChild(p2);
michael@0 44 div2.appendChild(p3);
michael@0 45 div3.appendChild(p4);
michael@0 46 doc.body.appendChild(div);
michael@0 47 doc.body.appendChild(div2);
michael@0 48 doc.body.appendChild(div3);
michael@0 49
michael@0 50 openInspector(aInspector => {
michael@0 51 inspector = aInspector;
michael@0 52 inspector.selection.setNode(div, null);
michael@0 53 inspector.once("inspector-updated", () => {
michael@0 54 inspector.toolbox.highlighterUtils.startPicker().then(testMouseOverH1Highlights);
michael@0 55 });
michael@0 56 });
michael@0 57 }
michael@0 58
michael@0 59 function testMouseOverH1Highlights() {
michael@0 60 inspector.toolbox.once("highlighter-ready", () => {
michael@0 61 ok(isHighlighting(), "Highlighter is shown");
michael@0 62 is(getHighlitNode(), h1, "Highlighter's outline correspond to the selected node");
michael@0 63 testBoxModelDimensions();
michael@0 64 });
michael@0 65
michael@0 66 EventUtils.synthesizeMouse(h1, 2, 2, {type: "mousemove"}, content);
michael@0 67 }
michael@0 68
michael@0 69 function testBoxModelDimensions() {
michael@0 70 let h1Dims = h1.getBoundingClientRect();
michael@0 71 let h1Width = Math.ceil(h1Dims.width);
michael@0 72 let h1Height = Math.ceil(h1Dims.height);
michael@0 73
michael@0 74 let outlineDims = getSimpleBorderRect();
michael@0 75 let outlineWidth = Math.ceil(outlineDims.width);
michael@0 76 let outlineHeight = Math.ceil(outlineDims.height);
michael@0 77
michael@0 78 // Disabled due to bug 716245
michael@0 79 is(outlineWidth, h1Width, "outline width matches dimensions of element (no zoom)");
michael@0 80 is(outlineHeight, h1Height, "outline height matches dimensions of element (no zoom)");
michael@0 81
michael@0 82 // zoom the page by a factor of 2
michael@0 83 let contentViewer = gBrowser.selectedBrowser.docShell.contentViewer
michael@0 84 .QueryInterface(Ci.nsIMarkupDocumentViewer);
michael@0 85 contentViewer.fullZoom = 2;
michael@0 86
michael@0 87 // simulate the zoomed dimensions of the div element
michael@0 88 let h1Dims = h1.getBoundingClientRect();
michael@0 89 // There seems to be some very minor differences in the floats, so let's
michael@0 90 // floor the values
michael@0 91 let h1Width = Math.floor(h1Dims.width * contentViewer.fullZoom);
michael@0 92 let h1Height = Math.floor(h1Dims.height * contentViewer.fullZoom);
michael@0 93
michael@0 94 let outlineDims = getSimpleBorderRect();
michael@0 95 let outlineWidth = Math.floor(outlineDims.width);
michael@0 96 let outlineHeight = Math.floor(outlineDims.height);
michael@0 97
michael@0 98 is(outlineWidth, h1Width, "outline width matches dimensions of element (zoomed)");
michael@0 99
michael@0 100 is(outlineHeight, h1Height, "outline height matches dimensions of element (zoomed)");
michael@0 101
michael@0 102 executeSoon(finishUp);
michael@0 103 }
michael@0 104
michael@0 105 function finishUp() {
michael@0 106 inspector.toolbox.highlighterUtils.stopPicker().then(() => {
michael@0 107 doc = h1 = inspector = null;
michael@0 108 let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 109 gDevTools.closeToolbox(target);
michael@0 110 gBrowser.removeCurrentTab();
michael@0 111 finish();
michael@0 112 });
michael@0 113 }
michael@0 114
michael@0 115 function test() {
michael@0 116 waitForExplicitFinish();
michael@0 117 gBrowser.selectedTab = gBrowser.addTab();
michael@0 118 gBrowser.selectedBrowser.addEventListener("load", function() {
michael@0 119 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 120 doc = content.document;
michael@0 121 waitForFocus(createDocument, content);
michael@0 122 }, true);
michael@0 123
michael@0 124 content.location = "data:text/html;charset=utf-8,browser_inspector_highlighter.js";
michael@0 125 }

mercurial