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
This commit is contained in:
Ting-Yu Lin 2016-02-19 18:21:16 +08:00
parent 532ae28bc6
commit 536547f4bf
2 changed files with 29 additions and 3 deletions

View File

@ -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);
}

View File

@ -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<MockAccessibleCaretManager>();
@ -101,10 +101,20 @@ public:
class AccessibleCaretEventHubTester : public ::testing::Test
{
public:
explicit AccessibleCaretEventHubTester()
AccessibleCaretEventHubTester()
{
DefaultValue<nsresult>::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<WidgetEvent> CreateMouseEvent(EventMessage aMessage,