|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +"use strict"; |
| 6 | + |
| 7 | +// Test that the node picker works while reloading a page with |
| 8 | +// an iframe going through an intermediate about:blank document |
| 9 | + |
| 10 | +const FRAME_URL = "https://example.com/document-builder.sjs?html=iframe"; |
| 11 | +const TEST_URL = |
| 12 | + `https://example.org/document-builder.sjs?html=` + |
| 13 | + encodeURI( |
| 14 | + `<h1>Pick target</h1><h2>Other element</h2><iframe></iframe><script>window.onload=()=>{document.querySelector("iframe").src = "${FRAME_URL}";}</script>` |
| 15 | + ); |
| 16 | + |
| 17 | +async function waitForIframeLoad() { |
| 18 | + const iframeBC = await SpecialPowers.spawn( |
| 19 | + gBrowser.selectedBrowser, |
| 20 | + [], |
| 21 | + function () { |
| 22 | + return content.document.querySelector("iframe").browsingContext; |
| 23 | + } |
| 24 | + ); |
| 25 | + await SpecialPowers.spawn(iframeBC, [FRAME_URL], async function (url) { |
| 26 | + if ( |
| 27 | + content.document.readyState == "complete" && |
| 28 | + content.location.href == url |
| 29 | + ) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + return new Promise(resolve => { |
| 33 | + content.addEventListener("load", resolve, { once: true }); |
| 34 | + }); |
| 35 | + }); |
| 36 | +} |
| 37 | + |
| 38 | +add_task(async () => { |
| 39 | + let { inspector, toolbox, highlighterTestFront } = |
| 40 | + await openInspectorForURL(TEST_URL); |
| 41 | + await waitForIframeLoad(); |
| 42 | + |
| 43 | + info( |
| 44 | + "Start the picker and hover an element to populate the picker hovered node reference" |
| 45 | + ); |
| 46 | + await startPicker(toolbox); |
| 47 | + await hoverElement(inspector, "iframe"); |
| 48 | + |
| 49 | + const HIGHLIGHTER_TYPE = inspector.highlighters.TYPES.BOXMODEL; |
| 50 | + const { getActiveHighlighter } = getHighlighterTestHelpers(inspector); |
| 51 | + |
| 52 | + ok(getActiveHighlighter(HIGHLIGHTER_TYPE), "Boxmodel highlighter is shown."); |
| 53 | + ok( |
| 54 | + await highlighterTestFront.assertHighlightedNode("iframe"), |
| 55 | + "The highlighter is shown on the expected node" |
| 56 | + ); |
| 57 | + |
| 58 | + // Do not wait for full reload as the faulty target for transient about:blank |
| 59 | + // document may already be destroyed and not cause troubles anymore |
| 60 | + const onReloaded = reloadSelectedTab(); |
| 61 | + |
| 62 | + // Bug 2003810: hovering during the navigation may throw error in the content process, |
| 63 | + // but this exception wouldn't make the test fail anyway. |
| 64 | + hoverElement(inspector, "h1"); |
| 65 | + |
| 66 | + await onReloaded; |
| 67 | + |
| 68 | + // As the previous hover may not complete, we have to do another one once the page is loaded |
| 69 | + await hoverElement(inspector, "h1"); |
| 70 | + ok(getActiveHighlighter(HIGHLIGHTER_TYPE), "Boxmodel highlighter is shown."); |
| 71 | + |
| 72 | + highlighterTestFront = await getHighlighterTestFront(toolbox); |
| 73 | + ok( |
| 74 | + await highlighterTestFront.assertHighlightedNode("h1"), |
| 75 | + "The highlighter is shown on the expected node" |
| 76 | + ); |
| 77 | + |
| 78 | + await stopPickerWithEscapeKey(toolbox); |
| 79 | + |
| 80 | + // Bug 2003810 highlighted that the toolbox couldn't be re-opened |
| 81 | + // as the broken, not correctly unregistered/disabled node-picker was keeping |
| 82 | + // its suppressedEventListener active and possibly disable all further key presses. |
| 83 | + // But there is no way to reproduce the exact same keypress event. |
| 84 | + // BrowserTestUtils.synthesizeKey/EventUtils.synthesizeNativeKey both seem to send the event only to the content. |
| 85 | + // And EventUtils.synthesizeKey doesn't, but avoids reproducing the regression. |
| 86 | + const onToolboxDestroyed = toolbox.once("destroyed"); |
| 87 | + info("Try to close the toolbox via a key shortcut"); |
| 88 | + if (Services.appinfo.OS == "Darwin") { |
| 89 | + EventUtils.synthesizeKey("i", { accelKey: true, altKey: true }); |
| 90 | + } else { |
| 91 | + EventUtils.synthesizeKey("i", { accelKey: true, shiftKey: true }); |
| 92 | + } |
| 93 | + await onToolboxDestroyed; |
| 94 | +}); |
0 commit comments