DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (004536f666bf)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/resizeTestHelper.js"></script>
<style>
  div {
    border: 1px dotted gray
  }
  .transform {
    transform: scale(2,2) rotate(90deg)
  }
</style>
<p>ResizeObserver tests</p>
<div id="target1" style="width:100px;height:100px;">t1
  <div id="target2" style="width:100px;height:100px;">t2
    <div id="target3" style="width:100px;height:100px;">t3
      <span id="inline">inline</span>
    </div>
  </div>
</div>
<div id="absolute" style="width:100.5px;height:100.5px;position:absolute;top:10.3px;left:10.3px"></div>
<script>
'use strict';

let t1 = document.querySelector('#target1');
let t2 = document.querySelector('#target2');
let t3 = document.querySelector('#target3');
let abs = document.querySelector('#absolute');
let inline = document.querySelector('#inline');

function test0() {
  let helper = new ResizeTestHelper(
    "test0: notification ordering",
  [
    {
      setup: observer => {
        observer.observe(t3);
        observer.observe(t2);
        observer.observe(t1);
        t1.style.width = "5px";
        t3.style.width = "5px";
        t2.style.width = "5px";
      },
      notify: (entries, observer) => {
        assert_equals(entries.length, 3, "3 resizes");
        assert_equals(entries[0].target, t3, "ordering");
        assert_equals(entries[1].target, t2, "ordering");
        assert_equals(entries[2].target, t1, "ordering");
        observer.disconnect();
        t1.style.width = "100px";
        t2.style.width = "100px";
        t3.style.width = "100px";
      }
    }
  ]);
  return helper.start();
}

function test1() {
  let helper = new ResizeTestHelper(
    "test1: display:none triggers notification",
  [
    {
      setup: observer => {
        observer.observe(t1);
      },
      notify: (entries, observer) => {
        return true;  // Delay next step
      }
    },
    {
      setup: observer => {
        t1.style.display = "none";
      },
      notify: (entries, observer) => {
        t1.style.display = "";
      }
    }
  ]);
  return helper.start();
}


function test2() {
  let helper = new ResizeTestHelper(
    "test2: remove/appendChild trigger notification",
  [
    {
      setup: observer => {
        observer.observe(t1);
      },
      notify: (entries, observer) => {
        return true;  // Delay next step
      }
    },
    { // "removeChild triggers notification"
      setup: observer => {
        t1.parentNode.removeChild(t1);
      },
      notify: (entries, observer) => {
        assert_equals(entries[0].target, t1);
        return true;  // Delay next step
      }
    },
    { // "appendChild triggers notification",
      setup: observer => {
        document.body.appendChild(t1);
      },
      notify: (entries, observer) => {
        assert_equals(entries[0].target, t1)
      }
    }
  ]);
  return helper.start();
}


function test3() {
  let helper = new ResizeTestHelper(
    "test3: dimensions match",
  [
    {
      setup: observer => {
        observer.observe(t1);
        t1.style.width = "200.5px";
        t1.style.height = "100px";
        t1.style.paddingLeft = "20px";
        t1.style.paddingTop = "10px";
      },
      notify: (entries, observer) => {
        assert_equals(entries[0].contentRect.left,20);
        assert_equals(entries[0].contentRect.top,10);
        assert_between_inclusive(entries[0].contentRect.width, 200.4, 200.6, "width is not rounded");
        assert_equals(entries[0].contentRect.height, 100);
      }
    }
  ]);
  return helper.start();
}

function test4() {
  let helper = new ResizeTestHelper(
    "test4: transform do not cause notifications",
  [
    {
      setup: observer => {
        observer.observe(t2);
      },
      notify: (entries, observer) => {
        return true; // Delay next step
      }
    },
    {
      setup: observer => {
        t2.classList.add("transform");
      },
      notify: (entries, observer) => {
        assert_unreached("transform must not trigger notifications");
      },
      timeout: () => {
        t2.classList.remove("transform");
      }
    }
  ]);
  return helper.start();
}

