browser/components/tabview/test/browser_tabview_bug600645.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:eb713130c6a7
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
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 */
9
10 const fi = Cc["@mozilla.org/browser/favicon-service;1"].
11 getService(Ci.nsIFaviconService);
12
13 let newTab;
14
15 function test() {
16 waitForExplicitFinish();
17
18 newTab = gBrowser.addTab();
19
20 showTabView(function() {
21 let cw = TabView.getContentWindow();
22 whenAppTabIconAdded(cw.GroupItems.groupItems[0], onTabPinned);
23 gBrowser.pinTab(newTab);
24 })
25 }
26
27 function onTabPinned() {
28 let contentWindow = TabView.getContentWindow();
29 is(contentWindow.GroupItems.groupItems.length, 1,
30 "There is one group item on startup");
31
32 let groupItem = contentWindow.GroupItems.groupItems[0];
33 let icon = contentWindow.iQ(".appTabIcon", groupItem.$appTabTray)[0];
34 let $icon = contentWindow.iQ(icon);
35
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");
41
42 let errorHandler = function(event) {
43 newTab.removeEventListener("error", errorHandler, false);
44
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");
50
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");
55
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.
63
64 // clean up
65 gBrowser.removeTab(newTab);
66 let endGame = function() {
67 window.removeEventListener("tabviewhidden", endGame, false);
68
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);
77
78 newTab.linkedBrowser.loadURI(
79 "http://mochi.test:8888/browser/browser/components/tabview/test/test_bug600645.html");
80 }

mercurial