michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if image responses show a popup in the requests menu when hovered. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let { $, EVENTS, ACTIVITY_TYPE, NetMonitorView, NetMonitorController } = aMonitor.panelWin; michael@0: let { RequestsMenu } = NetMonitorView; michael@0: michael@0: promise.all([ michael@0: waitForNetworkEvents(aMonitor, 6), michael@0: waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED) michael@0: ]).then(() => { michael@0: info("Checking the image thumbnail after a few requests were made..."); michael@0: let requestItem = RequestsMenu.items[5]; michael@0: let requestTooltip = requestItem.attachment.tooltip; michael@0: ok(requestTooltip, "There should be a tooltip instance for the image request."); michael@0: michael@0: let anchor = $(".requests-menu-file", requestItem.target); michael@0: return showTooltipOn(requestTooltip, anchor); michael@0: }).then(aTooltip => { michael@0: ok(true, michael@0: "An tooltip was successfully opened for the image request."); michael@0: is(aTooltip.content.querySelector("image").src, TEST_IMAGE_DATA_URI, michael@0: "The tooltip's image content is displayed correctly."); michael@0: michael@0: info("Reloading the debuggee and performing all requests again..."); michael@0: reloadAndPerformRequests(); michael@0: michael@0: return promise.all([ michael@0: waitForNetworkEvents(aMonitor, 7), // 6 + 1 michael@0: waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED) michael@0: ]); michael@0: }).then(() => { michael@0: info("Checking the image thumbnail after a reload."); michael@0: let requestItem = RequestsMenu.items[6]; michael@0: let requestTooltip = requestItem.attachment.tooltip; michael@0: ok(requestTooltip, "There should be a tooltip instance for the image request."); michael@0: michael@0: let anchor = $(".requests-menu-file", requestItem.target); michael@0: return showTooltipOn(requestTooltip, anchor); michael@0: }).then(aTooltip => { michael@0: ok(true, michael@0: "An tooltip was successfully opened for the image request."); michael@0: is(aTooltip.content.querySelector("image").src, TEST_IMAGE_DATA_URI, michael@0: "The tooltip's image content is displayed correctly."); michael@0: michael@0: teardown(aMonitor).then(finish); michael@0: }); michael@0: michael@0: function reloadAndPerformRequests() { michael@0: NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED).then(() => { michael@0: aDebuggee.performRequests(); michael@0: }); michael@0: } michael@0: michael@0: /** michael@0: * @return a promise that resolves when the tooltip is shown michael@0: */ michael@0: function showTooltipOn(tooltip, element) { michael@0: return Task.spawn(function*() { michael@0: let isTarget = yield tooltip.isValidHoverTarget(element); michael@0: let onShown = tooltip.once("shown"); michael@0: tooltip.show(); michael@0: yield onShown; michael@0: return tooltip; michael@0: }); michael@0: } michael@0: michael@0: aDebuggee.performRequests(); michael@0: }); michael@0: }