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.

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

mercurial