browser/devtools/netmonitor/test/browser_net_image-tooltip.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests if image responses show a popup in the requests menu when hovered.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL).then(([aTab, aDebuggee, aMonitor]) => {
michael@0 10 info("Starting test... ");
michael@0 11
michael@0 12 let { $, EVENTS, ACTIVITY_TYPE, NetMonitorView, NetMonitorController } = aMonitor.panelWin;
michael@0 13 let { RequestsMenu } = NetMonitorView;
michael@0 14
michael@0 15 promise.all([
michael@0 16 waitForNetworkEvents(aMonitor, 6),
michael@0 17 waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
michael@0 18 ]).then(() => {
michael@0 19 info("Checking the image thumbnail after a few requests were made...");
michael@0 20 let requestItem = RequestsMenu.items[5];
michael@0 21 let requestTooltip = requestItem.attachment.tooltip;
michael@0 22 ok(requestTooltip, "There should be a tooltip instance for the image request.");
michael@0 23
michael@0 24 let anchor = $(".requests-menu-file", requestItem.target);
michael@0 25 return showTooltipOn(requestTooltip, anchor);
michael@0 26 }).then(aTooltip => {
michael@0 27 ok(true,
michael@0 28 "An tooltip was successfully opened for the image request.");
michael@0 29 is(aTooltip.content.querySelector("image").src, TEST_IMAGE_DATA_URI,
michael@0 30 "The tooltip's image content is displayed correctly.");
michael@0 31
michael@0 32 info("Reloading the debuggee and performing all requests again...");
michael@0 33 reloadAndPerformRequests();
michael@0 34
michael@0 35 return promise.all([
michael@0 36 waitForNetworkEvents(aMonitor, 7), // 6 + 1
michael@0 37 waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
michael@0 38 ]);
michael@0 39 }).then(() => {
michael@0 40 info("Checking the image thumbnail after a reload.");
michael@0 41 let requestItem = RequestsMenu.items[6];
michael@0 42 let requestTooltip = requestItem.attachment.tooltip;
michael@0 43 ok(requestTooltip, "There should be a tooltip instance for the image request.");
michael@0 44
michael@0 45 let anchor = $(".requests-menu-file", requestItem.target);
michael@0 46 return showTooltipOn(requestTooltip, anchor);
michael@0 47 }).then(aTooltip => {
michael@0 48 ok(true,
michael@0 49 "An tooltip was successfully opened for the image request.");
michael@0 50 is(aTooltip.content.querySelector("image").src, TEST_IMAGE_DATA_URI,
michael@0 51 "The tooltip's image content is displayed correctly.");
michael@0 52
michael@0 53 teardown(aMonitor).then(finish);
michael@0 54 });
michael@0 55
michael@0 56 function reloadAndPerformRequests() {
michael@0 57 NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED).then(() => {
michael@0 58 aDebuggee.performRequests();
michael@0 59 });
michael@0 60 }
michael@0 61
michael@0 62 /**
michael@0 63 * @return a promise that resolves when the tooltip is shown
michael@0 64 */
michael@0 65 function showTooltipOn(tooltip, element) {
michael@0 66 return Task.spawn(function*() {
michael@0 67 let isTarget = yield tooltip.isValidHoverTarget(element);
michael@0 68 let onShown = tooltip.once("shown");
michael@0 69 tooltip.show();
michael@0 70 yield onShown;
michael@0 71 return tooltip;
michael@0 72 });
michael@0 73 }
michael@0 74
michael@0 75 aDebuggee.performRequests();
michael@0 76 });
michael@0 77 }

mercurial