Fix for bug 771967. OS idle api active to briefly idle to active notification fix. r=jst

This commit is contained in:
Bonnie Surender 2012-07-13 15:39:46 -07:00
Родитель a85faa1e57
Коммит b70b75ec44
3 изменённых файлов: 91 добавлений и 31 удалений

Просмотреть файл

@ -8478,12 +8478,15 @@ private:
};
void
nsGlobalWindow::NotifyIdleObserver(nsIIdleObserver* aIdleObserver,
PRUint32 aIdleObserverTimeInS,
nsGlobalWindow::NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder,
bool aCallOnidle)
{
MOZ_ASSERT(aIdleObserverHolder);
aIdleObserverHolder->mPrevNotificationIdle = aCallOnidle;
nsCOMPtr<nsIRunnable> caller =
new NotifyIdleObserverRunnable(aIdleObserver, aIdleObserverTimeInS,
new NotifyIdleObserverRunnable(aIdleObserverHolder->mIdleObserver,
aIdleObserverHolder->mTimeInS,
aCallOnidle, this);
if (NS_FAILED(NS_DispatchToCurrentThread(caller))) {
NS_WARNING("Failed to dispatch thread for idle observer notification.");
@ -8512,7 +8515,7 @@ IdleActiveTimerCallback(nsITimer* aTimer, void* aClosure)
{
nsRefPtr<nsGlobalWindow> idleWindow = static_cast<nsGlobalWindow*>(aClosure);
MOZ_ASSERT(idleWindow, "Idle window has not been instantiated.");
idleWindow->NotifyIdleObserversOfIdleActiveEvent();
idleWindow->HandleIdleActiveEvent();
}
void
@ -8529,11 +8532,8 @@ nsGlobalWindow::HandleIdleObserverCallback()
MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!");
MOZ_ASSERT(static_cast<PRUint32>(mIdleCallbackIndex) < mIdleObservers.Length(),
"Idle callback index exceeds array bounds!");
IdleObserverHolder idleObserver =
mIdleObservers.ElementAt(mIdleCallbackIndex);
NotifyIdleObserver(idleObserver.mIdleObserver,
idleObserver.mTimeInS,
true);
IdleObserverHolder& idleObserver = mIdleObservers.ElementAt(mIdleCallbackIndex);
NotifyIdleObserver(&idleObserver, true);
mIdleCallbackIndex++;
if (NS_FAILED(ScheduleNextIdleObserverCallback())) {
NS_WARNING("Failed to set next idle observer callback.");
@ -8602,7 +8602,7 @@ nsGlobalWindow::ScheduleActiveTimerCallback()
MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!");
if (!mAddActiveEventFuzzTime) {
return NotifyIdleObserversOfIdleActiveEvent();
return HandleIdleActiveEvent();
}
MOZ_ASSERT(mIdleTimer);
@ -8618,7 +8618,7 @@ nsGlobalWindow::ScheduleActiveTimerCallback()
}
nsresult
nsGlobalWindow::NotifyIdleObserversOfIdleActiveEvent()
nsGlobalWindow::HandleIdleActiveEvent()
{
MOZ_ASSERT(IsInnerWindow(), "Must be an inner window!");
@ -8636,7 +8636,9 @@ nsGlobalWindow::NotifyIdleObserversOfIdleActiveEvent()
nsTObserverArray<IdleObserverHolder>::ForwardIterator iter(mIdleObservers);
while (iter.HasMore()) {
IdleObserverHolder& idleObserver = iter.GetNext();
NotifyIdleObserver(idleObserver.mIdleObserver, idleObserver.mTimeInS, false);
if (idleObserver.mPrevNotificationIdle) {
NotifyIdleObserver(&idleObserver, false);
}
}
return NS_OK;
@ -8718,9 +8720,8 @@ nsGlobalWindow::RegisterIdleObserver(nsIIdleObserver* aIdleObserver)
MOZ_ASSERT(mIdleCallbackIndex >= 0);
if (static_cast<PRInt32>(insertAtIndex) < mIdleCallbackIndex) {
NotifyIdleObserver(tmpIdleObserver.mIdleObserver,
tmpIdleObserver.mTimeInS,
true);
IdleObserverHolder& idleObserver = mIdleObservers.ElementAt(insertAtIndex);
NotifyIdleObserver(&idleObserver, true);
mIdleCallbackIndex++;
return NS_OK;
}
@ -8841,7 +8842,7 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic,
mNotifyIdleObserversIdleOnThaw = true;
mNotifyIdleObserversActiveOnThaw = false;
} else if (mOuterWindow && mOuterWindow->GetCurrentInnerWindow() == this) {
NotifyIdleObserversOfIdleActiveEvent();
HandleIdleActiveEvent();
}
return NS_OK;
}
@ -9027,7 +9028,7 @@ nsGlobalWindow::FireDelayedDOMEvents()
if (mNotifyIdleObserversIdleOnThaw) {
mNotifyIdleObserversIdleOnThaw = false;
NotifyIdleObserversOfIdleActiveEvent();
HandleIdleActiveEvent();
}
if (mNotifyIdleObserversActiveOnThaw) {

Просмотреть файл

@ -207,23 +207,25 @@ struct IdleObserverHolder
{
nsCOMPtr<nsIIdleObserver> mIdleObserver;
PRUint32 mTimeInS;
bool mPrevNotificationIdle;
IdleObserverHolder()
: mTimeInS(0)
: mTimeInS(0), mPrevNotificationIdle(false)
{
MOZ_COUNT_CTOR(IdleObserverHolder);
}
IdleObserverHolder(const IdleObserverHolder& aOtherIdleObserver)
: mIdleObserver(aOtherIdleObserver.mIdleObserver), mTimeInS(aOtherIdleObserver.mTimeInS)
IdleObserverHolder(const IdleObserverHolder& aOther)
: mIdleObserver(aOther.mIdleObserver), mTimeInS(aOther.mTimeInS),
mPrevNotificationIdle(aOther.mPrevNotificationIdle)
{
MOZ_COUNT_CTOR(IdleObserverHolder);
}
bool operator==(const IdleObserverHolder& aOtherIdleObserver) const {
bool operator==(const IdleObserverHolder& aOther) const {
return
mIdleObserver == aOtherIdleObserver.mIdleObserver &&
mTimeInS == aOtherIdleObserver.mTimeInS;
mIdleObserver == aOther.mIdleObserver &&
mTimeInS == aOther.mTimeInS;
}
~IdleObserverHolder()
@ -583,10 +585,9 @@ public:
void AddEventTargetObject(nsDOMEventTargetHelper* aObject);
void RemoveEventTargetObject(nsDOMEventTargetHelper* aObject);
void NotifyIdleObserver(nsIIdleObserver* aIdleObserver,
PRUint32 aIdleObserverTimeInS,
void NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder,
bool aCallOnidle);
nsresult NotifyIdleObserversOfIdleActiveEvent();
nsresult HandleIdleActiveEvent();
bool ContainsIdleObserver(nsIIdleObserver* aIdleObserver, PRUint32 timeInS);
void HandleIdleObserverCallback();

Просмотреть файл

@ -140,7 +140,7 @@ target="_blank">Mozilla Bug 715041</a>
//test case enabled
var AddOutOfOrderActiveEnabled = AddOutOfOrderIdleEnabled =
AddShiftLocalEnabled = AddNewLocalWhileAllIdleEnabled =
ShiftLocalTimerBackEnabled =
TestActiveToActiveNotification = ShiftLocalTimerBackEnabled =
AddRemoveIdleObserverWithInvalidTimeEnabled = true;
//msgXCount
@ -156,6 +156,7 @@ target="_blank">Mozilla Bug 715041</a>
var tcAddNewLocalWhileAllIdle = 4;
var tcShiftLocalTimerBack = 5;
var tcAddRemoveIdleObserverWithInvalidTime = 6;
var tcTestActiveToActiveNotification = 7;
function ResetMsgCounts() {
msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
@ -238,6 +239,25 @@ target="_blank">Mozilla Bug 715041</a>
AddOutOfOrderIdleCleanUp();
}
break;
case tcTestActiveToActiveNotification:
if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
idleServiceObj.idleTime = 500;
idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
return;
}
if (msg1Count === 2 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
idleServiceObj.idleTime = 1000;
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
return;
}
if (msg1Count === 3 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
return;
}
ok(false, "Failed test active to active notification.");
SimpleTest.finish();
break;
default:
break;
}
@ -361,6 +381,14 @@ target="_blank">Mozilla Bug 715041</a>
ShiftLocalTimerBackCleanUp();
}
break;
case tcTestActiveToActiveNotification:
passed = false;
if (msg1Count === 3 && !msg2Count && !msg3Count && !msg4Count && msg5Count === 1) {
passed = true;
}
ok(passed, "Failed TestActiveToActiveNotification.");
TestActiveNotificationCleanUp();
break;
default:
//do nothing.
break;
@ -619,7 +647,7 @@ target="_blank">Mozilla Bug 715041</a>
ShiftLocalTimerBack();
}
else {
dump("Finished testing AddNewLocalWhileAllIdle()\n");
dump("Finished testing TestActiveToActiveNotificationCleanUp()\n");
SimpleTest.finish();
}
}
@ -657,6 +685,35 @@ target="_blank">Mozilla Bug 715041</a>
window.navigator.removeIdleObserver(idleObserversArray[5]);
dump("ShiftLocalTimerBackCleanUp() done clean up\n");
if (TestActiveToActiveNotificationEnabled) {
TestActiveNotification();
}
else {
dump("Finished testing AddNewLocalWhileAllIdle()\n");
SimpleTest.finish();
}
}
function TestActiveNotification()
{
dump("\n\nTESTING CASE TestActiveNotification\n");
dump("===============================================\n");
ResetVars();
currTestCaseNum = tcTestActiveToActiveNotification;
idleServiceObj.idleTime = 500;
window.navigator.addIdleObserver(idleObserversArray[1]);
window.navigator.addIdleObserver(idleObserversArray[5]);
idleServiceObj.idleTime = 1000;
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
}
function TestActiveNotificationCleanUp()
{
dump("\n\nTESTING CASE TestActiveNotificationCleanUp\n");
dump("===============================================\n");
try {
componentMgr.unregisterFactory(idleServiceCID, idleServiceObj);
}
@ -749,11 +806,12 @@ target="_blank">Mozilla Bug 715041</a>
AddOutOfOrderActiveEnabled = true;
AddOutOfOrderIdleEnabled = true;
AddNewLocalWhileAllIdleEnabled = true;
TestActiveToActiveNotificationEnabled = true;
AddShiftLocalEnabled = true;
AddIdleObserverWithInvalidTimeEnabled = false;
caseZero();
caseZero();
]]>
</script>
</window>