/toolkit/content/tests/widgets/videocontrols_direction_test.js

http://github.com/zpao/v8monkey · JavaScript · 90 lines · 77 code · 13 blank · 0 comment · 10 complexity · 73767c939405e44e7889780fe7caf1f4 MD5 · raw file

  1. var RemoteCanvas = function(url, id) {
  2. this.url = url;
  3. this.id = id;
  4. this.snapshot = null;
  5. };
  6. RemoteCanvas.CANVAS_WIDTH = 200;
  7. RemoteCanvas.CANVAS_HEIGHT = 200;
  8. RemoteCanvas.prototype.compare = function(otherCanvas, expected) {
  9. return compareSnapshots(this.snapshot, otherCanvas.snapshot, expected)[0];
  10. }
  11. RemoteCanvas.prototype.load = function(callback) {
  12. var iframe = document.createElement("iframe");
  13. iframe.id = this.id + "-iframe";
  14. iframe.width = RemoteCanvas.CANVAS_WIDTH + "px";
  15. iframe.height = RemoteCanvas.CANVAS_HEIGHT + "px";
  16. iframe.src = this.url;
  17. var me = this;
  18. iframe.addEventListener("load", function() {
  19. var m = iframe.contentDocument.getElementById("av");
  20. m.addEventListener("progress", function(aEvent) {
  21. var v = aEvent.target;
  22. var b = v.buffered;
  23. if (b.length == 1 && b.end(0) == v.duration) {
  24. m.removeEventListener("progress", arguments.callee, false);
  25. setTimeout(function() {
  26. me.remotePageLoaded(callback);
  27. }, 0);
  28. }
  29. }, false);
  30. m.src = m.getAttribute("source");
  31. }, false);
  32. window.document.body.appendChild(iframe);
  33. };
  34. RemoteCanvas.prototype.remotePageLoaded = function(callback) {
  35. var ldrFrame = document.getElementById(this.id + "-iframe");
  36. this.snapshot = snapshotWindow(ldrFrame.contentWindow);
  37. this.snapshot.id = this.id + "-canvas";
  38. window.document.body.appendChild(this.snapshot);
  39. callback(this);
  40. };
  41. RemoteCanvas.prototype.cleanup = function() {
  42. var iframe = document.getElementById(this.id + "-iframe");
  43. iframe.parentNode.removeChild(iframe);
  44. var canvas = document.getElementById(this.id + "-canvas");
  45. canvas.parentNode.removeChild(canvas);
  46. };
  47. function runTest(index) {
  48. var canvases = [];
  49. function testCallback(canvas) {
  50. canvases.push(canvas);
  51. if (canvases.length == 2) { // when both canvases are loaded
  52. var expectedEqual = currentTest.op == "==";
  53. var result = canvases[0].compare(canvases[1], expectedEqual);
  54. ok(result, "Rendering of reftest " + currentTest.test + " should " +
  55. (expectedEqual ? "not " : "") + "be different to the reference");
  56. if (result) {
  57. canvases[0].cleanup();
  58. canvases[1].cleanup();
  59. }
  60. else {
  61. ok(true, "Snapshot of canvas 1: " + canvases[0].snapshot.toDataURL());
  62. ok(true, "Snapshot of canvas 2: " + canvases[1].snapshot.toDataURL());
  63. }
  64. if (index < tests.length - 1)
  65. runTest(index + 1);
  66. else
  67. SimpleTest.finish();
  68. }
  69. }
  70. var currentTest = tests[index];
  71. var testCanvas = new RemoteCanvas(currentTest.test, "test-" + index);
  72. testCanvas.load(testCallback);
  73. var refCanvas = new RemoteCanvas(currentTest.ref, "ref-" + index);
  74. refCanvas.load(testCallback);
  75. }
  76. SimpleTest.waitForExplicitFinish();
  77. window.addEventListener("load", function() { runTest(0); }, true);