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.

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

mercurial