From 18969c5159196e747891b40bb42d646f2e9ebe8f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 26 Oct 2007 03:10:06 +0000 Subject: [PATCH] prototype: Reset the browser's dimensions to their original settings after running the DOM viewport tests. --- CHANGELOG | 2 ++ test/unit/dom.html | 46 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2a7b6bc..058d484 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. diff --git a/test/unit/dom.html b/test/unit/dom.html index a484583..fb2438b 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -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); + } + } + // ]]>