Skip to content

Commit

Permalink
[IntersectionObserver] Fix tracking bookkeeping
Browse files Browse the repository at this point in the history
Cherry-picked from:

https://chromium-review.googlesource.com/c/chromium/src/+/1513077

BUG=926539
TBR=chrishtr@chromium.org

Change-Id: I90ca898574e4c9efb6bdbe35aade2860d9763399
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1518910
Reviewed-by: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/branch-heads/3729@{#55}
Cr-Branched-From: d4a8972-refs/heads/master@{#638880}
  • Loading branch information
szager-chromium committed Mar 12, 2019
1 parent 3b6cf30 commit 84c6117
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ void IntersectionObservation::TakeRecords(

void IntersectionObservation::Disconnect() {
DCHECK(Observer());
if (target_)
if (target_) {
Target()->EnsureIntersectionObserverData().RemoveObservation(*Observer());
if (target_->isConnected()) {
target_->GetDocument()
.EnsureIntersectionObserverController()
.RemoveTrackedTarget(*target_);
}
}
entries_.clear();
observer_.Clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void IntersectionObserverController::AddTrackedTarget(Element& target) {
}

void IntersectionObserverController::RemoveTrackedTarget(Element& target) {
target.ComputeIntersectionObservations(false);
tracked_observation_targets_.erase(&target);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class IntersectionObserverController
const char* NameInHeapSnapshot() const override {
return "IntersectionObserverController";
}
unsigned GetTrackedTargetCountForTesting() const {
return tracked_observation_targets_.size();
}

private:
void PostTaskToDeliverObservations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/exported/web_view_impl.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/intersection_observer/intersection_observer_controller.h"
#include "third_party/blink/renderer/core/intersection_observer/intersection_observer_delegate.h"
#include "third_party/blink/renderer/core/intersection_observer/intersection_observer_init.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
Expand Down Expand Up @@ -339,6 +340,10 @@ TEST_F(IntersectionObserverTest, DisconnectClearsNotifications) {
Element* target = GetDocument().getElementById("target");
ASSERT_TRUE(target);
observer->observe(target, exception_state);
EXPECT_EQ(GetDocument()
.EnsureIntersectionObserverController()
.GetTrackedTargetCountForTesting(),
1u);

Compositor().BeginFrame();
test::RunPendingTasks();
Expand All @@ -350,6 +355,10 @@ TEST_F(IntersectionObserverTest, DisconnectClearsNotifications) {
kProgrammaticScroll);
Compositor().BeginFrame();
observer->disconnect();
EXPECT_EQ(GetDocument()
.EnsureIntersectionObserverController()
.GetTrackedTargetCountForTesting(),
0u);
test::RunPendingTasks();
EXPECT_EQ(observer_delegate->CallCount(), 1);
}
Expand Down

0 comments on commit 84c6117

Please sign in to comment.