michael@0: /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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: let doc; michael@0: let div1; michael@0: let div2; michael@0: let iframe1; michael@0: let iframe2; michael@0: let inspector; michael@0: michael@0: function createDocument() { michael@0: doc.title = "Inspector iframe Tests"; michael@0: michael@0: iframe1 = doc.createElement('iframe'); michael@0: michael@0: iframe1.addEventListener("load", function () { michael@0: iframe1.removeEventListener("load", arguments.callee, false); michael@0: michael@0: div1 = iframe1.contentDocument.createElement('div'); michael@0: div1.textContent = 'little div'; michael@0: iframe1.contentDocument.body.appendChild(div1); michael@0: michael@0: iframe2 = iframe1.contentDocument.createElement('iframe'); michael@0: michael@0: iframe2.addEventListener('load', function () { michael@0: iframe2.removeEventListener("load", arguments.callee, false); michael@0: michael@0: div2 = iframe2.contentDocument.createElement('div'); michael@0: div2.textContent = 'nested div'; michael@0: iframe2.contentDocument.body.appendChild(div2); michael@0: michael@0: // Open the inspector, start the picker mode, and start the tests michael@0: openInspector(aInspector => { michael@0: inspector = aInspector; michael@0: inspector.toolbox.highlighterUtils.startPicker().then(runTests); michael@0: }); michael@0: }, false); michael@0: michael@0: iframe2.src = 'data:text/html,nested iframe'; michael@0: iframe1.contentDocument.body.appendChild(iframe2); michael@0: }, false); michael@0: michael@0: iframe1.src = 'data:text/html,little iframe'; michael@0: doc.body.appendChild(iframe1); michael@0: } michael@0: michael@0: function moveMouseOver(aElement, cb) { michael@0: inspector.toolbox.once("picker-node-hovered", cb); michael@0: EventUtils.synthesizeMouseAtCenter(aElement, {type: "mousemove"}, michael@0: aElement.ownerDocument.defaultView); michael@0: } michael@0: michael@0: function runTests() { michael@0: testDiv1Highlighter(); michael@0: } michael@0: michael@0: function testDiv1Highlighter() { michael@0: moveMouseOver(div1, () => { michael@0: is(getHighlitNode(), div1, "highlighter matches selection of div1"); michael@0: testDiv2Highlighter(); michael@0: }); michael@0: } michael@0: michael@0: function testDiv2Highlighter() { michael@0: moveMouseOver(div2, () => { michael@0: is(getHighlitNode(), div2, "highlighter matches selection of div2"); michael@0: selectRoot(); michael@0: }); michael@0: } michael@0: michael@0: function selectRoot() { michael@0: // Select the root document element to clear the breadcrumbs. michael@0: inspector.selection.setNode(doc.documentElement, null); michael@0: inspector.once("inspector-updated", selectIframe); michael@0: } michael@0: michael@0: function selectIframe() { michael@0: // Directly select an element in an iframe (without navigating to it michael@0: // with mousemoves). michael@0: inspector.selection.setNode(div2, null); michael@0: inspector.once("inspector-updated", () => { michael@0: let breadcrumbs = inspector.breadcrumbs; michael@0: is(breadcrumbs.nodeHierarchy.length, 9, "Should have 9 items"); michael@0: finishUp(); michael@0: }); michael@0: } michael@0: michael@0: function finishUp() { michael@0: inspector.toolbox.highlighterUtils.stopPicker().then(() => { michael@0: doc = div1 = div2 = iframe1 = iframe2 = inspector = null; michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.closeToolbox(target); michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); michael@0: doc = content.document; michael@0: gBrowser.selectedBrowser.focus(); michael@0: createDocument(); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,iframe tests for inspector"; michael@0: }