gecko/toolkit/modules/tests/browser/browser_Geometry.js
Ekanan Ketunuti 620410f94c Bug 828116 - Move modules in toolkit/content and toolkit/mozapps/shared to toolkit/modules. r=Mossop
--HG--
rename : toolkit/mozapps/shared/CertUtils.jsm => toolkit/modules/CertUtils.jsm
rename : toolkit/content/DeferredTask.jsm => toolkit/modules/DeferredTask.jsm
rename : toolkit/content/Deprecated.jsm => toolkit/modules/Deprecated.jsm
rename : toolkit/content/Dict.jsm => toolkit/modules/Dict.jsm
rename : toolkit/mozapps/shared/FileUtils.jsm => toolkit/modules/FileUtils.jsm
rename : toolkit/content/Geometry.jsm => toolkit/modules/Geometry.jsm
rename : toolkit/content/InlineSpellChecker.jsm => toolkit/modules/InlineSpellChecker.jsm
rename : toolkit/content/LightweightThemeConsumer.jsm => toolkit/modules/LightweightThemeConsumer.jsm
rename : toolkit/content/PageMenu.jsm => toolkit/modules/PageMenu.jsm
rename : toolkit/content/PopupNotifications.jsm => toolkit/modules/PopupNotifications.jsm
rename : toolkit/content/PrivateBrowsingUtils.jsm => toolkit/modules/PrivateBrowsingUtils.jsm
rename : toolkit/content/PropertyListUtils.jsm => toolkit/modules/PropertyListUtils.jsm
rename : toolkit/content/Services.jsm => toolkit/modules/Services.jsm
rename : toolkit/content/Task.jsm => toolkit/modules/Task.jsm
rename : toolkit/content/Troubleshoot.jsm => toolkit/modules/Troubleshoot.jsm
rename : toolkit/content/UpdateChannel.jsm => toolkit/modules/UpdateChannel.jsm
rename : toolkit/content/WindowDraggingUtils.jsm => toolkit/modules/WindowDraggingUtils.jsm
rename : toolkit/content/debug.js => toolkit/modules/debug.js
rename : toolkit/content/tests/browser/browser_DeferredTask.js => toolkit/modules/tests/browser/browser_DeferredTask.js
rename : toolkit/content/tests/browser/browser_Deprecated.js => toolkit/modules/tests/browser/browser_Deprecated.js
rename : toolkit/content/tests/browser/browser_Geometry.js => toolkit/modules/tests/browser/browser_Geometry.js
rename : toolkit/content/tests/browser/browser_InlineSpellChecker.js => toolkit/modules/tests/browser/browser_InlineSpellChecker.js
rename : toolkit/content/tests/browser/browser_Services.js => toolkit/modules/tests/browser/browser_Services.js
rename : toolkit/content/tests/browser/browser_Troubleshoot.js => toolkit/modules/tests/browser/browser_Troubleshoot.js
rename : toolkit/mozapps/shared/test/chrome/Makefile.in => toolkit/modules/tests/chrome/Makefile.in
rename : toolkit/mozapps/shared/test/chrome/moz.build => toolkit/modules/tests/chrome/moz.build
rename : toolkit/mozapps/shared/test/chrome/test_bug544442_checkCert.xul => toolkit/modules/tests/chrome/test_bug544442_checkCert.xul
rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListBinary.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListBinary.plist
rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListXML.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListXML.plist
rename : toolkit/mozapps/shared/test/unit/test_FileUtils.js => toolkit/modules/tests/xpcshell/test_FileUtils.js
rename : toolkit/content/tests/unit/test_dict.js => toolkit/modules/tests/xpcshell/test_dict.js
rename : toolkit/content/tests/unit/test_propertyListsUtils.js => toolkit/modules/tests/xpcshell/test_propertyListsUtils.js
rename : toolkit/mozapps/shared/test/unit/test_readCertPrefs.js => toolkit/modules/tests/xpcshell/test_readCertPrefs.js
rename : toolkit/content/tests/unit/test_task.js => toolkit/modules/tests/xpcshell/test_task.js
2013-05-14 14:37:18 -07:00

