]> git.parisson.com Git - pdf.js.git/commitdiff
updating tests
authorArtur Adib <arturadib@gmail.com>
Thu, 24 May 2012 16:22:46 +0000 (12:22 -0400)
committerArtur Adib <arturadib@gmail.com>
Thu, 24 May 2012 16:22:46 +0000 (12:22 -0400)
test/mozcentral/Makefile.in
test/mozcentral/browser_pdfjs_main.js
test/mozcentral/browser_pdfjs_zoom.js [new file with mode: 0644]
test/mozcentral/head.js

index 8c9face17785edbb0a98ee3818a8ca17c37f9550..fd40574ef395f9aa086668d4e414d6e61bff73b0 100644 (file)
@@ -14,6 +14,7 @@ include $(topsrcdir)/config/rules.mk
 _BROWSER_TEST_FILES = \
   head.js \
   browser_pdfjs_main.js \
+  browser_pdfjs_zoom.js \
   file_pdfjs_test.pdf \
   $(NULL)
 
index d3f5dd64679afa4e40eb07261fc9c059dd07bbf4..5f07e65129285dfb6f40cd96126b3309c3525cfb 100644 (file)
@@ -32,7 +32,7 @@ function test() {
     ok(outerContainer.classList.contains('sidebarOpen'), 'sidebar opens on click');
 
     // Thumbnails are created asynchronously - wait for them
-    waitForElement(document, 'canvas#thumbnail2', function(error) {
+    waitForElement(document, 'canvas#thumbnail2', function(error, thumbnail) {
       if (error)
         finish();
 
@@ -42,7 +42,6 @@ function test() {
       var pageNumber = document.querySelector('input#pageNumber');
       is(parseInt(pageNumber.value), 1, 'initial page is 1');
 
-      var thumbnail = document.querySelector('canvas#thumbnail2');
       ok(thumbnail, 'thumbnail2 is available');
       if (thumbnail) {
         thumbnail.click();
@@ -73,25 +72,7 @@ function test() {
       var viewBookmark = document.querySelector('a#viewBookmark');
       viewBookmark.click();
       ok(viewBookmark.href.length > 0, 'viewBookmark button has href');
-
-      //
-      // Zoom in/out
-      //
-      var zoomOut = document.querySelector('button.zoomOut'),
-          zoomIn = document.querySelector('button.zoomIn');
-
-      // Zoom in
-      var oldWidth = document.querySelector('canvas#page1').width;
-      zoomIn.click();
-      var newWidth = document.querySelector('canvas#page1').width;
-      ok(oldWidth < newWidth, 'zooming in increases page width (old: '+oldWidth+', new: '+newWidth+')');
-
-      // Zoom out
-      var oldWidth = document.querySelector('canvas#page1').width;
-      zoomOut.click();
-      var newWidth = document.querySelector('canvas#page1').width;
-      ok(oldWidth > newWidth, 'zooming out decreases page width (old: '+oldWidth+', new: '+newWidth+')');
-
+    
       finish();
     });
   }, true, true);
diff --git a/test/mozcentral/browser_pdfjs_zoom.js b/test/mozcentral/browser_pdfjs_zoom.js
new file mode 100644 (file)
index 0000000..a6445da
--- /dev/null
@@ -0,0 +1,63 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const RELATIVE_DIR = "browser/extensions/pdfjs/test/";
+const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
+
+function test() {
+  waitForExplicitFinish();
+
+  var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
+  var newTabBrowser = gBrowser.getBrowserForTab(tab);
+  newTabBrowser.addEventListener("pagechange", function onPageChange() {
+    newTabBrowser.removeEventListener("pagechange", onPageChange, true);
+
+    var document = newTabBrowser.contentDocument,
+        window = newTabBrowser.contentWindow;
+
+    //
+    // Zoom in/out
+    //
+    var zoomOut = document.querySelector('button.zoomOut'),
+        zoomIn = document.querySelector('button.zoomIn');
+
+    var newWidth, oldWidth;
+
+    // We need to query the DOM every time since zoom in/out operations destroy the canvas element
+    waitForElement(document, 'canvas#page1', function(error, page1) {
+      if (error)
+        finish();
+      
+      oldWidth = page1.width;
+      zoomIn.click();
+
+      waitForElement(document, 'canvas#page1', function(error, page1) {
+        if (error)
+          finish();
+
+        newWidth = page1.width;
+        ok(oldWidth < newWidth, 'zooming in increases page width (old: '+oldWidth+', new: '+newWidth+')');
+
+        // Zoom out
+        oldWidth = newWidth;
+        zoomOut.click();
+        
+        waitForElement(document, 'canvas#page1', function(error, page1) {
+          if (error)
+            finish();
+
+          newWidth = page1.width;
+          ok(oldWidth > newWidth, 'zooming out decreases page width (old: '+oldWidth+', new: '+newWidth+')');
+
+          finish();
+        });
+      });
+    });
+
+  }, true, true);
+
+  registerCleanupFunction(function() {
+    gBrowser.removeTab(tab);
+  });
+}
index 6ee421b2f18dea81fbb1e77a470496e4fdbf5f26..0636ba4e9a4ea713bd19ce70ba00b830d21bcea7 100644 (file)
@@ -1,19 +1,20 @@
-// Waits for element 'el' to exist in the DOM of 'doc' before executing 'callback'
+// Waits for element 'sel' to exist in the DOM of 'doc' before executing 'callback'
 // Useful when elements are created asynchronously, e.g. after a Web Worker task
-function waitForElement(doc, el, callback) {
+function waitForElement(doc, sel, callback) {
   var time = 0,
       interval = 10,
       timeout = 5000;
 
   var checkEl = setInterval(function() {
-    if (doc.querySelector(el)) {
+    var el = doc.querySelector(sel);
+    if (el) {
       clearInterval(checkEl);
-      if (callback) callback();
+      if (callback) callback(null, el);
     }
 
     time += interval;
     if (time > timeout) {
-      ok(false, 'waitForElement timed out on element: '+el);
+      ok(false, 'waitForElement timed out on element: '+sel);
       clearInterval(checkEl);
       if (callback) callback(true);
     }