toolkit/modules/tests/browser/browser_Geometry.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 let tempScope = {};
     6 Components.utils.import("resource://gre/modules/Geometry.jsm", tempScope);
     7 let Point = tempScope.Point;
     8 let Rect = tempScope.Rect;
    10 function test() {
    11   ok(Rect, "Rect class exists");
    12   for (var fname in tests) {
    13     tests[fname]();
    14   }
    15 }
    17 let tests = {
    18   testGetDimensions: function() {
    19     let r = new Rect(5, 10, 100, 50);
    20     ok(r.left == 5, "rect has correct left value");
    21     ok(r.top == 10, "rect has correct top value");
    22     ok(r.right == 105, "rect has correct right value");
    23     ok(r.bottom == 60, "rect has correct bottom value");
    24     ok(r.width == 100, "rect has correct width value");
    25     ok(r.height == 50, "rect has correct height value");
    26     ok(r.x == 5, "rect has correct x value");
    27     ok(r.y == 10, "rect has correct y value");
    28   },
    30   testIsEmpty: function() {
    31     let r = new Rect(0, 0, 0, 10);
    32     ok(r.isEmpty(), "rect with nonpositive width is empty");
    33     let r = new Rect(0, 0, 10, 0);
    34     ok(r.isEmpty(), "rect with nonpositive height is empty");
    35     let r = new Rect(0, 0, 10, 10);
    36     ok(!r.isEmpty(), "rect with positive dimensions is not empty");
    37   },
    39   testRestrictTo: function() {
    40     let r1 = new Rect(10, 10, 100, 100);
    41     let r2 = new Rect(50, 50, 100, 100);
    42     r1.restrictTo(r2);
    43     ok(r1.equals(new Rect(50, 50, 60, 60)), "intersection is non-empty");
    45     let r1 = new Rect(10, 10, 100, 100);
    46     let r2 = new Rect(120, 120, 100, 100);
    47     r1.restrictTo(r2);
    48     ok(r1.isEmpty(), "intersection is empty");
    50     let r1 = new Rect(10, 10, 100, 100);
    51     let r2 = new Rect(0, 0, 0, 0);
    52     r1.restrictTo(r2);
    53     ok(r1.isEmpty(), "intersection of rect and empty is empty");
    55     let r1 = new Rect(0, 0, 0, 0);
    56     let r2 = new Rect(0, 0, 0, 0);
    57     r1.restrictTo(r2);
    58     ok(r1.isEmpty(), "intersection of empty and empty is empty");
    59   },
    61   testExpandToContain: function() {
    62     let r1 = new Rect(10, 10, 100, 100);
    63     let r2 = new Rect(50, 50, 100, 100);
    64     r1.expandToContain(r2);
    65     ok(r1.equals(new Rect(10, 10, 140, 140)), "correct expandToContain on intersecting rectangles");
    67     let r1 = new Rect(10, 10, 100, 100);
    68     let r2 = new Rect(120, 120, 100, 100);
    69     r1.expandToContain(r2);
    70     ok(r1.equals(new Rect(10, 10, 210, 210)), "correct expandToContain on non-intersecting rectangles");
    72     let r1 = new Rect(10, 10, 100, 100);
    73     let r2 = new Rect(0, 0, 0, 0);
    74     r1.expandToContain(r2);
    75     ok(r1.equals(new Rect(10, 10, 100, 100)), "expandToContain of rect and empty is rect");
    77     let r1 = new Rect(10, 10, 0, 0);
    78     let r2 = new Rect(0, 0, 0, 0);
    79     r1.expandToContain(r2);
    80     ok(r1.isEmpty(), "expandToContain of empty and empty is empty");
    81   },
    83   testSubtract: function testSubtract() {
    84     function equals(rects1, rects2) {
    85       return rects1.length == rects2.length && rects1.every(function(r, i) {
    86         return r.equals(rects2[i]);
    87       });
    88     }
    90     let r1 = new Rect(0, 0, 100, 100);
    91     let r2 = new Rect(500, 500, 100, 100);
    92     ok(equals(r1.subtract(r2), [r1]), "subtract area outside of region yields same region");
    94     let r1 = new Rect(0, 0, 100, 100);
    95     let r2 = new Rect(-10, -10, 50, 120);
    96     ok(equals(r1.subtract(r2), [new Rect(40, 0, 60, 100)]), "subtracting vertical bar from edge leaves one rect");
    98     let r1 = new Rect(0, 0, 100, 100);
    99     let r2 = new Rect(-10, -10, 120, 50);
   100     ok(equals(r1.subtract(r2), [new Rect(0, 40, 100, 60)]), "subtracting horizontal bar from edge leaves one rect");
   102     let r1 = new Rect(0, 0, 100, 100);
   103     let r2 = new Rect(40, 40, 20, 20);
   104     ok(equals(r1.subtract(r2), [
   105       new Rect(0, 0, 40, 100),
   106       new Rect(40, 0, 20, 40),
   107       new Rect(40, 60, 20, 40),
   108       new Rect(60, 0, 40, 100)]),
   109       "subtracting rect in middle leaves union of rects");
   110   },
   111 };

mercurial