michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * This file tests that, when there is an app tab that references an invalid michael@0: * favicon, the default favicon appears the group app tab tray, instead of an michael@0: * empty image that would not be visible. michael@0: */ michael@0: michael@0: const fi = Cc["@mozilla.org/browser/favicon-service;1"]. michael@0: getService(Ci.nsIFaviconService); michael@0: michael@0: let newTab; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: newTab = gBrowser.addTab(); michael@0: michael@0: showTabView(function() { michael@0: let cw = TabView.getContentWindow(); michael@0: whenAppTabIconAdded(cw.GroupItems.groupItems[0], onTabPinned); michael@0: gBrowser.pinTab(newTab); michael@0: }) michael@0: } michael@0: michael@0: function onTabPinned() { michael@0: let contentWindow = TabView.getContentWindow(); michael@0: is(contentWindow.GroupItems.groupItems.length, 1, michael@0: "There is one group item on startup"); michael@0: michael@0: let groupItem = contentWindow.GroupItems.groupItems[0]; michael@0: let icon = contentWindow.iQ(".appTabIcon", groupItem.$appTabTray)[0]; michael@0: let $icon = contentWindow.iQ(icon); michael@0: michael@0: is($icon.data("xulTab"), newTab, michael@0: "The app tab icon has the right tab reference") michael@0: // check to see whether it's showing the default one or not. michael@0: is($icon.attr("src"), fi.defaultFavicon.spec, michael@0: "The icon is showing the default fav icon for blank tab"); michael@0: michael@0: let errorHandler = function(event) { michael@0: newTab.removeEventListener("error", errorHandler, false); michael@0: michael@0: // since the browser code and test code are invoked when an error event is michael@0: // fired, a delay is used here to avoid the test code run before the browser michael@0: // code. michael@0: executeSoon(function() { michael@0: let iconSrc = $icon.attr("src"); michael@0: michael@0: // with moz-anno:favicon automatically redirects to the default favIcon michael@0: // if the given url is invalid michael@0: ok(iconSrc.startsWith("moz-anno:favicon:"), michael@0: "The icon url starts with moz-anno:favicon so the default fav icon would be displayed"); michael@0: michael@0: // At this point, as an additional integrity check we could also verify michael@0: // that the iconSrc URI does not have any associated favicon data. This michael@0: // kind of check, however, is not easily supported by the asynchronous michael@0: // favicon API. Fortunately, the fact that we received the error event michael@0: // already indicates that the original favicon was not available. michael@0: // Morevover, since we are using a "moz-anno:favicon:" URI, we know that michael@0: // we'll not display an empty icon, but the default favicon. michael@0: michael@0: // clean up michael@0: gBrowser.removeTab(newTab); michael@0: let endGame = function() { michael@0: window.removeEventListener("tabviewhidden", endGame, false); michael@0: michael@0: ok(!TabView.isVisible(), "Tab View is hidden"); michael@0: finish(); michael@0: } michael@0: window.addEventListener("tabviewhidden", endGame, false); michael@0: TabView.toggle(); michael@0: }); michael@0: }; michael@0: newTab.addEventListener("error", errorHandler, false); michael@0: michael@0: newTab.linkedBrowser.loadURI( michael@0: "http://mochi.test:8888/browser/browser/components/tabview/test/test_bug600645.html"); michael@0: }