browser/components/tabview/test/browser_tabview_bug600645.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  * This file tests that, when there is an app tab that references an invalid
     6  * favicon, the default favicon appears the group app tab tray, instead of an
     7  * empty image that would not be visible.
     8  */
    10 const fi = Cc["@mozilla.org/browser/favicon-service;1"].
    11            getService(Ci.nsIFaviconService);
    13 let newTab;
    15 function test() {
    16   waitForExplicitFinish();
    18   newTab = gBrowser.addTab();
    20   showTabView(function() {
    21     let cw = TabView.getContentWindow();
    22     whenAppTabIconAdded(cw.GroupItems.groupItems[0], onTabPinned);
    23     gBrowser.pinTab(newTab);
    24   })
    25 }
    27 function onTabPinned() {
    28   let contentWindow = TabView.getContentWindow();
    29   is(contentWindow.GroupItems.groupItems.length, 1, 
    30      "There is one group item on startup");
    32   let groupItem = contentWindow.GroupItems.groupItems[0];
    33   let icon = contentWindow.iQ(".appTabIcon", groupItem.$appTabTray)[0];
    34   let $icon = contentWindow.iQ(icon);
    36   is($icon.data("xulTab"), newTab, 
    37      "The app tab icon has the right tab reference")
    38   // check to see whether it's showing the default one or not.
    39   is($icon.attr("src"), fi.defaultFavicon.spec,
    40      "The icon is showing the default fav icon for blank tab");
    42   let errorHandler = function(event) {
    43     newTab.removeEventListener("error", errorHandler, false);
    45     // since the browser code and test code are invoked when an error event is 
    46     // fired, a delay is used here to avoid the test code run before the browser 
    47     // code.
    48     executeSoon(function() {
    49       let iconSrc = $icon.attr("src");
    51       // with moz-anno:favicon automatically redirects to the default favIcon 
    52       // if the given url is invalid
    53       ok(iconSrc.startsWith("moz-anno:favicon:"),
    54          "The icon url starts with moz-anno:favicon so the default fav icon would be displayed");
    56       // At this point, as an additional integrity check we could also verify
    57       // that the iconSrc URI does not have any associated favicon data.  This
    58       // kind of check, however, is not easily supported by the asynchronous
    59       // favicon API.  Fortunately, the fact that we received the error event
    60       // already indicates that the original favicon was not available.
    61       // Morevover, since we are using a "moz-anno:favicon:" URI, we know that
    62       // we'll not display an empty icon, but the default favicon.
    64       // clean up
    65       gBrowser.removeTab(newTab);
    66       let endGame = function() {
    67         window.removeEventListener("tabviewhidden", endGame, false);
    69         ok(!TabView.isVisible(), "Tab View is hidden");
    70         finish();
    71       }
    72       window.addEventListener("tabviewhidden", endGame, false);
    73       TabView.toggle();
    74     });
    75   };
    76   newTab.addEventListener("error", errorHandler, false);
    78   newTab.linkedBrowser.loadURI(
    79     "http://mochi.test:8888/browser/browser/components/tabview/test/test_bug600645.html");
    80 }

mercurial