Skip to content

Commit 701fc70

Browse files
Fix issues causing failing tests in dom.js, mostly related to the preservingBrowserDimensions helper function.
1 parent d457b7e commit 701fc70

File tree

1 file changed

+56
-18
lines changed

1 file changed

+56
-18
lines changed

test/unit/dom_test.js

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,15 +1448,31 @@ new Test.Unit.Runner({
14481448
},
14491449

14501450
testViewportDimensions: function() {
1451-
preservingBrowserDimensions(function() {
1452-
window.resizeTo(800, 600);
1451+
var original = document.viewport.getDimensions();
1452+
1453+
window.resizeTo(800, 600);
1454+
1455+
this.wait(1000, function() {
14531456
var before = document.viewport.getDimensions();
1457+
1458+
var delta = { width: 800 - before.width, height: 600 - before.height };
1459+
14541460
window.resizeBy(50, 50);
1455-
var after = document.viewport.getDimensions();
1456-
1457-
this.assertEqual(before.width + 50, after.width, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THIS TEST TO PASS");
1458-
this.assertEqual(before.height + 50, after.height, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THIS TEST TO PASS");
1459-
}.bind(this));
1461+
this.wait(1000, function() {
1462+
var after = document.viewport.getDimensions();
1463+
1464+
this.assertEqual(before.width + 50, after.width, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THIS TEST TO PASS");
1465+
this.assertEqual(before.height + 50, after.height, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THIS TEST TO PASS");
1466+
1467+
this.wait(1000, function() {
1468+
// Restore original dimensions.
1469+
window.resizeTo(
1470+
original.width + delta.width,
1471+
original.height + delta.height
1472+
);
1473+
});
1474+
})
1475+
});
14601476
},
14611477

14621478
testElementToViewportDimensionsDoesNotAffectDocumentProperties: function() {
@@ -1475,19 +1491,31 @@ new Test.Unit.Runner({
14751491
},
14761492

14771493
testViewportScrollOffsets: function() {
1478-
preservingBrowserDimensions(function() {
1479-
window.scrollTo(0, 0);
1480-
this.assertEqual(0, document.viewport.getScrollOffsets().top);
1494+
var original = document.viewport.getDimensions();
1495+
1496+
window.scrollTo(0, 0);
1497+
this.assertEqual(0, document.viewport.getScrollOffsets().top);
1498+
1499+
window.scrollTo(0, 35);
1500+
this.assertEqual(35, document.viewport.getScrollOffsets().top);
14811501

1482-
window.scrollTo(0, 35);
1483-
this.assertEqual(35, document.viewport.getScrollOffsets().top);
1502+
window.resizeTo(200, 650);
14841503

1485-
window.resizeTo(200, 650);
1504+
this.wait(1000, function() {
1505+
var before = document.viewport.getDimensions();
1506+
var delta = { width: 200 - before.width, height: 650 - before.height };
1507+
14861508
window.scrollTo(25, 35);
14871509
this.assertEqual(25, document.viewport.getScrollOffsets().left, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS");
1488-
1489-
window.resizeTo(850, 650);
1490-
}.bind(this));
1510+
1511+
this.wait(1000, function() {
1512+
// Restore original dimensions.
1513+
window.resizeTo(
1514+
original.width + delta.width,
1515+
original.height + delta.height
1516+
);
1517+
});
1518+
});
14911519
},
14921520

14931521
testNodeConstants: function() {
@@ -1600,10 +1628,14 @@ new Test.Unit.Runner({
16001628
},
16011629

16021630
testElementPurge: function() {
1631+
function uidForElement(elem) {
1632+
return elem.uniqueID ? elem.uniqueID : elem._prototypeUID;
1633+
}
1634+
16031635
var element = new Element('div');
16041636
element.store('foo', 'bar');
16051637

1606-
var uid = element._prototypeUID;
1638+
var uid = uidForElement(element);
16071639
this.assert(uid in Element.Storage, "newly-created element's uid should exist in `Element.Storage`");
16081640

16091641
var storageKeysBefore = Object.keys(Element.Storage).length;
@@ -1647,14 +1679,20 @@ new Test.Unit.Runner({
16471679

16481680
function preservingBrowserDimensions(callback) {
16491681
var original = document.viewport.getDimensions();
1682+
16501683
window.resizeTo(640, 480);
1684+
16511685
var resized = document.viewport.getDimensions();
16521686
original.width += 640 - resized.width, original.height += 480 - resized.height;
16531687

16541688
try {
16551689
window.resizeTo(original.width, original.height);
16561690
callback();
1657-
} finally {
1691+
} catch(e) {
1692+
throw e;
1693+
}finally {
16581694
window.resizeTo(original.width, original.height);
16591695
}
16601696
}
1697+
1698+

0 commit comments

Comments
 (0)