test_bug415761.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Test for icon filenames</title>
  5. <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  6. <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
  7. <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
  8. </head>
  9. <body>
  10. <pre id="test">
  11. <script class="testbody" type="text/javascript">
  12. SimpleTest.waitForExplicitFinish();
  13. // We want to make sure that moz-icon URIs with non-ascii characters work. To that
  14. // end, we compare the rendering of an icon without non-ascii characters to that
  15. // of one that does include such characters.
  16. // First, obtain the file URI to the ourselves:
  17. var chromeURI = location.href;
  18. var io = Components.classes['@mozilla.org/network/io-service;1']
  19. .getService(Components.interfaces.nsIIOService);
  20. chromeURI = io.newURI(chromeURI, null, null);
  21. var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
  22. .getService(Components.interfaces.nsIChromeRegistry);
  23. fileURI = chromeReg.convertChromeURL(chromeURI);
  24. fileURI.QueryInterface(Components.interfaces.nsIFileURL);
  25. var self = fileURI.file;
  26. // Check if the non-ascii-named icon is still hanging around from a previous test
  27. var dest = self.parent;
  28. dest.append("\u263a.ico");
  29. if (dest.exists()) {
  30. dest.remove(false);
  31. }
  32. // Copy the source icon so that we have an identical icon with non-ascii characters
  33. // in its name
  34. var src = self.parent;
  35. src.append("bug415761.ico");
  36. src.copyTo(null, dest.leafName);
  37. // Now load both icons in an Image() with a moz-icon URI
  38. var testImage = new Image();
  39. var refImage = new Image();
  40. var loadedImages = 0;
  41. testImage.onload = refImage.onload = function() {
  42. loadedImages++;
  43. if (loadedImages == 2) {
  44. finishTest();
  45. }
  46. };
  47. testImage.onerror = refImage.onerror = function() {
  48. testImage.onload = refImage.onload = function() {};
  49. ok(false, "Icon did not load successfully");
  50. SimpleTest.finish();
  51. };
  52. function finishTest() {
  53. ok(true, "Both icons loaded successfully");
  54. // Render the reference to a canvas
  55. var refCanvas = document.createElement("canvas");
  56. refCanvas.setAttribute("height", 32);
  57. refCanvas.setAttribute("width", 32);
  58. refCanvas.getContext('2d').drawImage(refImage, 0, 0, 32, 32);
  59. // Render the icon with a non-ascii character in its name to a canvas
  60. var testCanvas = document.createElement("canvas");
  61. testCanvas.setAttribute("height", 32);
  62. testCanvas.setAttribute("width", 32);
  63. testCanvas.getContext('2d').drawImage(testImage, 0, 0, 32, 32);
  64. // Assert that they should be the same.
  65. assertSnapshots(refCanvas, testCanvas, true, 0, "icon", "reference icon");
  66. SimpleTest.finish();
  67. };
  68. var testURI = io.newFileURI(dest).spec;
  69. var refURI = io.newFileURI(src).spec;
  70. testImage.src = "moz-icon:" + testURI;
  71. refImage.src = "moz-icon:" + refURI;
  72. SimpleTest.registerCleanupFunction(function() {
  73. // Remove the copied file if it exists.
  74. if (dest.exists()) {
  75. dest.remove(false);
  76. }
  77. });
  78. </script>
  79. </pre>
  80. </body>
  81. </html>