prototype: Reset the browser's dimensions to their original settings after running the DOM viewport tests.

This commit is contained in:
Sam Stephenson 2007-10-26 03:10:06 +00:00
parent 1c5e3fe3fb
commit 18969c5159
2 changed files with 34 additions and 14 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Reset the browser's dimensions to their original settings after running the DOM viewport tests. [sam]
* Fix the test runner for Firefox in Leopard. [sam]
* Use String#include wherever possible.

View File

@ -1517,27 +1517,31 @@
}},
testViewportDimensions: function() {with(this) {
window.resizeTo(800, 600);
var before = document.viewport.getDimensions();
window.resizeBy(50, 50);
var after = document.viewport.getDimensions();
preservingBrowserDimensions(function() {
window.resizeTo(800, 600);
var before = document.viewport.getDimensions();
window.resizeBy(50, 50);
var after = document.viewport.getDimensions();
assertEqual(before.width + 50, after.width, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS");
assertEqual(before.height + 50, after.height, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS");
assertEqual(before.width + 50, after.width, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS");
assertEqual(before.height + 50, after.height, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS");
}.bind(this));
}},
testViewportScrollOffsets: function() {with(this) {
window.scrollTo(0, 0);
assertEqual(0, document.viewport.getScrollOffsets().top);
preservingBrowserDimensions(function() {
window.scrollTo(0, 0);
assertEqual(0, document.viewport.getScrollOffsets().top);
window.scrollTo(0, 35);
assertEqual(35, document.viewport.getScrollOffsets().top);
window.scrollTo(0, 35);
assertEqual(35, document.viewport.getScrollOffsets().top);
window.resizeTo(200, 650);
window.scrollTo(25, 35);
assertEqual(25, document.viewport.getScrollOffsets().left);
window.resizeTo(200, 650);
window.scrollTo(25, 35);
assertEqual(25, document.viewport.getScrollOffsets().left);
window.resizeTo(850, 650);
window.resizeTo(850, 650);
}.bind(this));
}},
testNodeConstants: function() {with(this) {
@ -1563,7 +1567,21 @@
}, this);
}}
}, 'testlog');
function preservingBrowserDimensions(callback) {
var original = document.viewport.getDimensions();
window.resizeTo(640, 480);
var resized = document.viewport.getDimensions();
original.width += 640 - resized.width, original.height += 480 - resized.height;
try {
window.resizeTo(original.width, original.height);
callback();
} finally {
window.resizeTo(original.width, original.height);
}
}
// ]]>
</script>
</body>