tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

hit-test.js (1669B)


      1 setup({explicit_done: true});
      2 
      3 var img = document.getElementById('img');
      4 var area = document.getElementById('area');
      5 
      6 var hitRect = [[area, 3, 3], [area, 9, 9], [img, 1, 3], [img, 3, 1], [img, 11, 9], [img, 9, 11], [img, 21, 41], [img, 101, 101]];
      7 var hitNone = [[img, 3, 3], [img, 9, 9], [img, 1, 3], [img, 3, 1], [img, 11, 9], [img, 9, 11], [img, 21, 41], [img, 101, 101]];
      8 var hitAll = [[area, 1, 1], [area, 1, 299], [area, 299, 1], [area, 299, 299], [area, 21, 41], [area, 101, 101]];
      9 var hitCircle = [[area, 11, 40], [area, 29, 40], [area, 20, 31], [area, 20, 49], [img, 12, 32], [img, 28, 48], [img, 101, 101]];
     10 var hitPoly = [[area, 101, 101], [area, 119, 101], [area, 101, 119], [img, 118, 118], [img, 3, 3], [img, 21, 41]];
     11 var hitStar = [[area, 101, 101], [area, 199, 101], [area, 150, 51], [img, 150, 125], [img, 3, 3], [img, 21, 41]];
     12 
     13 var tests;
     14 // The test file should have `tests` defined as follows:
     15 // tests = [
     16 // {desc: string, shape: string?, coords: string?, hit: [[element, x, y], ...]},
     17 // ...
     18 // ];
     19 
     20 onload = function() {
     21  tests.forEach(function(t) {
     22    test(function(t_obj) {
     23      if (t.shape === null) {
     24        area.removeAttribute('shape');
     25      } else {
     26        area.shape = t.shape;
     27      }
     28      if (area.coords === null) {
     29        area.removeAttribute('coords');
     30      } else {
     31        area.coords = t.coords;
     32      }
     33      t.hit.forEach(function(arr) {
     34        var expected = arr[0];
     35        var x = arr[1];
     36        var y = arr[2];
     37        assert_equals(document.elementFromPoint(x, y), expected, 'elementFromPoint('+x+', '+y+')');
     38      });
     39    }, t.desc + ': ' + format_value(t.coords) + ' (' + t.shape + ')');
     40  });
     41  done();
     42 };