browser/devtools/inspector/test/browser_inspector_iframeTest.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 div1;
michael@0 9 let div2;
michael@0 10 let iframe1;
michael@0 11 let iframe2;
michael@0 12 let inspector;
michael@0 13
michael@0 14 function createDocument() {
michael@0 15 doc.title = "Inspector iframe Tests";
michael@0 16
michael@0 17 iframe1 = doc.createElement('iframe');
michael@0 18
michael@0 19 iframe1.addEventListener("load", function () {
michael@0 20 iframe1.removeEventListener("load", arguments.callee, false);
michael@0 21
michael@0 22 div1 = iframe1.contentDocument.createElement('div');
michael@0 23 div1.textContent = 'little div';
michael@0 24 iframe1.contentDocument.body.appendChild(div1);
michael@0 25
michael@0 26 iframe2 = iframe1.contentDocument.createElement('iframe');
michael@0 27
michael@0 28 iframe2.addEventListener('load', function () {
michael@0 29 iframe2.removeEventListener("load", arguments.callee, false);
michael@0 30
michael@0 31 div2 = iframe2.contentDocument.createElement('div');
michael@0 32 div2.textContent = 'nested div';
michael@0 33 iframe2.contentDocument.body.appendChild(div2);
michael@0 34
michael@0 35 // Open the inspector, start the picker mode, and start the tests
michael@0 36 openInspector(aInspector => {
michael@0 37 inspector = aInspector;
michael@0 38 inspector.toolbox.highlighterUtils.startPicker().then(runTests);
michael@0 39 });
michael@0 40 }, false);
michael@0 41
michael@0 42 iframe2.src = 'data:text/html,nested iframe';
michael@0 43 iframe1.contentDocument.body.appendChild(iframe2);
michael@0 44 }, false);
michael@0 45
michael@0 46 iframe1.src = 'data:text/html,little iframe';
michael@0 47 doc.body.appendChild(iframe1);
michael@0 48 }
michael@0 49
michael@0 50 function moveMouseOver(aElement, cb) {
michael@0 51 inspector.toolbox.once("picker-node-hovered", cb);
michael@0 52 EventUtils.synthesizeMouseAtCenter(aElement, {type: "mousemove"},
michael@0 53 aElement.ownerDocument.defaultView);
michael@0 54 }
michael@0 55
michael@0 56 function runTests() {
michael@0 57 testDiv1Highlighter();
michael@0 58 }
michael@0 59
michael@0 60 function testDiv1Highlighter() {
michael@0 61 moveMouseOver(div1, () => {
michael@0 62 is(getHighlitNode(), div1, "highlighter matches selection of div1");
michael@0 63 testDiv2Highlighter();
michael@0 64 });
michael@0 65 }
michael@0 66
michael@0 67 function testDiv2Highlighter() {
michael@0 68 moveMouseOver(div2, () => {
michael@0 69 is(getHighlitNode(), div2, "highlighter matches selection of div2");
michael@0 70 selectRoot();
michael@0 71 });
michael@0 72 }
michael@0 73
michael@0 74 function selectRoot() {
michael@0 75 // Select the root document element to clear the breadcrumbs.
michael@0 76 inspector.selection.setNode(doc.documentElement, null);
michael@0 77 inspector.once("inspector-updated", selectIframe);
michael@0 78 }
michael@0 79
michael@0 80 function selectIframe() {
michael@0 81 // Directly select an element in an iframe (without navigating to it
michael@0 82 // with mousemoves).
michael@0 83 inspector.selection.setNode(div2, null);
michael@0 84 inspector.once("inspector-updated", () => {
michael@0 85 let breadcrumbs = inspector.breadcrumbs;
michael@0 86 is(breadcrumbs.nodeHierarchy.length, 9, "Should have 9 items");
michael@0 87 finishUp();
michael@0 88 });
michael@0 89 }
michael@0 90
michael@0 91 function finishUp() {
michael@0 92 inspector.toolbox.highlighterUtils.stopPicker().then(() => {
michael@0 93 doc = div1 = div2 = iframe1 = iframe2 = inspector = null;
michael@0 94 let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 95 gDevTools.closeToolbox(target);
michael@0 96 gBrowser.removeCurrentTab();
michael@0 97 finish();
michael@0 98 });
michael@0 99 }
michael@0 100
michael@0 101 function test() {
michael@0 102 waitForExplicitFinish();
michael@0 103
michael@0 104 gBrowser.selectedTab = gBrowser.addTab();
michael@0 105 gBrowser.selectedBrowser.addEventListener("load", function() {
michael@0 106 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 107 doc = content.document;
michael@0 108 gBrowser.selectedBrowser.focus();
michael@0 109 createDocument();
michael@0 110 }, true);
michael@0 111
michael@0 112 content.location = "data:text/html,iframe tests for inspector";
michael@0 113 }

mercurial