From 4a4798d88b33a9682a078660b907672fe4044b80 Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Thu, 18 Feb 2016 18:38:44 +0800 Subject: [PATCH] Bug 1248847 - Assert AccessibleCaretEventHub mRefCnt > 1 in all its entry points. r=mats Also I removed the 'explicit' keywords from the constructor since they have no argument so nothing can be implicited converted to them. MozReview-Commit-ID: GrFcqO0Uf1o --HG-- extra : rebase_source : c4747c5e3ea09ddfc08bfc1b0c8e4bcedb1d75ce extra : amend_source : 6289aaff79b22956b72956734e4d99bdd3b7977d --- layout/base/AccessibleCaretEventHub.cpp | 16 ++++++++++++++++ .../base/gtest/TestAccessibleCaretEventHub.cpp | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/layout/base/AccessibleCaretEventHub.cpp b/layout/base/AccessibleCaretEventHub.cpp index 4dbd1556d27a..4105064a4820 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 50215901aa23..1b9f98bd9279 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->AddRef(); + } + + ~AccessibleCaretEventHubTester() + { + // Release the ref added in the constructor. + mHub->Release(); } static UniquePtr CreateMouseEvent(EventMessage aMessage,