diff --git a/layout/base/AccessibleCaretEventHub.cpp b/layout/base/AccessibleCaretEventHub.cpp index 4dbd1556d27..4105064a482 100644 --- a/layout/base/AccessibleCaretEventHub.cpp +++ b/layout/base/AccessibleCaretEventHub.cpp @@ -473,6 +473,8 @@ AccessibleCaretEventHub::HandleEvent(WidgetEvent* aEvent) return status; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + switch (aEvent->mClass) { case eMouseEventClass: status = HandleMouseEvent(aEvent->AsMouseEvent()); @@ -655,6 +657,8 @@ AccessibleCaretEventHub::Reflow(DOMHighResTimeStamp aStart, return NS_OK; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + AC_LOG("%s, state: %s", __FUNCTION__, mState->Name()); mState->OnReflow(this); return NS_OK; @@ -668,6 +672,8 @@ AccessibleCaretEventHub::ReflowInterruptible(DOMHighResTimeStamp aStart, return NS_OK; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + return Reflow(aStart, aEnd); } @@ -678,6 +684,8 @@ AccessibleCaretEventHub::AsyncPanZoomStarted() return; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + AC_LOG("%s, state: %s", __FUNCTION__, mState->Name()); mState->OnScrollStart(this); } @@ -689,6 +697,8 @@ AccessibleCaretEventHub::AsyncPanZoomStopped() return; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + AC_LOG("%s, state: %s", __FUNCTION__, mState->Name()); mState->OnScrollEnd(this); } @@ -700,6 +710,8 @@ AccessibleCaretEventHub::ScrollPositionChanged() return; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + AC_LOG("%s, state: %s", __FUNCTION__, mState->Name()); mState->OnScrollPositionChanged(this); } @@ -742,6 +754,8 @@ AccessibleCaretEventHub::NotifySelectionChanged(nsIDOMDocument* aDoc, return NS_OK; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + AC_LOG("%s, state: %s, reason: %d", __FUNCTION__, mState->Name(), aReason); mState->OnSelectionChanged(this, aDoc, aSel, aReason); return NS_OK; @@ -754,6 +768,8 @@ AccessibleCaretEventHub::NotifyBlur(bool aIsLeavingDocument) return; } + MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!"); + AC_LOG("%s, state: %s", __FUNCTION__, mState->Name()); mState->OnBlur(this, aIsLeavingDocument); } diff --git a/layout/base/gtest/TestAccessibleCaretEventHub.cpp b/layout/base/gtest/TestAccessibleCaretEventHub.cpp index 50215901aa2..2f230c48fda 100644 --- a/layout/base/gtest/TestAccessibleCaretEventHub.cpp +++ b/layout/base/gtest/TestAccessibleCaretEventHub.cpp @@ -35,7 +35,7 @@ namespace mozilla class MockAccessibleCaretManager : public AccessibleCaretManager { public: - explicit MockAccessibleCaretManager() + MockAccessibleCaretManager() : AccessibleCaretManager(nullptr) { } @@ -63,7 +63,7 @@ public: using AccessibleCaretEventHub::LongTapState; using AccessibleCaretEventHub::FireScrollEnd; - explicit MockAccessibleCaretEventHub() + MockAccessibleCaretEventHub() : AccessibleCaretEventHub(nullptr) { mManager = MakeUnique(); @@ -101,10 +101,20 @@ public: class AccessibleCaretEventHubTester : public ::testing::Test { public: - explicit AccessibleCaretEventHubTester() + AccessibleCaretEventHubTester() { DefaultValue::Set(NS_OK); EXPECT_EQ(mHub->GetState(), MockAccessibleCaretEventHub::NoActionState()); + + // AccessibleCaretEventHub requires the caller to hold a ref to it. We just + // add ref here for the sake of convenience. + mHub.get()->AddRef(); + } + + ~AccessibleCaretEventHubTester() + { + // Release the ref added in the constructor. + mHub.get()->Release(); } static UniquePtr CreateMouseEvent(EventMessage aMessage,