1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/inspector/test/browser_inspector_iframeTest.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 1.4 +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +let doc; 1.11 +let div1; 1.12 +let div2; 1.13 +let iframe1; 1.14 +let iframe2; 1.15 +let inspector; 1.16 + 1.17 +function createDocument() { 1.18 + doc.title = "Inspector iframe Tests"; 1.19 + 1.20 + iframe1 = doc.createElement('iframe'); 1.21 + 1.22 + iframe1.addEventListener("load", function () { 1.23 + iframe1.removeEventListener("load", arguments.callee, false); 1.24 + 1.25 + div1 = iframe1.contentDocument.createElement('div'); 1.26 + div1.textContent = 'little div'; 1.27 + iframe1.contentDocument.body.appendChild(div1); 1.28 + 1.29 + iframe2 = iframe1.contentDocument.createElement('iframe'); 1.30 + 1.31 + iframe2.addEventListener('load', function () { 1.32 + iframe2.removeEventListener("load", arguments.callee, false); 1.33 + 1.34 + div2 = iframe2.contentDocument.createElement('div'); 1.35 + div2.textContent = 'nested div'; 1.36 + iframe2.contentDocument.body.appendChild(div2); 1.37 + 1.38 + // Open the inspector, start the picker mode, and start the tests 1.39 + openInspector(aInspector => { 1.40 + inspector = aInspector; 1.41 + inspector.toolbox.highlighterUtils.startPicker().then(runTests); 1.42 + }); 1.43 + }, false); 1.44 + 1.45 + iframe2.src = 'data:text/html,nested iframe'; 1.46 + iframe1.contentDocument.body.appendChild(iframe2); 1.47 + }, false); 1.48 + 1.49 + iframe1.src = 'data:text/html,little iframe'; 1.50 + doc.body.appendChild(iframe1); 1.51 +} 1.52 + 1.53 +function moveMouseOver(aElement, cb) { 1.54 + inspector.toolbox.once("picker-node-hovered", cb); 1.55 + EventUtils.synthesizeMouseAtCenter(aElement, {type: "mousemove"}, 1.56 + aElement.ownerDocument.defaultView); 1.57 +} 1.58 + 1.59 +function runTests() { 1.60 + testDiv1Highlighter(); 1.61 +} 1.62 + 1.63 +function testDiv1Highlighter() { 1.64 + moveMouseOver(div1, () => { 1.65 + is(getHighlitNode(), div1, "highlighter matches selection of div1"); 1.66 + testDiv2Highlighter(); 1.67 + }); 1.68 +} 1.69 + 1.70 +function testDiv2Highlighter() { 1.71 + moveMouseOver(div2, () => { 1.72 + is(getHighlitNode(), div2, "highlighter matches selection of div2"); 1.73 + selectRoot(); 1.74 + }); 1.75 +} 1.76 + 1.77 +function selectRoot() { 1.78 + // Select the root document element to clear the breadcrumbs. 1.79 + inspector.selection.setNode(doc.documentElement, null); 1.80 + inspector.once("inspector-updated", selectIframe); 1.81 +} 1.82 + 1.83 +function selectIframe() { 1.84 + // Directly select an element in an iframe (without navigating to it 1.85 + // with mousemoves). 1.86 + inspector.selection.setNode(div2, null); 1.87 + inspector.once("inspector-updated", () => { 1.88 + let breadcrumbs = inspector.breadcrumbs; 1.89 + is(breadcrumbs.nodeHierarchy.length, 9, "Should have 9 items"); 1.90 + finishUp(); 1.91 + }); 1.92 +} 1.93 + 1.94 +function finishUp() { 1.95 + inspector.toolbox.highlighterUtils.stopPicker().then(() => { 1.96 + doc = div1 = div2 = iframe1 = iframe2 = inspector = null; 1.97 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.98 + gDevTools.closeToolbox(target); 1.99 + gBrowser.removeCurrentTab(); 1.100 + finish(); 1.101 + }); 1.102 +} 1.103 + 1.104 +function test() { 1.105 + waitForExplicitFinish(); 1.106 + 1.107 + gBrowser.selectedTab = gBrowser.addTab(); 1.108 + gBrowser.selectedBrowser.addEventListener("load", function() { 1.109 + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); 1.110 + doc = content.document; 1.111 + gBrowser.selectedBrowser.focus(); 1.112 + createDocument(); 1.113 + }, true); 1.114 + 1.115 + content.location = "data:text/html,iframe tests for inspector"; 1.116 +}