112 lines
3.8 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let tempScope = {};
Components.utils.import("resource://gre/modules/Geometry.jsm", tempScope);
let Point = tempScope.Point;
let Rect = tempScope.Rect;
function test() {
ok(Rect, "Rect class exists");
for (var fname in tests) {
tests[fname]();
}
}
let tests = {
testGetDimensions: function() {
let r = new Rect(5, 10, 100, 50);
ok(r.left == 5, "rect has correct left value");
ok(r.top == 10, "rect has correct top value");
ok(r.right == 105, "rect has correct right value");
ok(r.bottom == 60, "rect has correct bottom value");
ok(r.width == 100, "rect has correct width value");
ok(r.height == 50, "rect has correct height value");
ok(r.x == 5, "rect has correct x value");
ok(r.y == 10, "rect has correct y value");
},
testIsEmpty: function() {
let r = new Rect(0, 0, 0, 10);
ok(r.isEmpty(), "rect with nonpositive width is empty");
let r = new Rect(0, 0, 10, 0);
ok(r.isEmpty(), "rect with nonpositive height is empty");
let r = new Rect(0, 0, 10, 10);
ok(!r.isEmpty(), "rect with positive dimensions is not empty");
},
testRestrictTo: function() {
let r1 = new Rect(10, 10, 100, 100);
let r2 = new Rect(50, 50, 100, 100);
r1.restrictTo(r2);
ok(r1.equals(new Rect(50, 50, 60, 60)), "intersection is non-empty");
let r1 = new Rect(10, 10, 100, 100);
let r2 = new Rect(120, 120, 100, 100);
r1.restrictTo(r2);
ok(r1.isEmpty(), "intersection is empty");
let r1 = new Rect(10, 10, 100, 100);
let r2 = new Rect(0, 0, 0, 0);
r1.restrictTo(r2);
ok(r1.isEmpty(), "intersection of rect and empty is empty");
let r1 = new Rect(0, 0, 0, 0);
let r2 = new Rect(0, 0, 0, 0);
r1.restrictTo(r2);
ok(r1.isEmpty(), "intersection of empty and empty is empty");
},
testExpandToContain: function() {
let r1 = new Rect(10, 10, 100, 100);
let r2 = new Rect(50, 50, 100, 100);
r1.expandToContain(r2);
ok(r1.equals(new Rect(10, 10, 140, 140)), "correct expandToContain on intersecting rectangles");
let r1 = new Rect(10, 10, 100, 100);
let r2 = new Rect(120, 120, 100, 100);
r1.expandToContain(r2);
ok(r1.equals(new Rect(10, 10, 210, 210)), "correct expandToContain on non-intersecting rectangles");
let r1 = new Rect(10, 10, 100, 100);
let r2 = new Rect(0, 0, 0, 0);
r1.expandToContain(r2);
ok(r1.equals(new Rect(10, 10, 100, 100)), "expandToContain of rect and empty is rect");
let r1 = new Rect(10, 10, 0, 0);
let r2 = new Rect(0, 0, 0, 0);
r1.expandToContain(r2);
ok(r1.isEmpty(), "expandToContain of empty and empty is empty");
},
testSubtract: function testSubtract() {
function equals(rects1, rects2) {
return rects1.length == rects2.length && rects1.every(function(r, i) {
return r.equals(rects2[i]);
});
}
let r1 = new Rect(0, 0, 100, 100);
let r2 = new Rect(500, 500, 100, 100);
ok(equals(r1.subtract(r2), [r1]), "subtract area outside of region yields same region");
let r1 = new Rect(0, 0, 100, 100);
let r2 = new Rect(-10, -10, 50, 120);
ok(equals(r1.subtract(r2), [new Rect(40, 0, 60, 100)]), "subtracting vertical bar from edge leaves one rect");
let r1 = new Rect(0, 0, 100, 100);
let r2 = new Rect(-10, -10, 120, 50);
ok(equals(r1.subtract(r2), [new Rect(0, 40, 100, 60)]), "subtracting horizontal bar from edge leaves one rect");
let r1 = new Rect(0, 0, 100, 100);
let r2 = new Rect(40, 40, 20, 20);
ok(equals(r1.subtract(r2), [
new Rect(0, 0, 40, 100),
new Rect(40, 0, 20, 40),
new Rect(40, 60, 20, 40),
new Rect(60, 0, 40, 100)]),
"subtracting rect in middle leaves union of rects");
},
};