function test5() {
  let helper = new ResizeTestHelper(
    "test5: moving an element does not trigger notifications",
  [
    {
      setup: observer => {
        observer.observe(abs);
      },
      notify: (entries, observer) => {
        return true; // Delay next step
      }
    },
    {
      setup: observer => {
        abs.style.top = "20.33px";
        abs.style.left = "20.33px";
      },
      notify: (entries, observer) => {
        assert_unreached("movement should not cause resize notifications");
      },
      timeout: () => {
      }
    }
  ]);
  return helper.start();
}

function test6() {
  let helper = new ResizeTestHelper(
    "test6: inline element does not notify",
  [
    {
      setup: observer => {
        observer.observe(inline);
        observer.observe(t1);
        t1.style.width = "66px";
        inline.style.width = "66px";
      },
      notify: (entries, observer) => {
        assert_equals(entries.length, 1, "inline elements must not trigger notifications");
        assert_equals(entries[0].target, t1, "inline elements must not trigger notifications");
        return true; // Delay next step
      }
    },
    { // "inline element that becomes block should notify",
      setup: observer => {
        inline.style.display = "block";
      },
      notify: (entries, observer) => {
        assert_equals(entries[0].target, inline);
      }
    }
  ]);
  return helper.start();
}

function test7() {
  let helper = new ResizeTestHelper(
    "test7: unobserve inside notify callback",
  [
    {
      setup: observer => {
        observer.observe(t1);
        observer.observe(t2);
      },
      notify: (entries, observer) => {
        t1.style.width = "777px";
        t2.style.width = "777px";
        observer.unobserve(t1);
        return true;  // Delay next step
      }
    },
    {
      setup: observer => {
      },
      notify: (entries, observer) => {
        assert_equals(entries.length, 1, "only t2 is observed");
        assert_equals(entries[0].target, t2, "only t2 is observed");
      }
    }
  ]);
  return helper.start();
}

function test8() {
  let helper = new ResizeTestHelper(
    "test8: observe inside notify callback",
  [
    {
      setup: observer => {
        observer.observe(t1);
      },
      notify: (entries, observer) => {
        observer.observe(t2);
        t2.style.width = "888px";
        return true;  // Delay next step
      }
    },
    {
      setup: observer => {
      },
      notify: (entries, observer) => {
        assert_equals(entries.length, 1, "only t2 is observed");
        assert_equals(entries[0].target, t2, "only t2 is observed");
      }
    }
  ]);
  return helper.start();
}

function test9() {
  let helper = new ResizeTestHelper(
    "test9: disconnect inside notify callback",
  [
    {
      setup: observer => {
        observer.observe(t1);
      },
      notify: (entries, observer) => {
        t1.style.width = "999px";
        observer.disconnect();
        return true;  // Delay next step
      }
    },
    {
      setup: observer => {
      },
      notify: (entries, observer) => {
        assert_unreached("there should be no notifications after disconnect");
      },
      timeout: () => {
      }
    }
  ]);
  return helper.start();
}

function test10() {
  var parent = t1.parentNode;
  let helper = new ResizeTestHelper(
    "test10: element notifies when parent removed",
  [
    {
      setup: observer => {
        observer.observe(t3);
      },
      notify: (entries, observer) => {
        return true;  // Delay next step
      }
    },
    {
      setup: observer => {
        t1.parentNode.removeChild(t1);
      },
      notify: (entries, observer) => {
        assert_equals(entries.length, 1);
        assert_equals(entries[0].target, t3);
        parent.appendChild(t1);
      }
    }
  ]);
  return helper.start();
}

let guard;
test(_ => {
  assert_own_property(window, "ResizeObserver");
  guard = async_test('guard');
}, "ResizeObserver implemented")

test0()
  .then(() => { return test1(); })
  .then(() => { return test2(); })
  .then(() => { return test3(); })
  .then(() => { return test4(); })
  .then(() => { return test5(); })
  .then(() => { return test6(); })
  .then(() => { return test7(); })
  .then(() => { return test8(); })
  .then(() => { return test9(); })
  .then(() => { return test10(); })
  .then(() => { guard.done(); });

</script>