browser/devtools/netmonitor/test/browser_net_image-tooltip.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/test/browser_net_image-tooltip.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if image responses show a popup in the requests menu when hovered.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.13 +    info("Starting test... ");
    1.14 +
    1.15 +    let { $, EVENTS, ACTIVITY_TYPE, NetMonitorView, NetMonitorController } = aMonitor.panelWin;
    1.16 +    let { RequestsMenu } = NetMonitorView;
    1.17 +
    1.18 +    promise.all([
    1.19 +      waitForNetworkEvents(aMonitor, 6),
    1.20 +      waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
    1.21 +    ]).then(() => {
    1.22 +      info("Checking the image thumbnail after a few requests were made...");
    1.23 +      let requestItem = RequestsMenu.items[5];
    1.24 +      let requestTooltip = requestItem.attachment.tooltip;
    1.25 +      ok(requestTooltip, "There should be a tooltip instance for the image request.");
    1.26 +
    1.27 +      let anchor = $(".requests-menu-file", requestItem.target);
    1.28 +      return showTooltipOn(requestTooltip, anchor);
    1.29 +    }).then(aTooltip => {
    1.30 +      ok(true,
    1.31 +        "An tooltip was successfully opened for the image request.");
    1.32 +      is(aTooltip.content.querySelector("image").src, TEST_IMAGE_DATA_URI,
    1.33 +        "The tooltip's image content is displayed correctly.");
    1.34 +
    1.35 +      info("Reloading the debuggee and performing all requests again...");
    1.36 +      reloadAndPerformRequests();
    1.37 +
    1.38 +      return promise.all([
    1.39 +        waitForNetworkEvents(aMonitor, 7), // 6 + 1
    1.40 +        waitFor(aMonitor.panelWin, EVENTS.RESPONSE_IMAGE_THUMBNAIL_DISPLAYED)
    1.41 +      ]);
    1.42 +    }).then(() => {
    1.43 +      info("Checking the image thumbnail after a reload.");
    1.44 +      let requestItem = RequestsMenu.items[6];
    1.45 +      let requestTooltip = requestItem.attachment.tooltip;
    1.46 +      ok(requestTooltip, "There should be a tooltip instance for the image request.");
    1.47 +
    1.48 +      let anchor = $(".requests-menu-file", requestItem.target);
    1.49 +      return showTooltipOn(requestTooltip, anchor);
    1.50 +    }).then(aTooltip => {
    1.51 +      ok(true,
    1.52 +        "An tooltip was successfully opened for the image request.");
    1.53 +      is(aTooltip.content.querySelector("image").src, TEST_IMAGE_DATA_URI,
    1.54 +        "The tooltip's image content is displayed correctly.");
    1.55 +
    1.56 +      teardown(aMonitor).then(finish);
    1.57 +    });
    1.58 +
    1.59 +    function reloadAndPerformRequests() {
    1.60 +      NetMonitorController.triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_ENABLED).then(() => {
    1.61 +        aDebuggee.performRequests();
    1.62 +      });
    1.63 +    }
    1.64 +
    1.65 +    /**
    1.66 +     * @return a promise that resolves when the tooltip is shown
    1.67 +     */
    1.68 +    function showTooltipOn(tooltip, element) {
    1.69 +      return Task.spawn(function*() {
    1.70 +        let isTarget = yield tooltip.isValidHoverTarget(element);
    1.71 +        let onShown = tooltip.once("shown");
    1.72 +        tooltip.show();
    1.73 +        yield onShown;
    1.74 +        return tooltip;
    1.75 +      });
    1.76 +    }
    1.77 +
    1.78 +    aDebuggee.performRequests();
    1.79 +  });
    1.80 +}

mercurial