3 <title>Original Title
</title>
4 <link rel=
"shortcut icon" type=
"image/x-icon" href=
"http://test.com/oldfavicon.ico"/>
6 function debugOutput(str
) {
7 text
= document
.createTextNode(str
);
8 debugDiv
= document
.getElementById('debugDiv');
9 div
= document
.createElement ('div');
10 div
.appendChild(text
);
11 debugDiv
.appendChild(div
);
14 function createFavIconElement(iconURL
) {
15 var link
= document
.createElement("link");
16 link
.type
= "image/x-icon";
17 link
.rel
= "shortcut icon";
22 function getHeadElement() {
23 return document
.getElementsByTagName("head")[0];
26 function setFavIcon(iconURL
) {
27 var docHead
= getHeadElement();
28 var links
= docHead
.getElementsByTagName("link");
29 for (var i
= 0; i
< links
.length
; ++i
) {
31 if (link
.type
=="image/x-icon" && link
.rel
=="shortcut icon") {
32 docHead
.removeChild(link
);
33 break; // Assuming only one match at most.
36 docHead
.appendChild(createFavIconElement(iconURL
));
40 if (window
.testRunner
) {
41 testRunner
.dumpAsText();
42 if (testRunner
.dumpIconChanges
)
43 testRunner
.dumpIconChanges();
46 iconURL
= document
.getElementsByTagName("head")[0].getElementsByTagName("link")[0].href
;
47 debugOutput ('Original iconURL is: ' + iconURL
);
48 newURL
= 'http://test.com/newfavicon.ico';
49 debugOutput ('Setting new icon URL to: ' + newURL
);
51 iconURL
= document
.getElementsByTagName("head")[0].getElementsByTagName("link")[0].href
;
53 debugOutput ('New iconURL is: ' + iconURL
);
55 // check that the URL list in the document is as we expect
56 var expectedURLs
= "http://test.com/newfavicon.ico";
57 var iconURLs
= window
.internals
.shortcutIconURLs(document
);
58 if (expectedURLs
== iconURLs
[0])
59 debugOutput('PASS - URL list matches expected');
61 debugOutput('FAIL - URL list does not match expected');
63 // Add some more fav icons to verify that didChangeIcons gets called.
64 var docHead
= getHeadElement();
65 docHead
.insertBefore(createFavIconElement("http://example.org/icon1.ico"), docHead
.firstChild
);
66 docHead
.appendChild(createFavIconElement("http://example.org/icon2.ico"));
71 <body onload='runTests();'
>