1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug600645.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 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 + * This file tests that, when there is an app tab that references an invalid 1.9 + * favicon, the default favicon appears the group app tab tray, instead of an 1.10 + * empty image that would not be visible. 1.11 + */ 1.12 + 1.13 +const fi = Cc["@mozilla.org/browser/favicon-service;1"]. 1.14 + getService(Ci.nsIFaviconService); 1.15 + 1.16 +let newTab; 1.17 + 1.18 +function test() { 1.19 + waitForExplicitFinish(); 1.20 + 1.21 + newTab = gBrowser.addTab(); 1.22 + 1.23 + showTabView(function() { 1.24 + let cw = TabView.getContentWindow(); 1.25 + whenAppTabIconAdded(cw.GroupItems.groupItems[0], onTabPinned); 1.26 + gBrowser.pinTab(newTab); 1.27 + }) 1.28 +} 1.29 + 1.30 +function onTabPinned() { 1.31 + let contentWindow = TabView.getContentWindow(); 1.32 + is(contentWindow.GroupItems.groupItems.length, 1, 1.33 + "There is one group item on startup"); 1.34 + 1.35 + let groupItem = contentWindow.GroupItems.groupItems[0]; 1.36 + let icon = contentWindow.iQ(".appTabIcon", groupItem.$appTabTray)[0]; 1.37 + let $icon = contentWindow.iQ(icon); 1.38 + 1.39 + is($icon.data("xulTab"), newTab, 1.40 + "The app tab icon has the right tab reference") 1.41 + // check to see whether it's showing the default one or not. 1.42 + is($icon.attr("src"), fi.defaultFavicon.spec, 1.43 + "The icon is showing the default fav icon for blank tab"); 1.44 + 1.45 + let errorHandler = function(event) { 1.46 + newTab.removeEventListener("error", errorHandler, false); 1.47 + 1.48 + // since the browser code and test code are invoked when an error event is 1.49 + // fired, a delay is used here to avoid the test code run before the browser 1.50 + // code. 1.51 + executeSoon(function() { 1.52 + let iconSrc = $icon.attr("src"); 1.53 + 1.54 + // with moz-anno:favicon automatically redirects to the default favIcon 1.55 + // if the given url is invalid 1.56 + ok(iconSrc.startsWith("moz-anno:favicon:"), 1.57 + "The icon url starts with moz-anno:favicon so the default fav icon would be displayed"); 1.58 + 1.59 + // At this point, as an additional integrity check we could also verify 1.60 + // that the iconSrc URI does not have any associated favicon data. This 1.61 + // kind of check, however, is not easily supported by the asynchronous 1.62 + // favicon API. Fortunately, the fact that we received the error event 1.63 + // already indicates that the original favicon was not available. 1.64 + // Morevover, since we are using a "moz-anno:favicon:" URI, we know that 1.65 + // we'll not display an empty icon, but the default favicon. 1.66 + 1.67 + // clean up 1.68 + gBrowser.removeTab(newTab); 1.69 + let endGame = function() { 1.70 + window.removeEventListener("tabviewhidden", endGame, false); 1.71 + 1.72 + ok(!TabView.isVisible(), "Tab View is hidden"); 1.73 + finish(); 1.74 + } 1.75 + window.addEventListener("tabviewhidden", endGame, false); 1.76 + TabView.toggle(); 1.77 + }); 1.78 + }; 1.79 + newTab.addEventListener("error", errorHandler, false); 1.80 + 1.81 + newTab.linkedBrowser.loadURI( 1.82 + "http://mochi.test:8888/browser/browser/components/tabview/test/test_bug600645.html"); 1.83 +}