Bug 1481904 [wpt PR 12358] - [IntersectionObserver] Fix initial notifications for non-zero threshold, a=testonly
authorStefan Zager <szager@chromium.org>
Mon, 13 Aug 2018 18:23:38 +0000
changeset 486617 fad7f71861a34f74f51e6af5c13f68cc6dbe1335
parent 486616 8da92fbd2897d3df88b029b1d9985940717ac63b
child 486618 b2ecac097a34350ca51c6168666d6165a2756e44
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1481904, 12358, 847623, 827639, 1167884, 581755
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481904 [wpt PR 12358] - [IntersectionObserver] Fix initial notifications for non-zero threshold, a=testonly Automatic update from web-platform-tests[IntersectionObserver] Fix initial notifications for non-zero threshold When a target is first observed, last_threshold_index_ is set to a sentinel value (0x1fffffff), to ensure that an initial notification will be sent on the next frame. For that notification, if the target is intersecting, but the intersection ratio is less than the smallest threshold set on the observer, then the isIntersecting field of the notification should be false. Also, for IOv2, the isVisible field should always be false -- and skip the expensive hit test -- if the intersection ratio is less than the smallest threshold set on the observer. BUG=847623,827639 R=chrishtr@chromium.org Change-Id: I518ff97a23afd92a82c4d01d9280d57ffb0c9ae2 Reviewed-on: https://chromium-review.googlesource.com/1167884 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Commit-Queue: Stefan Zager <szager@chromium.org> Cr-Commit-Position: refs/heads/master@{#581755} -- wpt-commits: a6abe150c4901fdb461fc853f3b067ac495ce8f3 wpt-pr: 12358
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/intersection-observer/initial-observation-with-threshold.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -364543,16 +364543,22 @@
     ]
    ],
    "intersection-observer/iframe-no-root.html": [
     [
      "/intersection-observer/iframe-no-root.html",
      {}
     ]
    ],
+   "intersection-observer/initial-observation-with-threshold.html": [
+    [
+     "/intersection-observer/initial-observation-with-threshold.html",
+     {}
+    ]
+   ],
    "intersection-observer/inline-client-rect.html": [
     [
      "/intersection-observer/inline-client-rect.html",
      {}
     ]
    ],
    "intersection-observer/isIntersecting-change-events.html": [
     [
@@ -605412,16 +605418,20 @@
   "intersection-observer/idlharness.window.js": [
    "2059e1ce638b5f2cac4e4f013c567a56894599a0",
    "testharness"
   ],
   "intersection-observer/iframe-no-root.html": [
    "e37aeac5530f348328274f9f8a2eeae9f08609ff",
    "testharness"
   ],
+  "intersection-observer/initial-observation-with-threshold.html": [
+   "d677f0eefa84b7394ab92ccb0ad0cd43b3208476",
+   "testharness"
+  ],
   "intersection-observer/inline-client-rect.html": [
    "0bdfc8de24458e0fb490de4f00537197c0662e53",
    "testharness"
   ],
   "intersection-observer/isIntersecting-change-events.html": [
    "f9362c3024c2003ac03c1e789c54486830710c92",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/intersection-observer/initial-observation-with-threshold.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./resources/intersection-observer-test-utils.js"></script>
+
+<style>
+pre, #log {
+  position: absolute;
+  top: 0;
+  left: 200px;
+}
+.spacer {
+  height: calc(100vh + 100px);
+}
+#root {
+  display: inline-block;
+  overflow-y: scroll;
+  height: 240px;
+  border: 3px solid black;
+}
+#target {
+  width: 100px;
+  height: 100px;
+  margin: 200px 0 0 0;
+  background-color: green;
+}
+</style>
+
+<div id="root">
+  <div id="target"></div>
+</div>
+
+<script>
+var entries = [];
+var root, target;
+
+runTestCycle(function() {
+  target = document.getElementById("target");
+  assert_true(!!target, "target exists");
+  root = document.getElementById("root");
+  assert_true(!!root, "root exists");
+  var observer = new IntersectionObserver(function(changes) {
+    entries = entries.concat(changes)
+  }, { root: root, threshold: [0.5] });
+  observer.observe(target);
+  entries = entries.concat(observer.takeRecords());
+  assert_equals(entries.length, 0, "No initial notifications.");
+  runTestCycle(step0, "First rAF");
+}, "First observation with a threshold.");
+
+function step0() {
+  root.scrollTop = 20;
+  runTestCycle(step1, "root.scrollTop = 20");
+  checkLastEntry(entries, 0, [ 11, 111, 211, 311, 11, 111, 211, 251, 11, 111, 11, 251, false]);
+}
+
+function step1() {
+  checkLastEntry(entries, 1, [ 11, 111, 191, 291, 11, 111, 191, 251, 11, 111, 11, 251, true]);
+}
+</script>