зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1532351. Remove idle observer API on navigator. r=farre
Differential Revision: https://phabricator.services.mozilla.com/D22029 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6efac32ac8
Коммит
fee4435d19
|
@ -665,28 +665,6 @@ void VibrateWindowListener::RemoveListener() {
|
|||
|
||||
} // namespace
|
||||
|
||||
void Navigator::AddIdleObserver(MozIdleObserver& aIdleObserver,
|
||||
ErrorResult& aRv) {
|
||||
if (!mWindow) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
if (NS_FAILED(mWindow->RegisterIdleObserver(aIdleObserver))) {
|
||||
NS_WARNING("Failed to add idle observer.");
|
||||
}
|
||||
}
|
||||
|
||||
void Navigator::RemoveIdleObserver(MozIdleObserver& aIdleObserver,
|
||||
ErrorResult& aRv) {
|
||||
if (!mWindow) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
if (NS_FAILED(mWindow->UnregisterIdleObserver(aIdleObserver))) {
|
||||
NS_WARNING("Failed to remove idle observer.");
|
||||
}
|
||||
}
|
||||
|
||||
void Navigator::SetVibrationPermission(bool aPermitted, bool aPersistent) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ class BatteryManager;
|
|||
|
||||
class Promise;
|
||||
|
||||
class MozIdleObserver;
|
||||
class Gamepad;
|
||||
class GamepadServiceTest;
|
||||
class NavigatorUserMediaSuccessCallback;
|
||||
|
@ -158,8 +157,6 @@ class Navigator final : public nsISupports, public nsWrapperCache {
|
|||
bool JavaEnabled() { return false; }
|
||||
uint64_t HardwareConcurrency();
|
||||
bool TaintEnabled() { return false; }
|
||||
void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
|
||||
void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<LegacyMozTCPSocket> MozTCPSocket();
|
||||
network::Connection* GetConnection(ErrorResult& aRv);
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#endif
|
||||
#include "nsDOMOfflineResourceList.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIIdleService.h"
|
||||
#include "nsISizeOfEventTarget.h"
|
||||
#include "nsDOMJSUtils.h"
|
||||
#include "nsArrayUtils.h"
|
||||
|
@ -342,18 +341,11 @@ static nsGlobalWindowOuter* GetOuterWindowForForwarding(
|
|||
// dialogs for this window.
|
||||
#define MAX_SUCCESSIVE_DIALOG_COUNT 5
|
||||
|
||||
// Idle fuzz time upper limit
|
||||
#define MAX_IDLE_FUZZ_TIME_MS 90000
|
||||
|
||||
// Min idle notification time in seconds.
|
||||
#define MIN_IDLE_NOTIFICATION_TIME_S 1
|
||||
|
||||
// Max number of Report objects
|
||||
#define MAX_REPORT_RECORDS 100
|
||||
|
||||
static LazyLogModule gDOMLeakPRLogInner("DOMLeakInner");
|
||||
|
||||
static bool gIdleObserversAPIFuzzTimeDisabled = false;
|
||||
static FILE* gDumpFile = nullptr;
|
||||
|
||||
nsGlobalWindowInner::InnerWindowByIdTable*
|
||||
|
@ -842,14 +834,8 @@ class PromiseDocumentFlushedResolver final {
|
|||
nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow)
|
||||
: nsPIDOMWindowInner(aOuterWindow->AsOuter()),
|
||||
mozilla::webgpu::InstanceProvider(this),
|
||||
mIdleFuzzFactor(0),
|
||||
mIdleCallbackIndex(-1),
|
||||
mCurrentlyIdle(false),
|
||||
mAddActiveEventFuzzTime(true),
|
||||
mWasOffline(false),
|
||||
mHasHadSlowScript(false),
|
||||
mNotifyIdleObserversIdleOnThaw(false),
|
||||
mNotifyIdleObserversActiveOnThaw(false),
|
||||
mIsChrome(false),
|
||||
mCleanMessageManager(false),
|
||||
mNeedsFocus(true),
|
||||
|
@ -926,9 +912,6 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter* aOuterWindow)
|
|||
if (sFirstTime) {
|
||||
sFirstTime = false;
|
||||
TimeoutManager::Initialize();
|
||||
Preferences::AddBoolVarCache(&gIdleObserversAPIFuzzTimeDisabled,
|
||||
"dom.idle-observers-api.fuzz_time.disabled",
|
||||
false);
|
||||
}
|
||||
|
||||
if (gDumpFile == nullptr) {
|
||||
|
@ -1114,13 +1097,6 @@ void nsGlobalWindowInner::FreeInnerObjects() {
|
|||
mTimeoutManager->ClearAllTimeouts();
|
||||
}
|
||||
|
||||
if (mIdleTimer) {
|
||||
mIdleTimer->Cancel();
|
||||
mIdleTimer = nullptr;
|
||||
}
|
||||
|
||||
mIdleObservers.Clear();
|
||||
|
||||
DisableIdleCallbackRequests();
|
||||
|
||||
mChromeEventHandler = nullptr;
|
||||
|
@ -1230,10 +1206,6 @@ void nsGlobalWindowInner::FreeInnerObjects() {
|
|||
sns->Unregister(mObserver);
|
||||
}
|
||||
|
||||
if (mIdleService) {
|
||||
mIdleService->RemoveIdleObserver(mObserver, MIN_IDLE_NOTIFICATION_TIME_S);
|
||||
}
|
||||
|
||||
Preferences::RemoveObserver(mObserver, "intl.accept_languages");
|
||||
|
||||
// Drop its reference to this dying window, in case for some bogus reason
|
||||
|
@ -1380,15 +1352,12 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTabChild)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleService)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleRequestExecutor)
|
||||
for (IdleRequest* request : tmp->mIdleRequestCallbacks) {
|
||||
cb.NoteNativeChild(request, NS_CYCLE_COLLECTION_PARTICIPANT(IdleRequest));
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleObservers)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mClientSource)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepads)
|
||||
|
@ -1479,8 +1448,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
|
|||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTabChild)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleService)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleObservers)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads)
|
||||
|
||||
|
@ -1903,13 +1870,6 @@ void nsGlobalWindowInner::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
|||
}
|
||||
|
||||
aVisitor.SetParentTarget(GetParentTarget(), true);
|
||||
|
||||
// Handle 'active' event.
|
||||
if (!mIdleObservers.IsEmpty() && aVisitor.mEvent->IsTrusted() &&
|
||||
(aVisitor.mEvent->HasMouseEventMessage() ||
|
||||
aVisitor.mEvent->HasDragEventMessage())) {
|
||||
mAddActiveEventFuzzTime = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool nsGlobalWindowInner::DialogsAreBeingAbused() {
|
||||
|
@ -4519,179 +4479,6 @@ void nsGlobalWindowInner::FireOfflineStatusEventIfChanged() {
|
|||
name, CanBubble::eNo, Cancelable::eNo);
|
||||
}
|
||||
|
||||
class NotifyIdleObserverRunnable : public Runnable {
|
||||
public:
|
||||
NotifyIdleObserverRunnable(MozIdleObserver& aIdleObserver, uint32_t aTimeInS,
|
||||
bool aCallOnidle, nsGlobalWindowInner* aIdleWindow)
|
||||
: mozilla::Runnable("NotifyIdleObserverRunnable"),
|
||||
mIdleObserver(aIdleObserver),
|
||||
mTimeInS(aTimeInS),
|
||||
mIdleWindow(aIdleWindow),
|
||||
mCallOnidle(aCallOnidle) {}
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
if (mIdleWindow->ContainsIdleObserver(mIdleObserver, mTimeInS)) {
|
||||
if (mCallOnidle) {
|
||||
mIdleObserver->Onidle(IgnoreErrors());
|
||||
} else {
|
||||
mIdleObserver->Onactive(IgnoreErrors());
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
OwningNonNull<MozIdleObserver> mIdleObserver;
|
||||
uint32_t mTimeInS;
|
||||
RefPtr<nsGlobalWindowInner> mIdleWindow;
|
||||
|
||||
// If false then call on active
|
||||
bool mCallOnidle;
|
||||
};
|
||||
|
||||
void nsGlobalWindowInner::NotifyIdleObserver(
|
||||
IdleObserverHolder* aIdleObserverHolder, bool aCallOnidle) {
|
||||
MOZ_ASSERT(aIdleObserverHolder);
|
||||
aIdleObserverHolder->mPrevNotificationIdle = aCallOnidle;
|
||||
|
||||
nsCOMPtr<nsIRunnable> caller = new NotifyIdleObserverRunnable(
|
||||
aIdleObserverHolder->mIdleObserver, aIdleObserverHolder->mTimeInS,
|
||||
aCallOnidle, this);
|
||||
if (NS_FAILED(Dispatch(TaskCategory::Other, caller.forget()))) {
|
||||
NS_WARNING("Failed to dispatch thread for idle observer notification.");
|
||||
}
|
||||
}
|
||||
|
||||
bool nsGlobalWindowInner::ContainsIdleObserver(MozIdleObserver& aIdleObserver,
|
||||
uint32_t aTimeInS) {
|
||||
bool found = false;
|
||||
nsTObserverArray<IdleObserverHolder>::ForwardIterator iter(mIdleObservers);
|
||||
while (iter.HasMore()) {
|
||||
IdleObserverHolder& idleObserver = iter.GetNext();
|
||||
if (idleObserver.mIdleObserver.ref() == aIdleObserver &&
|
||||
idleObserver.mTimeInS == aTimeInS) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
void IdleActiveTimerCallback(nsITimer* aTimer, void* aClosure) {
|
||||
RefPtr<nsGlobalWindowInner> idleWindow =
|
||||
static_cast<nsGlobalWindowInner*>(aClosure);
|
||||
MOZ_ASSERT(idleWindow, "Idle window has not been instantiated.");
|
||||
idleWindow->HandleIdleActiveEvent();
|
||||
}
|
||||
|
||||
void IdleObserverTimerCallback(nsITimer* aTimer, void* aClosure) {
|
||||
RefPtr<nsGlobalWindowInner> idleWindow =
|
||||
static_cast<nsGlobalWindowInner*>(aClosure);
|
||||
MOZ_ASSERT(idleWindow, "Idle window has not been instantiated.");
|
||||
idleWindow->HandleIdleObserverCallback();
|
||||
}
|
||||
|
||||
void nsGlobalWindowInner::HandleIdleObserverCallback() {
|
||||
MOZ_ASSERT(
|
||||
static_cast<uint32_t>(mIdleCallbackIndex) < mIdleObservers.Length(),
|
||||
"Idle callback index exceeds array bounds!");
|
||||
IdleObserverHolder& idleObserver =
|
||||
mIdleObservers.ElementAt(mIdleCallbackIndex);
|
||||
NotifyIdleObserver(&idleObserver, true);
|
||||
mIdleCallbackIndex++;
|
||||
if (NS_FAILED(ScheduleNextIdleObserverCallback())) {
|
||||
NS_WARNING("Failed to set next idle observer callback.");
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowInner::ScheduleNextIdleObserverCallback() {
|
||||
MOZ_ASSERT(mIdleService, "No idle service!");
|
||||
|
||||
if (mIdleCallbackIndex < 0 ||
|
||||
static_cast<uint32_t>(mIdleCallbackIndex) >= mIdleObservers.Length()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
IdleObserverHolder& idleObserver =
|
||||
mIdleObservers.ElementAt(mIdleCallbackIndex);
|
||||
|
||||
uint32_t userIdleTimeMS = 0;
|
||||
nsresult rv = mIdleService->GetIdleTime(&userIdleTimeMS);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint32_t callbackTimeMS = 0;
|
||||
if (idleObserver.mTimeInS * 1000 + mIdleFuzzFactor > userIdleTimeMS) {
|
||||
callbackTimeMS =
|
||||
idleObserver.mTimeInS * 1000 - userIdleTimeMS + mIdleFuzzFactor;
|
||||
}
|
||||
|
||||
mIdleTimer->Cancel();
|
||||
rv = mIdleTimer->InitWithNamedFuncCallback(
|
||||
IdleObserverTimerCallback, this, callbackTimeMS, nsITimer::TYPE_ONE_SHOT,
|
||||
"nsGlobalWindowInner::ScheduleNextIdleObserverCallback");
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t nsGlobalWindowInner::GetFuzzTimeMS() {
|
||||
if (gIdleObserversAPIFuzzTimeDisabled) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t randNum = MAX_IDLE_FUZZ_TIME_MS;
|
||||
size_t nbytes = PR_GetRandomNoise(&randNum, sizeof(randNum));
|
||||
if (nbytes != sizeof(randNum)) {
|
||||
NS_WARNING("PR_GetRandomNoise(...) Not implemented or no available noise!");
|
||||
return MAX_IDLE_FUZZ_TIME_MS;
|
||||
}
|
||||
|
||||
if (randNum > MAX_IDLE_FUZZ_TIME_MS) {
|
||||
randNum %= MAX_IDLE_FUZZ_TIME_MS;
|
||||
}
|
||||
|
||||
return randNum;
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowInner::ScheduleActiveTimerCallback() {
|
||||
if (!mAddActiveEventFuzzTime) {
|
||||
return HandleIdleActiveEvent();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mIdleTimer);
|
||||
mIdleTimer->Cancel();
|
||||
|
||||
uint32_t fuzzFactorInMS = GetFuzzTimeMS();
|
||||
nsresult rv = mIdleTimer->InitWithNamedFuncCallback(
|
||||
IdleActiveTimerCallback, this, fuzzFactorInMS, nsITimer::TYPE_ONE_SHOT,
|
||||
"nsGlobalWindowInner::ScheduleActiveTimerCallback");
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowInner::HandleIdleActiveEvent() {
|
||||
if (mCurrentlyIdle) {
|
||||
mIdleCallbackIndex = 0;
|
||||
mIdleFuzzFactor = GetFuzzTimeMS();
|
||||
nsresult rv = ScheduleNextIdleObserverCallback();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mIdleCallbackIndex = -1;
|
||||
MOZ_ASSERT(mIdleTimer);
|
||||
mIdleTimer->Cancel();
|
||||
nsTObserverArray<IdleObserverHolder>::ForwardIterator iter(mIdleObservers);
|
||||
while (iter.HasMore()) {
|
||||
IdleObserverHolder& idleObserver = iter.GetNext();
|
||||
if (idleObserver.mPrevNotificationIdle) {
|
||||
NotifyIdleObserver(&idleObserver, false);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsGlobalWindowInner::SlowScriptResponse
|
||||
nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) {
|
||||
nsresult rv;
|
||||
|
@ -4920,180 +4707,6 @@ nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) {
|
|||
return KillSlowScript;
|
||||
}
|
||||
|
||||
uint32_t nsGlobalWindowInner::FindInsertionIndex(
|
||||
IdleObserverHolder* aIdleObserver) {
|
||||
MOZ_ASSERT(aIdleObserver, "Idle observer not instantiated.");
|
||||
|
||||
uint32_t i = 0;
|
||||
nsTObserverArray<IdleObserverHolder>::ForwardIterator iter(mIdleObservers);
|
||||
while (iter.HasMore()) {
|
||||
IdleObserverHolder& idleObserver = iter.GetNext();
|
||||
if (idleObserver.mTimeInS > aIdleObserver->mTimeInS) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
MOZ_ASSERT(i <= mIdleObservers.Length(),
|
||||
"Array index out of bounds error.");
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowInner::RegisterIdleObserver(
|
||||
MozIdleObserver& aIdleObserver) {
|
||||
nsresult rv;
|
||||
if (mIdleObservers.IsEmpty()) {
|
||||
mIdleService = do_GetService("@mozilla.org/widget/idleservice;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mIdleService->AddIdleObserver(mObserver, MIN_IDLE_NOTIFICATION_TIME_S);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!mIdleTimer) {
|
||||
mIdleTimer = NS_NewTimer();
|
||||
NS_ENSURE_TRUE(mIdleTimer, NS_ERROR_OUT_OF_MEMORY);
|
||||
} else {
|
||||
mIdleTimer->Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mIdleService);
|
||||
MOZ_ASSERT(mIdleTimer);
|
||||
|
||||
IdleObserverHolder tmpIdleObserver;
|
||||
tmpIdleObserver.mIdleObserver = aIdleObserver;
|
||||
ErrorResult err;
|
||||
tmpIdleObserver.mTimeInS = aIdleObserver.GetTime(err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
NS_ENSURE_ARG_MAX(tmpIdleObserver.mTimeInS, UINT32_MAX / 1000);
|
||||
NS_ENSURE_ARG_MIN(tmpIdleObserver.mTimeInS, MIN_IDLE_NOTIFICATION_TIME_S);
|
||||
|
||||
uint32_t insertAtIndex = FindInsertionIndex(&tmpIdleObserver);
|
||||
if (insertAtIndex == mIdleObservers.Length()) {
|
||||
mIdleObservers.AppendElement(tmpIdleObserver);
|
||||
} else {
|
||||
mIdleObservers.InsertElementAt(insertAtIndex, tmpIdleObserver);
|
||||
}
|
||||
|
||||
bool userIsIdle = false;
|
||||
rv = nsContentUtils::IsUserIdle(MIN_IDLE_NOTIFICATION_TIME_S, &userIsIdle);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Special case. First idle observer added to empty list while the user is
|
||||
// idle. Haven't received 'idle' topic notification from slow idle service
|
||||
// yet. Need to wait for the idle notification and then notify idle observers
|
||||
// in the list.
|
||||
if (userIsIdle && mIdleCallbackIndex == -1) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mCurrentlyIdle) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mIdleCallbackIndex >= 0);
|
||||
|
||||
if (static_cast<int32_t>(insertAtIndex) < mIdleCallbackIndex) {
|
||||
IdleObserverHolder& idleObserver = mIdleObservers.ElementAt(insertAtIndex);
|
||||
NotifyIdleObserver(&idleObserver, true);
|
||||
mIdleCallbackIndex++;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (static_cast<int32_t>(insertAtIndex) == mIdleCallbackIndex) {
|
||||
mIdleTimer->Cancel();
|
||||
rv = ScheduleNextIdleObserverCallback();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowInner::FindIndexOfElementToRemove(
|
||||
MozIdleObserver& aIdleObserver, int32_t* aRemoveElementIndex) {
|
||||
*aRemoveElementIndex = 0;
|
||||
if (mIdleObservers.IsEmpty()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ErrorResult rv;
|
||||
uint32_t aIdleObserverTimeInS = aIdleObserver.GetTime(rv);
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
NS_ENSURE_ARG_MIN(aIdleObserverTimeInS, MIN_IDLE_NOTIFICATION_TIME_S);
|
||||
|
||||
nsTObserverArray<IdleObserverHolder>::ForwardIterator iter(mIdleObservers);
|
||||
while (iter.HasMore()) {
|
||||
IdleObserverHolder& idleObserver = iter.GetNext();
|
||||
if (idleObserver.mTimeInS == aIdleObserverTimeInS &&
|
||||
idleObserver.mIdleObserver.ref() == aIdleObserver) {
|
||||
break;
|
||||
}
|
||||
(*aRemoveElementIndex)++;
|
||||
}
|
||||
return static_cast<uint32_t>(*aRemoveElementIndex) >= mIdleObservers.Length()
|
||||
? NS_ERROR_FAILURE
|
||||
: NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowInner::UnregisterIdleObserver(
|
||||
MozIdleObserver& aIdleObserver) {
|
||||
int32_t removeElementIndex;
|
||||
nsresult rv = FindIndexOfElementToRemove(aIdleObserver, &removeElementIndex);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
"Idle observer not found in list of idle observers. No idle observer "
|
||||
"removed.");
|
||||
return NS_OK;
|
||||
}
|
||||
mIdleObservers.RemoveElementAt(removeElementIndex);
|
||||
|
||||
MOZ_ASSERT(mIdleTimer);
|
||||
if (mIdleObservers.IsEmpty() && mIdleService) {
|
||||
rv = mIdleService->RemoveIdleObserver(mObserver,
|
||||
MIN_IDLE_NOTIFICATION_TIME_S);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mIdleService = nullptr;
|
||||
|
||||
mIdleTimer->Cancel();
|
||||
mIdleCallbackIndex = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mCurrentlyIdle) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (removeElementIndex < mIdleCallbackIndex) {
|
||||
mIdleCallbackIndex--;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (removeElementIndex != mIdleCallbackIndex) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mIdleTimer->Cancel();
|
||||
|
||||
// If the last element in the array had been notified then decrement
|
||||
// mIdleCallbackIndex because an idle was removed from the list of
|
||||
// idle observers.
|
||||
// Example: add idle observer with time 1, 2, 3,
|
||||
// Idle notifications for idle observers with time 1, 2, 3 are complete
|
||||
// Remove idle observer with time 3 while the user is still idle.
|
||||
// The user never transitioned to active state.
|
||||
// Add an idle observer with idle time 4
|
||||
if (static_cast<uint32_t>(mIdleCallbackIndex) == mIdleObservers.Length()) {
|
||||
mIdleCallbackIndex--;
|
||||
}
|
||||
rv = ScheduleNextIdleObserverCallback();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsGlobalWindowInner::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData) {
|
||||
if (!nsCRT::strcmp(aTopic, NS_IOSERVICE_OFFLINE_STATUS_TOPIC)) {
|
||||
|
@ -5119,29 +4732,6 @@ nsresult nsGlobalWindowInner::Observe(nsISupports* aSubject, const char* aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, OBSERVER_TOPIC_IDLE)) {
|
||||
mCurrentlyIdle = true;
|
||||
if (IsFrozen()) {
|
||||
// need to fire only one idle event while the window is frozen.
|
||||
mNotifyIdleObserversIdleOnThaw = true;
|
||||
mNotifyIdleObserversActiveOnThaw = false;
|
||||
} else if (IsCurrentInnerWindow()) {
|
||||
HandleIdleActiveEvent();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, OBSERVER_TOPIC_ACTIVE)) {
|
||||
mCurrentlyIdle = false;
|
||||
if (IsFrozen()) {
|
||||
mNotifyIdleObserversActiveOnThaw = true;
|
||||
mNotifyIdleObserversIdleOnThaw = false;
|
||||
} else if (IsCurrentInnerWindow()) {
|
||||
ScheduleActiveTimerCallback();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, "offline-cache-update-added")) {
|
||||
if (mApplicationCache) return NS_OK;
|
||||
|
||||
|
@ -5721,16 +5311,6 @@ nsresult nsGlobalWindowInner::FireDelayedDOMEvents() {
|
|||
// Fires an offline status event if the offline status has changed
|
||||
FireOfflineStatusEventIfChanged();
|
||||
|
||||
if (mNotifyIdleObserversIdleOnThaw) {
|
||||
mNotifyIdleObserversIdleOnThaw = false;
|
||||
HandleIdleActiveEvent();
|
||||
}
|
||||
|
||||
if (mNotifyIdleObserversActiveOnThaw) {
|
||||
mNotifyIdleObserversActiveOnThaw = false;
|
||||
ScheduleActiveTimerCallback();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
|
||||
if (docShell) {
|
||||
int32_t childCount = 0;
|
||||
|
|
|
@ -155,37 +155,6 @@ extern already_AddRefed<nsIScriptTimeoutHandler> NS_CreateJSTimeoutHandler(
|
|||
|
||||
extern const js::Class OuterWindowProxyClass;
|
||||
|
||||
struct IdleObserverHolder {
|
||||
mozilla::OwningNonNull<mozilla::dom::MozIdleObserver> mIdleObserver;
|
||||
uint32_t mTimeInS;
|
||||
bool mPrevNotificationIdle;
|
||||
|
||||
IdleObserverHolder() : mTimeInS(0), mPrevNotificationIdle(false) {
|
||||
MOZ_COUNT_CTOR(IdleObserverHolder);
|
||||
}
|
||||
|
||||
IdleObserverHolder(const IdleObserverHolder& aOther)
|
||||
: mIdleObserver(aOther.mIdleObserver),
|
||||
mTimeInS(aOther.mTimeInS),
|
||||
mPrevNotificationIdle(aOther.mPrevNotificationIdle) {
|
||||
MOZ_COUNT_CTOR(IdleObserverHolder);
|
||||
}
|
||||
|
||||
bool operator==(const IdleObserverHolder& aOther) const {
|
||||
return mIdleObserver.ref() == aOther.mIdleObserver &&
|
||||
mTimeInS == aOther.mTimeInS;
|
||||
}
|
||||
|
||||
~IdleObserverHolder() { MOZ_COUNT_DTOR(IdleObserverHolder); }
|
||||
};
|
||||
|
||||
inline void ImplCycleCollectionTraverse(
|
||||
nsCycleCollectionTraversalCallback& aCallback, IdleObserverHolder& aField,
|
||||
const char* aName, unsigned aFlags) {
|
||||
CycleCollectionNoteChild(aCallback, aField.mIdleObserver.get(), aName,
|
||||
aFlags);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsGlobalWindowInner: Global Object for Scripting
|
||||
//*****************************************************************************
|
||||
|
@ -491,13 +460,6 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
|
||||
void AddSizeOfIncludingThis(nsWindowSizes& aWindowSizes) const;
|
||||
|
||||
void NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder,
|
||||
bool aCallOnidle);
|
||||
nsresult HandleIdleActiveEvent();
|
||||
bool ContainsIdleObserver(mozilla::dom::MozIdleObserver& aIdleObserver,
|
||||
uint32_t timeInS);
|
||||
void HandleIdleObserverCallback();
|
||||
|
||||
enum SlowScriptResponse {
|
||||
ContinueSlowScript = 0,
|
||||
ContinueSlowScriptAndKeepNotifying,
|
||||
|
@ -1011,29 +973,6 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
mozilla::dom::CallerType aCallerType,
|
||||
mozilla::ErrorResult& aError);
|
||||
|
||||
// Array of idle observers that are notified of idle events.
|
||||
nsTObserverArray<IdleObserverHolder> mIdleObservers;
|
||||
|
||||
// Idle timer used for function callbacks to notify idle observers.
|
||||
nsCOMPtr<nsITimer> mIdleTimer;
|
||||
|
||||
// Idle fuzz time added to idle timer callbacks.
|
||||
uint32_t mIdleFuzzFactor;
|
||||
|
||||
// Index in mArrayIdleObservers
|
||||
// Next idle observer to notify user idle status
|
||||
int32_t mIdleCallbackIndex;
|
||||
|
||||
// If false then the topic is "active"
|
||||
// If true then the topic is "idle"
|
||||
bool mCurrentlyIdle;
|
||||
|
||||
// Set to true when a fuzz time needs to be applied
|
||||
// to active notifications to the idle observer.
|
||||
bool mAddActiveEventFuzzTime;
|
||||
|
||||
nsCOMPtr<nsIIdleService> mIdleService;
|
||||
|
||||
RefPtr<mozilla::dom::WakeLock> mWakeLock;
|
||||
|
||||
friend class HashchangeCallback;
|
||||
|
@ -1125,19 +1064,6 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
void FireOfflineStatusEventIfChanged();
|
||||
|
||||
public:
|
||||
// Inner windows only.
|
||||
nsresult ScheduleNextIdleObserverCallback();
|
||||
uint32_t GetFuzzTimeMS();
|
||||
nsresult ScheduleActiveTimerCallback();
|
||||
uint32_t FindInsertionIndex(IdleObserverHolder* aIdleObserver);
|
||||
nsresult RegisterIdleObserver(
|
||||
mozilla::dom::MozIdleObserver& aIdleObserverPtr) override;
|
||||
nsresult FindIndexOfElementToRemove(
|
||||
mozilla::dom::MozIdleObserver& aIdleObserver,
|
||||
int32_t* aRemoveElementIndex);
|
||||
nsresult UnregisterIdleObserver(
|
||||
mozilla::dom::MozIdleObserver& aIdleObserverPtr) override;
|
||||
|
||||
// Inner windows only.
|
||||
nsresult FireHashchange(const nsAString& aOldURL, const nsAString& aNewURL);
|
||||
|
||||
|
@ -1290,10 +1216,6 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
// SLOW_SCRIPT_PAGE_COUNT.
|
||||
bool mHasHadSlowScript : 1;
|
||||
|
||||
// Track what sorts of events we need to fire when thawed
|
||||
bool mNotifyIdleObserversIdleOnThaw : 1;
|
||||
bool mNotifyIdleObserversActiveOnThaw : 1;
|
||||
|
||||
// Fast way to tell if this is a chrome window (without having to QI).
|
||||
bool mIsChrome : 1;
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "mozilla/dom/LocalStorage.h"
|
||||
#include "mozilla/dom/LSObject.h"
|
||||
#include "mozilla/dom/Storage.h"
|
||||
#include "mozilla/dom/IdleRequest.h"
|
||||
#include "mozilla/dom/MaybeCrossOriginObject.h"
|
||||
#include "mozilla/dom/Performance.h"
|
||||
#include "mozilla/dom/StorageEvent.h"
|
||||
|
@ -45,7 +44,6 @@
|
|||
# include "mozilla/dom/WindowOrientationObserver.h"
|
||||
#endif
|
||||
#include "nsError.h"
|
||||
#include "nsIIdleService.h"
|
||||
#include "nsISizeOfEventTarget.h"
|
||||
#include "nsDOMJSUtils.h"
|
||||
#include "nsArrayUtils.h"
|
||||
|
@ -1098,10 +1096,6 @@ static JSObject* NewOuterWindowProxy(JSContext* cx,
|
|||
|
||||
nsGlobalWindowOuter::nsGlobalWindowOuter(uint64_t aWindowID)
|
||||
: nsPIDOMWindowOuter(aWindowID),
|
||||
mIdleFuzzFactor(0),
|
||||
mIdleCallbackIndex(-1),
|
||||
mCurrentlyIdle(false),
|
||||
mAddActiveEventFuzzTime(true),
|
||||
mFullscreen(false),
|
||||
mFullscreenMode(false),
|
||||
mIsClosed(false),
|
||||
|
@ -1324,11 +1318,6 @@ void nsGlobalWindowOuter::CleanUp() {
|
|||
mMessageManager = nullptr;
|
||||
|
||||
mArguments = nullptr;
|
||||
|
||||
if (mIdleTimer) {
|
||||
mIdleTimer->Cancel();
|
||||
mIdleTimer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void nsGlobalWindowOuter::ClearControllers() {
|
||||
|
@ -1418,9 +1407,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowOuter)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuspendedDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleService)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIdleObservers)
|
||||
|
||||
// Traverse stuff from nsPIDOMWindow
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler)
|
||||
|
@ -1447,8 +1433,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowOuter)
|
|||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSuspendedDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleService)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleObservers)
|
||||
|
||||
// Unlink stuff from nsPIDOMWindow
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler)
|
||||
|
|
|
@ -80,15 +80,10 @@ class nsHistory;
|
|||
class nsGlobalWindowObserver;
|
||||
class nsGlobalWindowInner;
|
||||
class nsDOMWindowUtils;
|
||||
class nsIIdleService;
|
||||
struct nsRect;
|
||||
|
||||
class nsWindowSizes;
|
||||
|
||||
class IdleRequestExecutor;
|
||||
|
||||
struct IdleObserverHolder;
|
||||
|
||||
namespace mozilla {
|
||||
class AbstractThread;
|
||||
class DOMEventTargetHelper;
|
||||
|
@ -104,8 +99,6 @@ class External;
|
|||
class Function;
|
||||
class Gamepad;
|
||||
enum class ImageBitmapFormat : uint8_t;
|
||||
class IdleRequest;
|
||||
class IdleRequestCallback;
|
||||
class IncrementalRunnable;
|
||||
class IntlUtils;
|
||||
class Location;
|
||||
|
@ -725,29 +718,6 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
|||
mozilla::dom::CallerType aCallerType,
|
||||
mozilla::ErrorResult& aError);
|
||||
|
||||
// Array of idle observers that are notified of idle events.
|
||||
nsTObserverArray<IdleObserverHolder> mIdleObservers;
|
||||
|
||||
// Idle timer used for function callbacks to notify idle observers.
|
||||
nsCOMPtr<nsITimer> mIdleTimer;
|
||||
|
||||
// Idle fuzz time added to idle timer callbacks.
|
||||
uint32_t mIdleFuzzFactor;
|
||||
|
||||
// Index in mArrayIdleObservers
|
||||
// Next idle observer to notify user idle status
|
||||
int32_t mIdleCallbackIndex;
|
||||
|
||||
// If false then the topic is "active"
|
||||
// If true then the topic is "idle"
|
||||
bool mCurrentlyIdle;
|
||||
|
||||
// Set to true when a fuzz time needs to be applied
|
||||
// to active notifications to the idle observer.
|
||||
bool mAddActiveEventFuzzTime;
|
||||
|
||||
nsCOMPtr<nsIIdleService> mIdleService;
|
||||
|
||||
RefPtr<mozilla::dom::WakeLock> mWakeLock;
|
||||
|
||||
friend class HashchangeCallback;
|
||||
|
@ -1177,7 +1147,6 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
|
|||
friend class mozilla::dom::PostMessageEvent;
|
||||
friend class DesktopNotification;
|
||||
friend class mozilla::dom::TimeoutManager;
|
||||
friend class IdleRequestExecutor;
|
||||
friend class nsGlobalWindowInner;
|
||||
};
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ class DocGroup;
|
|||
class Document;
|
||||
class TabGroup;
|
||||
class Element;
|
||||
class MozIdleObserver;
|
||||
class Navigator;
|
||||
class Performance;
|
||||
class Report;
|
||||
|
@ -343,11 +342,6 @@ class nsPIDOMWindowInner : public mozIDOMWindow {
|
|||
return mChromeEventHandler;
|
||||
}
|
||||
|
||||
virtual nsresult RegisterIdleObserver(
|
||||
mozilla::dom::MozIdleObserver& aIdleObserver) = 0;
|
||||
virtual nsresult UnregisterIdleObserver(
|
||||
mozilla::dom::MozIdleObserver& aIdleObserver) = 0;
|
||||
|
||||
mozilla::dom::EventTarget* GetParentTarget() {
|
||||
if (!mParentTarget) {
|
||||
UpdateParentTarget();
|
||||
|
|
|
@ -20,8 +20,6 @@ support-files =
|
|||
[test_blockParsing.html]
|
||||
[test_blocking_image.html]
|
||||
[test_bug419527.xhtml]
|
||||
[test_bug715041.xul]
|
||||
[test_bug715041_removal.xul]
|
||||
[test_bug945152.html]
|
||||
[test_bug1008126.html]
|
||||
[test_bug1016960.html]
|
||||
|
|
|
@ -1,808 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=715041
|
||||
-->
|
||||
<window title="Mozilla Bug 715041"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
|
||||
<!-- test results are displayed in the html:body -->
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=715041"
|
||||
target="_blank">Mozilla Bug 715041</a>
|
||||
</body>
|
||||
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Mock Idle Service Test for Bug 715041 **/
|
||||
//class mock javascript idle service
|
||||
var idleServiceObj = {
|
||||
observers: [],
|
||||
windowObservers: [],
|
||||
idleTimeInMS: 5000, //in milli seconds
|
||||
|
||||
// takes note of the idle observers added as the minimum idle observer
|
||||
// with the idle service
|
||||
timesAdded: [],
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsISupports) ||
|
||||
iid.equals(Ci.nsIFactory) ||
|
||||
iid.equals(Ci.nsIIdleService)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
|
||||
createInstance: function(outer, iid) {
|
||||
return this.QueryInterface(iid);
|
||||
},
|
||||
|
||||
get idleTime() {
|
||||
return this.idleTimeInMS; //in milli seconds
|
||||
},
|
||||
|
||||
set idleTime(timeInMS) {
|
||||
this.idleTimeInMS = timeInMS;
|
||||
},
|
||||
|
||||
getWindowFromObserver: function(observer) {
|
||||
try {
|
||||
var interfaceRequestor = observer.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||
var window = interfaceRequestor.getInterface(Ci.nsIDOMWindow);
|
||||
return window;
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
testIdleBackService: function(observer, topic) {
|
||||
dump("\nJS FAKE IDLE SERVICE\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
|
||||
if (this.observers.length > 1) {
|
||||
this.observers[1].observer.observe(observer, topic, '\0');
|
||||
dump("JS CALLED OBSERVE FUNCTION!!!\n\n");
|
||||
}
|
||||
},
|
||||
|
||||
addIdleObserver: function(observer, time) {
|
||||
dump("\nJS FAKE IDLE SERVICE add idle observer before\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
|
||||
var window = this.getWindowFromObserver(observer);
|
||||
dump("window is: " + window + "\n");
|
||||
|
||||
if (window) {
|
||||
this.observers.push({ observer: observer, time: time, });
|
||||
addedIdleObserver = true;
|
||||
numIdleObserversAdded++;
|
||||
this.timesAdded.push(time);
|
||||
|
||||
dump ("\nMOCK IDLE SERVICE ADDING idle observer with time: " + time + "\n");
|
||||
dump("MOCK IDLE SERVICE: num idle observers added: " + numIdleObserversAdded + "\n\n");
|
||||
}
|
||||
else {
|
||||
dump("SHOULD NEVER GET HERE!");
|
||||
oldIdleService.addIdleObserver(observer, time);
|
||||
addedIdleObserver = false;
|
||||
}
|
||||
|
||||
dump("\nJS FAKE IDLE SERVICE end of add idle observer\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
},
|
||||
|
||||
removeIdleObserver: function(observer, time) {
|
||||
dump("\nJS REMOVE IDLE OBSERVER () time to be removed: " + time + "\n");
|
||||
var window = this.getWindowFromObserver(observer);
|
||||
if (!window) {
|
||||
oldIdleService.removeIdleObserver(observer, time);
|
||||
}
|
||||
else {
|
||||
var observerIndex = -1;
|
||||
for (var i=0; i<this.observers.length; i++) {
|
||||
dump("JS removeIdleObserver() observer time: " + this.observers[i].time + "\n");
|
||||
if (this.observers[i].time === time) {
|
||||
observerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (observerIndex != -1 && this.observers.length > 0) {
|
||||
numIdleObserversRemoved++;
|
||||
this.observers.splice(observerIndex, 1);
|
||||
removedIdleObserver = true;
|
||||
dump("MOCK IDLE SERVICE REMOVING idle observer with time " + time + "\n");
|
||||
dump("MOCK IDLE SERVICE numIdleObserversRemoved: " + numIdleObserversRemoved + " numIdleObserversAdded: " + numIdleObserversAdded + "\n\n");
|
||||
}
|
||||
else {
|
||||
removedIdleObserver = false;
|
||||
}
|
||||
}
|
||||
dump("\nJS FAKE IDLE SERVICE end of remove idle observer\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
},
|
||||
};
|
||||
|
||||
/** Test for Bug 715041 **/
|
||||
dump("\n\n\nJS STARTING TESTING FOR BUG 715041\n");
|
||||
|
||||
//bool variables
|
||||
var addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
|
||||
|
||||
//test case enabled
|
||||
var AddOutOfOrderActiveEnabled = AddOutOfOrderIdleEnabled =
|
||||
AddShiftLocalEnabled = AddNewLocalWhileAllIdleEnabled =
|
||||
TestActiveToActiveNotification = ShiftLocalTimerBackEnabled =
|
||||
AddRemoveIdleObserverWithInvalidTimeEnabled = true;
|
||||
|
||||
//msgXCount
|
||||
var msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
|
||||
msg6Count = tcZero = currTestCaseNum = prevMsgNum =
|
||||
numIdleObserversRemoved = numIdleObserversAdded = 0;
|
||||
|
||||
//test case number
|
||||
var tcZero = 0;
|
||||
var tcAddOutOfOrderActive = 1;
|
||||
var tcAddOutOfOrderIdle = 2;
|
||||
var tcAddShiftLocal = 3;
|
||||
var tcAddNewLocalWhileAllIdle = 4;
|
||||
var tcShiftLocalTimerBack = 5;
|
||||
var tcAddRemoveIdleObserverWithInvalidTime = 6;
|
||||
var tcTestActiveToActiveNotification = 7;
|
||||
|
||||
function ResetMsgCounts() {
|
||||
msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
|
||||
msg6Count = prevMsgNum = 0;
|
||||
}
|
||||
|
||||
function ResetVars() {
|
||||
msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
|
||||
msg6Count = prevMsgNum = 0;
|
||||
|
||||
numIdleObserversAdded = numIdleObserversRemoved = 0;
|
||||
currTestCaseNum = -1;
|
||||
addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* - function printMsgCounts()
|
||||
*/
|
||||
function printMsgCounts() {
|
||||
dump("\nmsg0Count: " + msg0Count +
|
||||
"\nmsg1Count: " + msg1Count +
|
||||
"\nmsg2Count: " + msg2Count +
|
||||
"\nmsg3Count: " + msg3Count +
|
||||
"\nmsg5Count: " + msg5Count +
|
||||
"\nmsg6Count: " + msg6Count +
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
|
||||
function performNextTest() {
|
||||
dump("\nfunction performNextTest()\ncurrTestCaseNum: " + currTestCaseNum +
|
||||
"\ncleanUp: " + cleanUp +
|
||||
"\npassed: " + passed +
|
||||
"\nnumIdleObserversRemoved: " + numIdleObserversRemoved +
|
||||
"\nnumIdleObservesAdded: " + numIdleObserversAdded + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcZero:
|
||||
ok(passed, "Test case 0 failed clean up!");
|
||||
caseZeroCleanUp();
|
||||
break;
|
||||
case tcAddShiftLocal:
|
||||
if (cleanUp && numIdleObserversRemoved === 1) {
|
||||
passed = true;
|
||||
ok(passed, "Failed test case AddShiftLocalCleanUp()");
|
||||
if (AddNewLocalWhileAllIdleEnabled) {
|
||||
AddNewLocalWhileAllIdle();
|
||||
}
|
||||
else {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case tcAddNewLocalWhileAllIdle:
|
||||
ok(passed, "Failed test case: AddNewLocalWhileAllIdle()");
|
||||
AddNewLocalWhileAllIdleCleanUp();
|
||||
break;
|
||||
default:
|
||||
//do nothing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Place Holder.
|
||||
var idleHandler0 = function() { dump("rmsg 0, should never be used!\n"); };
|
||||
|
||||
//idleHandler1
|
||||
function idleHandler1() {
|
||||
msg1Count++;
|
||||
dump("msg 1 Count: " + msg1Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcAddOutOfOrderIdle:
|
||||
if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1) {
|
||||
idleServiceObj.idleTime = 0;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
|
||||
}
|
||||
else if (msg1Count === 4 && msg2Count === 4 && msg3Count === 4) {
|
||||
passed = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler2
|
||||
function idleHandler2() {
|
||||
msg2Count++;
|
||||
dump("msg 2 Count: " + msg2Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcZero:
|
||||
switch (msg2Count) {
|
||||
case 2:
|
||||
passed = true;
|
||||
performNextTest();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case tcAddOutOfOrderIdle:
|
||||
if (msg3Count === 1 && msg2Count === 1 && !msg1Count) {
|
||||
idleServiceObj.idleTime = 4000;
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
}
|
||||
break;
|
||||
case tcAddShiftLocal:
|
||||
if (!msg1Count && msg2Count === 1 && !msg3Count && !msg4Count) {
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
}
|
||||
AddShiftLocalCleanUp();
|
||||
break;
|
||||
case tcAddNewLocalWhileAllIdle:
|
||||
if (msg1Count === 1 && msg2Count === 2) {
|
||||
idleServiceObj.idleTime = 3500;
|
||||
window.navigator.addIdleObserver(idleObserversArray[5]);
|
||||
}
|
||||
break;
|
||||
case (tcShiftLocalTimerBack):
|
||||
if (!msg1Count && msg2Count === 1 && !msg3Count && !msg4Count && !msg5Count) {
|
||||
window.navigator.addIdleObserver(idleObserversArray[5]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler3
|
||||
function idleHandler3() {
|
||||
msg3Count++;
|
||||
dump("msg 3 Count: " + msg3Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case (tcAddOutOfOrderIdle):
|
||||
if (msg3Count === 1) {
|
||||
idleServiceObj.idleTime = 3500;
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
}
|
||||
if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2) {
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
else if (msg1Count === 3 && msg2Count === 3 && msg3Count === 3) {
|
||||
AddOutOfOrderIdle();
|
||||
}
|
||||
else if (msg1Count === 3 && msg2Count === 3 && msg3Count === 4) {
|
||||
passed = true;
|
||||
AddOutOfOrderIdleCleanUp();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler4
|
||||
function idleHandler4() {
|
||||
msg4Count++;
|
||||
dump("msg 4 Count: " + msg4Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcAddOutOfOrderActive:
|
||||
if (msg1Count && msg2Count && msg3Count && msg4Count) {
|
||||
passed = true;
|
||||
ok(passed, "idleHandler4: failed AddOutOfOrderActive()");
|
||||
AddOutOfOrderActiveCleanUp();
|
||||
cleanUp = true;
|
||||
}
|
||||
break;
|
||||
case tcAddShiftLocal:
|
||||
if (msg1Count === 1 && msg3Count === 1 && msg4Count === 1) {
|
||||
idleServiceObj.idleTime = 3200;
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler5
|
||||
function idleHandler5() {
|
||||
msg5Count++;
|
||||
dump("msg 5 Count: " + msg5Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcAddNewLocalWhileAllIdle:
|
||||
if (msg1Count === 1 && msg2Count === 2 && msg5Count === 1) {
|
||||
passed = true;
|
||||
performNextTest();
|
||||
}
|
||||
break;
|
||||
case tcShiftLocalTimerBack:
|
||||
if (!msg1Count && msg2Count === 1 && !msg3Count && msg4Count === 1 && msg5Count === 1) {
|
||||
passed = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler6
|
||||
function idleHandler6() {
|
||||
dump("msg 6 Count: " + msg6Count + "\n");
|
||||
}
|
||||
|
||||
var idleObserversArray = [];
|
||||
idleObserversArray[0] = {time: 0, onidle: idleHandler0, onactive: idleHandler0};
|
||||
idleObserversArray[1] = {time: 1, onidle: idleHandler1, onactive: idleHandler1};
|
||||
idleObserversArray[2] = {time: 2, onidle: idleHandler2, onactive: idleHandler2};
|
||||
idleObserversArray[3] = {time: 3, onidle: idleHandler3, onactive: idleHandler3};
|
||||
idleObserversArray[4] = {time: 4, onidle: idleHandler4, onactive: idleHandler4};
|
||||
idleObserversArray[5] = {time: 5, onidle: idleHandler5, onactive: idleHandler5};
|
||||
idleObserversArray[6] = {time: 0, onidle: idleHandler6, onactive: idleHandler6};
|
||||
idleObserversArray[7] = {time: 2, onidle: null, onactive: null};
|
||||
|
||||
idleServiceObj.observers.push( {observer: idleObserversArray[0], time: 0, } );
|
||||
|
||||
/*
|
||||
* - case 0
|
||||
* - AddSingleIdleObserver
|
||||
* - takes care of adding duplicate local too
|
||||
* - user is currently idle since the
|
||||
* requested idle time of 2s < current idle time of 5000ms set below.
|
||||
*/
|
||||
function caseZero() {
|
||||
dump("\n\nTESTING CASE 0\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcZero;
|
||||
idleServiceObj.idleTime = 5000;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
}
|
||||
|
||||
function caseZeroCleanUp() {
|
||||
dump("\ncaseZeroCleanUp()\n");
|
||||
dump("==============\n");
|
||||
ResetVars();
|
||||
currTestCaseNum = tcZero;
|
||||
cleanUp = false;
|
||||
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
|
||||
if (AddOutOfOrderActiveEnabled) {
|
||||
AddOutOfOrderActive();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
AddOutOfOrderActive()
|
||||
- Tests if the idle observer with the min time is always registered correctly
|
||||
with the idle service.
|
||||
*/
|
||||
function AddOutOfOrderActive() {
|
||||
dump("\n\nTESTING CASE AddOutOfOrderActive\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddOutOfOrderActive;
|
||||
idleServiceObj.idleTime = 500;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]); //msg3
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]); //msg4
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]); //msg1
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]); //msg2
|
||||
passed = false;
|
||||
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
/*
|
||||
- AddOutOfOrderActiveCleanUp()
|
||||
*/
|
||||
function AddOutOfOrderActiveCleanUp() {
|
||||
dump("\nAddOutOfOrderActiveCleanUp()\n");
|
||||
dump("==============================\n");
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddOutOfOrderActive;
|
||||
cleanUp = false;
|
||||
idleServiceObj.idleTime = 4500;
|
||||
|
||||
for (var i=1; i<5; i++) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[i]);
|
||||
}
|
||||
dump("JS AddOutOfOrderActiveCleanUp() DONE\n");
|
||||
if (AddOutOfOrderIdleEnabled) {
|
||||
AddOutOfOrderIdle();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- AddOutOfOrderIdle()
|
||||
*/
|
||||
function AddOutOfOrderIdle() {
|
||||
dump("\nAddOutOfOrderIdle()\n");
|
||||
dump("======================================================================\n");
|
||||
|
||||
dump("\nJS AddOutOfOrderIdle\n");
|
||||
dump("JS NUM OBSERVERS: " + idleServiceObj.observers.length + "\n");
|
||||
|
||||
if (!msg1Count && !msg2Count && !msg3Count) {
|
||||
ResetVars();
|
||||
}
|
||||
currTestCaseNum = tcAddOutOfOrderIdle;
|
||||
cleanUp = false;
|
||||
|
||||
if (!msg1Count && !msg2Count && !msg3Count) {
|
||||
idleServiceObj.idleTime = 3100;
|
||||
}
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
if (!msg1Count && !msg2Count && !msg3Count) {
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[3], "idle");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- AddOutOfOrderIdleCleanUp()
|
||||
*/
|
||||
function AddOutOfOrderIdleCleanUp() {
|
||||
ok(passed, "Failed test case: AddOutOfOrderIdle()");
|
||||
dump("\nAddOutOfOrderIdleCleanUp()\n");
|
||||
dump("==========================\n");
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddOutOfOrderIdle;
|
||||
cleanUp = true;
|
||||
idleServiceObj.idleTime = 4100;
|
||||
|
||||
for (var j=1; j<4; j++) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[j]);
|
||||
}
|
||||
window.navigator.removeIdleObserver(idleObserversArray[3]);
|
||||
|
||||
if (idleServiceObj.observers.length === 1) {
|
||||
passed = true;
|
||||
}
|
||||
else {
|
||||
passed = false;
|
||||
}
|
||||
ok(passed, "Failed test case: AddOutOfOrderIdleCleanUp()");
|
||||
if (AddShiftLocalEnabled) {
|
||||
AddShiftLocal();
|
||||
}
|
||||
else {
|
||||
dump("Finished AddOutOfOrderIdleCleanUp() test.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* function AddShiftLocal()
|
||||
* - user is idle
|
||||
* - check that local idle timer is shifted correctly
|
||||
* - msg 1 fired when user is idle
|
||||
* - msg 3 fired when 3000
|
||||
* - msg 2 fired immediately when added at 3200 ms
|
||||
* - msg 4 fired by local timer.
|
||||
*/
|
||||
function AddShiftLocal()
|
||||
{
|
||||
dump("\n\nTESTING CASE AddShiftLocal\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddShiftLocal;
|
||||
idleServiceObj.idleTime = 500;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
/*
|
||||
* function AddShiftLocalCleanUp()
|
||||
*/
|
||||
function AddShiftLocalCleanUp()
|
||||
{
|
||||
dump("\n\nTESTING CASE AddShiftLocalCleanUp\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddShiftLocal;
|
||||
|
||||
for (var i=1; i<5; i++) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[i]);
|
||||
}
|
||||
dump("AddShiftLocalCleanUp() done clean up\n");
|
||||
if (AddNewLocalWhileAllIdleEnabled) {
|
||||
AddNewLocalWhileAllIdle();
|
||||
}
|
||||
else {
|
||||
dump("Finished testing AddShiftLocal()\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* AddNewLocalWhileAllIdle()
|
||||
* - no local idle timer exists because all of the idle observers that were added had a requested
|
||||
* idle time of < curr user idle time and so were fired immediately. No local timer was required.
|
||||
* - now add an idle observer whose requested idle time is > current use idle time and > min idle
|
||||
* requested time in the list of idle observers.
|
||||
*/
|
||||
function AddNewLocalWhileAllIdle()
|
||||
{
|
||||
dump("\n\nTESTING CASE AddNewLocalWhileAllIdle\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddNewLocalWhileAllIdle;
|
||||
idleServiceObj.idleTime = 500;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function AddNewLocalWhileAllIdleCleanUp()
|
||||
{
|
||||
dump("\n\nTESTING CASE AddNewLocalWhileAllIdleCleanUp\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddNewLocalWhileAllIdle;
|
||||
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[5]);
|
||||
|
||||
if (ShiftLocalTimerBackEnabled) {
|
||||
ShiftLocalTimerBack();
|
||||
}
|
||||
else {
|
||||
dump("Finished testing TestActiveToActiveNotificationCleanUp()\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ShiftLocalTimerBack()
|
||||
* - add a new idle observer whose requested time is > current user idle time
|
||||
* but < the current local timer that has been set.
|
||||
* - the local timer will need to be reset to fire the new msg added.
|
||||
* RESULT
|
||||
* - should print all of them in order
|
||||
*/
|
||||
function ShiftLocalTimerBack()
|
||||
{
|
||||
dump("\n\nTESTING CASE ShiftLocalTimerBack()\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcShiftLocalTimerBack;
|
||||
idleServiceObj.idleTime = 2100;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
|
||||
}
|
||||
|
||||
function ShiftLocalTimerBackCleanUp()
|
||||
{
|
||||
dump("\n\nTESTING CASE ShiftLocalTimerBackCleanUp\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcShiftLocalTimerBack;
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[4]);
|
||||
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);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041.xul: ShiftLocalTimerBackCleanUp() Failed to unregister factory, mock idle service!\n");
|
||||
}
|
||||
|
||||
try {
|
||||
componentMgr.registerFactory(oldIdleServiceCID, "Re registering old idle service", idleServiceContractID, null);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041.xul: ShiftLocalTimerBackCleanUp() Failed to register factory, original idle service!\n");
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
/*
|
||||
* function AddRemoveIdleObserverWithInvalidTime()
|
||||
*/
|
||||
function AddRemoveIdleObserverWithInvalidTime()
|
||||
{
|
||||
dump("\n\nTESTING CASE AddRemoveIdleObserverWithInvalidTime()\n");
|
||||
dump("==============\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcAddRemoveIdleObserverWithInvalidTime;
|
||||
|
||||
//while idle
|
||||
idleServiceObj.idleTime = 2100;
|
||||
var rv = window.navigator.addIdleObserver(idleObserversArray[6]);
|
||||
dump("rv: " + rv + "\n");
|
||||
rv = window.navigator.removeIdleObserver(idleObserversArray[6]);
|
||||
|
||||
idleServiceObj.idleTime = 0;
|
||||
window.navigator.addIdleObserver(idleObserversArray[6]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[6]);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
try {
|
||||
var idleServiceCID = Components.ID("287075a6-f968-4516-8043-406c46f503b4");
|
||||
var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
|
||||
var oldIdleService = Cc[idleServiceContractID].getService(Ci.nsIIdleService);
|
||||
}
|
||||
catch(ex) {
|
||||
dump("test_bug715041.xul: 1) Failed to get old idle service.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
// Registering new moch JS idle service
|
||||
var componentMgr = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041.xul: Failed to query component registrar interface.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var oldIdleServiceFactoryObj = componentMgr.getClassObjectByContractID(idleServiceContractID, Ci.nsIFactory);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041.xul: Failed to get old idle service.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var oldIdleServiceCID = componentMgr.contractIDToCID(idleServiceContractID);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041.xul: Failed to convert ID to CID for old idle service.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
componentMgr.registerFactory(idleServiceCID, "Test Simple Idle/Back Notifications", idleServiceContractID, idleServiceObj);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041.xul: Failed to register mock idle service.\n");
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.requestLongerTimeout(10);
|
||||
|
||||
AddOutOfOrderActiveEnabled = true;
|
||||
AddOutOfOrderIdleEnabled = true;
|
||||
AddNewLocalWhileAllIdleEnabled = true;
|
||||
TestActiveToActiveNotificationEnabled = true;
|
||||
AddShiftLocalEnabled = true;
|
||||
AddIdleObserverWithInvalidTimeEnabled = false;
|
||||
|
||||
SpecialPowers.pushPrefEnv({"set":[['dom.idle-observers-api.fuzz_time.disabled', true]]}, caseZero);
|
||||
]]>
|
||||
</script>
|
||||
</window>
|
||||
|
|
@ -1,834 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=715041
|
||||
-->
|
||||
<window title="Mozilla Bug 715041"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||
|
||||
<!-- test results are displayed in the html:body -->
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=715041"
|
||||
target="_blank">Mozilla Bug 715041</a>
|
||||
</body>
|
||||
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Mock Idle Service Test for Bug 715041 **/
|
||||
try {
|
||||
var idleServiceCID = Components.ID("6f95d965-4322-4829-8a3c-5dc8a4587f4d");
|
||||
var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
|
||||
var oldIdleService = Cc[idleServiceContractID].getService(Ci.nsIIdleService);
|
||||
}
|
||||
catch (ex) {
|
||||
dump("test_bug715041_removal.xul: failed to get old idle service 1.");
|
||||
}
|
||||
|
||||
//class mock javascript idle service
|
||||
var idleServiceObj = {
|
||||
observers: [],
|
||||
windowObservers: [],
|
||||
idleTimeInMS: 5000, //in milli seconds
|
||||
|
||||
// takes note of the idle observers added as the minimum idle observer
|
||||
//with the idle service
|
||||
timesAdded: [],
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsISupports) ||
|
||||
iid.equals(Ci.nsIFactory) ||
|
||||
iid.equals(Ci.nsIIdleService)) {
|
||||
return this;
|
||||
}
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
|
||||
createInstance: function(outer, iid) {
|
||||
return this.QueryInterface(iid);
|
||||
},
|
||||
|
||||
get idleTime() {
|
||||
return this.idleTimeInMS; //in milli seconds
|
||||
},
|
||||
|
||||
set idleTime(timeInMS) {
|
||||
this.idleTimeInMS = timeInMS;
|
||||
},
|
||||
|
||||
getWindowFromObserver: function(observer) {
|
||||
try {
|
||||
var interfaceRequestor = observer.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||
var window = interfaceRequestor.getInterface(Ci.nsIDOMWindow);
|
||||
return window;
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
testIdleBackService: function(observer, topic) {
|
||||
dump("\nJS FAKE IDLE SERVICE\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
|
||||
if (this.observers.length > 1) {
|
||||
this.observers[1].observer.observe(observer, topic, '\0');
|
||||
dump("JS CALLED OBSERVE FUNCTION!!!\n\n");
|
||||
}
|
||||
},
|
||||
|
||||
addIdleObserver: function(observer, time) {
|
||||
dump("\nJS FAKE IDLE SERVICE add idle observer before\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
var window = this.getWindowFromObserver(observer);
|
||||
|
||||
if (window) {
|
||||
this.observers.push({ observer: observer, time: time, });
|
||||
addedIdleObserver = true;
|
||||
numIdleObserversAdded++;
|
||||
this.timesAdded.push(time);
|
||||
dump ("\nMOCK IDLE SERVICE ADDING idle observer with time: " + time + "\n");
|
||||
dump("MOCK IDLE SERVICE: num idle observers added: " + numIdleObserversAdded + "\n\n");
|
||||
}
|
||||
else {
|
||||
dump("SHOULD NEVER GET HERE!");
|
||||
oldIdleService.addIdleObserver(observer, time);
|
||||
addedIdleObserver = false;
|
||||
}
|
||||
|
||||
dump("\nJS FAKE IDLE SERVICE end of add idle observer\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
},
|
||||
|
||||
removeIdleObserver: function(observer, time) {
|
||||
dump("\nJS REMOVE IDLE OBSERVER () time to be removed: " + time + "\n");
|
||||
var window = this.getWindowFromObserver(observer);
|
||||
if (!window) {
|
||||
oldIdleService.removeIdleObserver(observer, time);
|
||||
}
|
||||
else {
|
||||
var observerIndex = -1;
|
||||
for (var i=0; i<this.observers.length; i++) {
|
||||
dump("JS removeIdleObserver() observer time: " + this.observers[i].time + "\n");
|
||||
if (this.observers[i].time === time) {
|
||||
observerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (observerIndex != -1 && this.observers.length > 0) {
|
||||
numIdleObserversRemoved++;
|
||||
this.observers.splice(observerIndex, 1);
|
||||
removedIdleObserver = true;
|
||||
dump("MOCK IDLE SERVICE REMOVING idle observer with time " + time + "\n");
|
||||
dump("MOCK IDLE SERVICE numIdleObserversRemoved: " + numIdleObserversRemoved + " numIdleObserversAdded: " + numIdleObserversAdded + "\n\n");
|
||||
}
|
||||
else {
|
||||
removedIdleObserver = false;
|
||||
}
|
||||
}
|
||||
dump("\nJS FAKE IDLE SERVICE end of remove idle observer\n");
|
||||
dump("JS NUM OBSERVERS: " + this.observers.length + "\n");
|
||||
},
|
||||
};
|
||||
|
||||
/** Test for Bug 715041 **/
|
||||
dump("\n\n\nJS STARTING TESTING FOR BUG 715041 REMOVAL\n");
|
||||
|
||||
//bool variables
|
||||
var addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
|
||||
|
||||
//msgXCount
|
||||
var msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
|
||||
msg6Count = tcZero = currTestCaseNum = prevMsgNum = 0;
|
||||
|
||||
//test case number
|
||||
var tcRemoveHeadIdleObserverWhileActive = 0;
|
||||
var tcRemoveLocalIdleObserverWhileIdle = 1;
|
||||
var tcRemoveHeadIdleObserver = 2;
|
||||
var tcRemoveLocalIdleTimerWhileIdle = 3;
|
||||
var tcRemoveLocalIdleTimerLastElement = 4;
|
||||
var tcRemoveHeadAfterLastLocalFired = 5;
|
||||
var tcRemoveHeadIdleObserverWhileIdleCase1 = 6;
|
||||
var tcRemoveLastAddLast = 7;
|
||||
|
||||
function ResetMsgCounts() {
|
||||
msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
|
||||
msg6Count = prevMsgNum = 0;
|
||||
}
|
||||
|
||||
function ResetVars() {
|
||||
msg0Count = msg1Count = msg2Count = msg3Count = msg4Count = msg5Count =
|
||||
msg6Count = prevMsgNum = 0;
|
||||
|
||||
numIdleObserversAdded = numIdleObserversRemoved = 0;
|
||||
currTestCaseNum = -1;
|
||||
addedIdleObserver = removedIdleObserver = passed = cleanUp = false;
|
||||
}
|
||||
|
||||
function printVariableValues()
|
||||
{
|
||||
dump("\nfunction printVariableValues()\ncurrTestCaseNum: " + currTestCaseNum +
|
||||
"\ncleanUp: " + cleanUp +
|
||||
"\npassed: " + passed +
|
||||
"\nnumIdleObserversRemoved: " + numIdleObserversRemoved +
|
||||
"\nnumIdleObservesAdded: " + numIdleObserversAdded +
|
||||
"\nmsg1Count " + msg1Count +
|
||||
"\nmsg2Count " + msg2Count +
|
||||
"\nmsg3Count " + msg3Count +
|
||||
"\nmsg4Count " + msg4Count +
|
||||
"\nmsg5Count " + msg5Count +
|
||||
"\n");
|
||||
}
|
||||
|
||||
//Place Holder.
|
||||
var idleHandler0 = function() { dump("msg 0, should never be used!\n"); };
|
||||
|
||||
//idleHandler1
|
||||
function idleHandler1() {
|
||||
msg1Count++;
|
||||
dump("msg 1 Count: " + msg1Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcRemoveHeadIdleObserver:
|
||||
if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
}
|
||||
break;
|
||||
case tcRemoveLocalIdleObserverWhileIdle:
|
||||
if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
}
|
||||
break;
|
||||
case tcRemoveLocalIdleTimerWhileIdle:
|
||||
if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
|
||||
idleServiceObj.idleTime = 2000;
|
||||
window.navigator.removeIdleObserver(idleObserversArray[3]);
|
||||
}
|
||||
break;
|
||||
case tcRemoveHeadIdleObserverWhileIdleCase1:
|
||||
if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count) {
|
||||
for (var i=1; i<4; i++) {
|
||||
window.navigator.addIdleObserver(idleObserversArray[i]);
|
||||
}
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
|
||||
idleServiceObj.idleTime = 1200;
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
}
|
||||
break;
|
||||
case tcRemoveLocalIdleTimerLastElement:
|
||||
if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
|
||||
idleServiceObj.idleTime = 1500;
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
idleServiceObj.idleTime = 1700;
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
idleServiceObj.idleTime = 2000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
|
||||
}
|
||||
break;
|
||||
case tcRemoveHeadAfterLastLocalFired:
|
||||
if (msg1Count === 1 && !msg2Count && !msg3Count && !msg4Count && !msg5Count) {
|
||||
dump("idle handler 1: case tcRemoveHeadAfterLastLocalFired:\n");
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
}
|
||||
break;
|
||||
case tcRemoveLastAddLast:
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler2
|
||||
function idleHandler2() {
|
||||
msg2Count++;
|
||||
dump("msg 2 Count: " + msg2Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcRemoveLocalIdleTimerLastElement:
|
||||
if (msg1Count === 1 && msg2Count === 1 && !msg3Count && !msg4Count) {
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[3]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler3
|
||||
function idleHandler3() {
|
||||
msg3Count++;
|
||||
dump("msg 3 Count: " + msg3Count + "\n");
|
||||
passed = false;
|
||||
switch (currTestCaseNum) {
|
||||
case tcRemoveHeadIdleObserverWhileActive:
|
||||
if (!msg1Count && msg2Count === 1 && msg3Count === 1) {
|
||||
passed = true;
|
||||
}
|
||||
dump("idleHandler3: passed: " + passed + "\n");
|
||||
RemoveHeadIdleObserverWhileActiveCleanUp();
|
||||
break;
|
||||
case tcRemoveHeadIdleObserverWhileIdleCase1:
|
||||
if (msg3Count != 2 && msg3Count != 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2 && !msg4Count) {
|
||||
passed = true;
|
||||
ok(passed, "Failed test case remove head idle observer while idle case 1, part 1.\n");
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg1Count === 3 && msg2Count === 4 && msg3Count === 4 &&
|
||||
!msg4Count && !msg5Count) {
|
||||
passed = true;
|
||||
}
|
||||
RemoveHeadIdleObserverWhileIdleCase1CleanUp();
|
||||
break;
|
||||
case tcRemoveLastAddLast:
|
||||
if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1
|
||||
&& !msg4Count && !msg5Count) {
|
||||
idleServiceObj.idleTime = 3200;
|
||||
window.navigator.removeIdleObserver(idleObserversArray[3]);
|
||||
idleServiceObj.idleTime = 3500;
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case tcRemoveHeadAfterLastLocalFired:
|
||||
if (msg3Count === 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg1Count === 2 && msg2Count === 2 && msg3Count === 2 && msg4Count === 1) {
|
||||
passed = true;
|
||||
}
|
||||
RemoveHeadAfterLastLocalFiredCleanUp();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler4
|
||||
function idleHandler4() {
|
||||
msg4Count++;
|
||||
dump("msg 4 Count: " + msg4Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
case tcRemoveLocalIdleObserverWhileIdle:
|
||||
if (msg1Count === 1 && !msg2Count && msg3Count === 1 && msg4Count === 1) {
|
||||
passed = true;
|
||||
RemoveLocalIdleObserverWhileIdleCleanUp();
|
||||
}
|
||||
break;
|
||||
case tcRemoveHeadIdleObserver:
|
||||
printVariableValues();
|
||||
if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count === 1) {
|
||||
passed = true;
|
||||
RemoveHeadIdleObserverCleanUp();
|
||||
}
|
||||
break;
|
||||
case tcRemoveLocalIdleTimerWhileIdle:
|
||||
if (msg1Count === 1 && !msg2Count && !msg3Count && msg4Count === 1) {
|
||||
passed = true;
|
||||
RemoveLocalIdleTimerWhileIdleCleanUp();
|
||||
}
|
||||
break
|
||||
case tcRemoveLocalIdleTimerLastElement:
|
||||
if (msg1Count === 1 && msg2Count === 1 && !msg3Count && msg4Count === 1) {
|
||||
passed = true;
|
||||
ok(passed, "Failed test case remove local idle timer last element.\n");
|
||||
RemoveLocalIdleTimerLastElementCleanUp();
|
||||
}
|
||||
break;
|
||||
case tcRemoveHeadAfterLastLocalFired:
|
||||
if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count === 1) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[4]);
|
||||
passed = true;
|
||||
ok(passed, "Failed remove head after last local fired.\n");
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "active");
|
||||
}
|
||||
break;
|
||||
case tcRemoveLastAddLast:
|
||||
if (msg1Count === 1 && msg2Count === 1 && msg3Count === 1 && msg4Count == 1) {
|
||||
idleServiceObj.idleTime = 4100;
|
||||
passed = true;
|
||||
RemoveLastAddLastCleanUp();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler5
|
||||
function idleHandler5() {
|
||||
msg5Count++;
|
||||
dump("msg 5 Count: " + msg5Count + "\n");
|
||||
|
||||
switch (currTestCaseNum) {
|
||||
|
||||
default:
|
||||
//do nothing.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//idleHandler6
|
||||
function idleHandler6() {
|
||||
dump("msg 6 Count: " + msg6Count + "\n");
|
||||
}
|
||||
|
||||
var idleObserversArray = [];
|
||||
idleObserversArray[0] = {time: 0, onidle: idleHandler0, onactive: idleHandler0};
|
||||
idleObserversArray[1] = {time: 1, onidle: idleHandler1, onactive: idleHandler1};
|
||||
idleObserversArray[2] = {time: 2, onidle: idleHandler2, onactive: idleHandler2};
|
||||
idleObserversArray[3] = {time: 3, onidle: idleHandler3, onactive: idleHandler3};
|
||||
idleObserversArray[4] = {time: 4, onidle: idleHandler4, onactive: idleHandler4};
|
||||
idleObserversArray[5] = {time: 5, onidle: idleHandler5, onactive: idleHandler5};
|
||||
idleObserversArray[6] = {time: 0, onidle: idleHandler6, onactive: idleHandler6};
|
||||
|
||||
//observers array space holder at index zero
|
||||
idleServiceObj.observers.push( {observer: idleObserversArray[0], time: 0, } );
|
||||
|
||||
/*
|
||||
* - function RemoveHeadIdleObserverWhileActive1()
|
||||
* - Remove head idle observer before the head idle notification is fired by the
|
||||
* idle service. I.e. remove the head idle observer while the user is active.
|
||||
* - RESULT: prints 2 in 2ms, 3
|
||||
*/
|
||||
function RemoveHeadIdleObserverWhileActive() {
|
||||
dump("\n\nTESTING CASE RemoveHeadIdleObserverWhileActive\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
|
||||
idleServiceObj.idleTime = 500;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
dump("test_bug715041_removal.xul: RemoveHeadIdleObserverWhileActive() idle time " + idleServiceObj.idleTime + "\n");
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
|
||||
idleServiceObj.idleTime = 800;
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[2], "idle");
|
||||
}
|
||||
|
||||
function RemoveHeadIdleObserverWhileActiveCleanUp() {
|
||||
dump("\nRemoveHeadIdleObserverWhileActiveCleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
dump("Passed: " + passed + "\n");
|
||||
ok(passed, "Failed test case: RemoveHeadIdleObserverWhileActive");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
|
||||
idleServiceObj.idleTime = 3500;
|
||||
|
||||
for (var i=2; i<4; i++) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[i]);
|
||||
}
|
||||
|
||||
dump("JS RemoveHeadIdleObserverWhileActiveCleanUp() DONE\n");
|
||||
if (RemoveLocalIdleObserverWhileIdleEnabled) {
|
||||
RemoveLocalIdleObserverWhileIdle();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* function RemoveLocalIdleObserverWhileIdle()
|
||||
* Remove local observer before the local oberver at index 1 is triggered while
|
||||
* the user is idle.
|
||||
* RESULT: should print 1, 3, 4
|
||||
*/
|
||||
function RemoveLocalIdleObserverWhileIdle() {
|
||||
dump("\n\nTESTING CASE RemoveLocalIdleObserverWhileIdle\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveLocalIdleObserverWhileIdle;
|
||||
idleServiceObj.idleTime = 500;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function RemoveLocalIdleObserverWhileIdleCleanUp() {
|
||||
dump("\nRemoveLocalIdleObserverWhileIdleCleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
ok(passed, "Failed test case: RemoveLocalIdleObserverWhileIdleCleanUp()");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadIdleObserverWhileActive;
|
||||
idleServiceObj.idleTime = 3500;
|
||||
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[3]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[4]);
|
||||
|
||||
dump("JS RemoveLocalIdleObserverWhileIdleCleanUp() DONE\n");
|
||||
if (RemoveHeadIdleObserverEnabled) {
|
||||
RemoveHeadIdleObserver();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* function RemoveHeadIdleObserver()
|
||||
* Remove head idle observer while the user has been idle for 2400 ms.
|
||||
* - RESULT: prints 1, 2, remove 2, 3, 4
|
||||
*/
|
||||
function RemoveHeadIdleObserver() {
|
||||
dump("\n\nTESTING CASE RemoveHeadIdleObserver\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadIdleObserver;
|
||||
idleServiceObj.idleTime = 500;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function RemoveHeadIdleObserverCleanUp() {
|
||||
dump("\nRemoveHeadIdleObserverCleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
ok(passed, "Failed test case: RemoveHeadIdleObserverCleanUp()");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadIdleObserver;
|
||||
idleServiceObj.idleTime = 3500;
|
||||
|
||||
for (var i=2; i<5; i++) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[i]);
|
||||
}
|
||||
|
||||
dump("JS RemoveHeadIdleObserverCleanUp() DONE\n");
|
||||
if (RemoveLocalIdleTimerWhileIdleEnabled) {
|
||||
RemoveLocalIdleTimerWhileIdle();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* RemoveLocalIdleTimerWhileIdle()
|
||||
* - Removes the idle observer that is also set as the current local idle timer callback
|
||||
* local idle observer being removed is NOT at index 1!
|
||||
* - RESULT: should trigger 1 in 1ms and 4 in 4ms
|
||||
*/
|
||||
function RemoveLocalIdleTimerWhileIdle()
|
||||
{
|
||||
dump("\n\nTESTING CASE RemoveLocalIdleTimerWhileIdle\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveLocalIdleTimerWhileIdle;
|
||||
idleServiceObj.idleTime = 500;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[3]);
|
||||
window.navigator.addIdleObserver(idleObserversArray[4]);
|
||||
|
||||
idleServiceObj.idleTime = 1000;
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function RemoveLocalIdleTimerWhileIdleCleanUp()
|
||||
{
|
||||
dump("\nRemoveLocalIdleTimerWhileIdleCleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
ok(passed, "Failed test case: RemoveLocalIdleTimerWhileIdleCleanUp()");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveLocalIdleTimerWhileIdle;
|
||||
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[4]);
|
||||
|
||||
dump("JS RemoveLocalIdleTimerWhileIdleCleanUp() DONE\n");
|
||||
if (RemoveLocalIdleTimerLastElementEnabled) {
|
||||
RemoveLocalIdleTimerLastElement();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* function RemoveLocalIdleTimerLastElement()
|
||||
*/
|
||||
function RemoveLocalIdleTimerLastElement()
|
||||
{
|
||||
dump("\n\nTESTING CASE RemoveLocalIdleTimerLastElement\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveLocalIdleTimerLastElement;
|
||||
idleServiceObj.idleTime = 1200;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function RemoveLocalIdleTimerLastElementCleanUp() {
|
||||
dump("\nRemoveLocalIdleTimerLastElementCleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
ok(passed, "Failed test case: RemoveLocalIdleTimerLastElementCleanUp()");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveLocalIdleTimerLastElement;
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[4]);
|
||||
|
||||
dump("JS RemoveLocalIdleTimerLastElementCleanUp() DONE\n");
|
||||
if (RemoveHeadAfterLastLocalFiredEnabled) {
|
||||
RemoveHeadAfterLastLocalFired();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- Remove the head after the last local idle timer has been fired
|
||||
- add 1 2 3 4
|
||||
- after 4 has been notified, removed idle observer with time 4
|
||||
- send a back topic
|
||||
- message notification should be 1, 2, 3.
|
||||
*/
|
||||
function RemoveHeadAfterLastLocalFired()
|
||||
{
|
||||
dump("\n\nTESTING CASE RemoveHeadAfterLastLocalFired\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadAfterLastLocalFired;
|
||||
idleServiceObj.idleTime = 1200;
|
||||
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function RemoveHeadAfterLastLocalFiredCleanUp() {
|
||||
dump("\RemoveHeadAfterLastLocalFiredCleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
ok(passed, "Failed test case: RemoveHeadAfterLastLocalFiredCleanUp()");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadAfterLastLocalFired;
|
||||
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[3]);
|
||||
|
||||
dump("JS RemoveHeadAfterLastLocalFiredCleanUp() DONE\n");
|
||||
if (RemoveHeadIdleObserverWhileIdleCase1Enabled) {
|
||||
RemoveHeadIdleObserverWhileIdleCase1();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
function RemoveHeadIdleObserverWhileIdleCase1() {
|
||||
dump("\n\nTESTING CASE RemoveHeadIdleObserverWhileIdleCase1\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadIdleObserverWhileIdleCase1;
|
||||
idleServiceObj.idleTime = 1000;
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function RemoveHeadIdleObserverWhileIdleCase1CleanUp() {
|
||||
dump("\nRemoveHeadIdleObserverWhileIdleCase1CleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
ok(passed, "Failed test case: RemoveHeadIdleObserverWhileIdleCase1CleanUp()");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveHeadIdleObserverWhileIdleCase1;
|
||||
|
||||
for (var i=1; i<4; i++) {
|
||||
window.navigator.removeIdleObserver(idleObserversArray[i]);
|
||||
}
|
||||
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[3]);
|
||||
|
||||
dump("JS RemoveHeadIdleObserverWhileIdleCase1CleanUp() DONE\n");
|
||||
if (RemoveLastAddLastEnabled) {
|
||||
RemoveLastAddLast();
|
||||
}
|
||||
else {
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* - RemoveLastAddLast()
|
||||
*
|
||||
* - User is currently idle.
|
||||
* - Add callback 1, 2, 3,
|
||||
* - Remove callback 3 after 3200 MS. I.e. after callback 3 has been notified.
|
||||
* - Add callback 4 after 3500 MS
|
||||
* - Output: 1, 2, 3, 4
|
||||
*/
|
||||
function RemoveLastAddLast()
|
||||
{
|
||||
dump("\n\nTESTING CASE RemoveLastAddLast()\n");
|
||||
dump("=================================\n");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveLastAddLast;
|
||||
idleServiceObj.idleTime = 1000;
|
||||
window.navigator.addIdleObserver(idleObserversArray[1]);
|
||||
idleServiceObj.testIdleBackService(idleObserversArray[1], "idle");
|
||||
}
|
||||
|
||||
function RemoveLastAddLastCleanUp()
|
||||
{
|
||||
dump("\RemoveLastAddLastCleanUp()\n");
|
||||
dump("=====================================\n");
|
||||
|
||||
ok(passed, "Failed test case: RemoveLastAddLastCleanUp()");
|
||||
|
||||
ResetVars();
|
||||
currTestCaseNum = tcRemoveLastAddLast;
|
||||
|
||||
window.navigator.removeIdleObserver(idleObserversArray[1]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[2]);
|
||||
window.navigator.removeIdleObserver(idleObserversArray[4]);
|
||||
|
||||
if (numIdleObserversRemoved === 1 && !numIdleObserversAdded) {
|
||||
ok(true, "Failed test case: RemoveLastAddLastCleanUp()");
|
||||
}
|
||||
else {
|
||||
ok(false, "Failed test case: RemoveLastAddLastCleanUp()");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
componentMgr.unregisterFactory(idleServiceCID, idleServiceObj);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041_removal.xul: RemoveLastAddLastCleanUp() Failed to unregister factory, mock idle service!\n");
|
||||
}
|
||||
|
||||
try {
|
||||
componentMgr.registerFactory(oldIdleServiceCID, "Re registering old idle service", idleServiceContractID, null);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041_removal.xul: RemoveLastAddLastCleanUp() Failed to register factory, original idle service!\n");
|
||||
}
|
||||
|
||||
dump("JS RemoveLastAddLastCleanUp() DONE\n");
|
||||
dump("Finishing testing idle API.\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
||||
// Registering new moch JS idle service
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.requestLongerTimeout(10);
|
||||
|
||||
try {
|
||||
var idleServiceCID = Components.ID("0fdc1bbf-3868-4660-9855-0c2e376922bc");
|
||||
var idleServiceContractID = "@mozilla.org/widget/idleservice;1";
|
||||
var oldIdleService = Cc[idleServiceContractID].getService(Ci.nsIIdleService);
|
||||
}
|
||||
catch(ex) {
|
||||
dump("test_bug715041_removal.xul: 1) Failed to get old idle service.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
// Registering new moch JS idle service
|
||||
var componentMgr = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041_removal.xul: Failed to query component registrar interface.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var oldIdleServiceFactoryObj = componentMgr.getClassObjectByContractID(idleServiceContractID, Ci.nsIFactory);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041_removal.xul: Failed to get old idle service.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
var oldIdleServiceCID = componentMgr.contractIDToCID(idleServiceContractID);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041._removalxul: Failed to convert ID to CID for old idle service.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
componentMgr.registerFactory(idleServiceCID, "Test Simple Idle/Back Notifications", idleServiceContractID, idleServiceObj);
|
||||
}
|
||||
catch(err) {
|
||||
dump("test_bug715041_removal.xul: Failed to register mock idle service.\n");
|
||||
}
|
||||
|
||||
//test case enabled
|
||||
var RemoveLocalIdleObserverWhileIdleEnabled = true;
|
||||
var RemoveHeadIdleObserverEnabled = true;
|
||||
var RemoveLocalIdleTimerWhileIdleEnabled = true;
|
||||
var RemoveLocalIdleTimerLastElementEnabled = true;
|
||||
var RemoveHeadAfterLastLocalFiredEnabled = true;
|
||||
var RemoveHeadIdleObserverWhileIdleCase1Enabled = true;
|
||||
var RemoveLastAddLastEnabled = true;
|
||||
SpecialPowers.pushPrefEnv({"set":[['dom.idle-observers-api.fuzz_time.disabled', true]]}, RemoveHeadIdleObserverWhileActive);
|
||||
]]>
|
||||
</script>
|
||||
</window>
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
[DEFAULT]
|
||||
skip-if = os == 'android'
|
||||
|
||||
[test_idleapi_permissions.html]
|
||||
[test_innerScreen.xul]
|
||||
[test_offsets.xul]
|
||||
support-files = test_offsets.css test_offsets.js
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for idle api permissions</title>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
var idleObserver = {
|
||||
onidle: null,
|
||||
onactive: null
|
||||
};
|
||||
|
||||
function doAddIdleObserver(obs) {
|
||||
var i = document.createElement("iframe");
|
||||
document.body.appendChild(i);
|
||||
var added = false;
|
||||
try {
|
||||
i.contentWindow.navigator.addIdleObserver(obs);
|
||||
added = true;
|
||||
} catch (e) { }
|
||||
i.remove();
|
||||
return added;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// addIdleObserver checks whether time is > 0.
|
||||
this.idleObserver.time = 100;
|
||||
|
||||
SpecialPowers.pushPermissions([{type: "idle", allow: true, context: document}], () => {
|
||||
added = doAddIdleObserver(this.idleObserver, true);
|
||||
ok(added, "Should be able to add idle observer with permission.");
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(run_test);
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -175,14 +175,6 @@ partial interface Navigator {
|
|||
optional boolean persistent = true);
|
||||
};
|
||||
|
||||
callback interface MozIdleObserver {
|
||||
// Time is in seconds and is read only when idle observers are added
|
||||
// and removed.
|
||||
readonly attribute unsigned long time;
|
||||
void onidle();
|
||||
void onactive();
|
||||
};
|
||||
|
||||
partial interface Navigator {
|
||||
[Throws, Constant, Cached, NeedsCallerType]
|
||||
readonly attribute DOMString oscpu;
|
||||
|
@ -200,18 +192,6 @@ partial interface Navigator {
|
|||
// WebKit/Blink/Trident/Presto support this.
|
||||
[Affects=Nothing, DependsOn=Nothing]
|
||||
boolean javaEnabled();
|
||||
|
||||
/**
|
||||
* Navigator requests to add an idle observer to the existing window.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
void addIdleObserver(MozIdleObserver aIdleObserver);
|
||||
|
||||
/**
|
||||
* Navigator requests to remove an idle observer from the existing window.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
void removeIdleObserver(MozIdleObserver aIdleObserver);
|
||||
};
|
||||
|
||||
// NetworkInformation
|
||||
|
|
|
@ -5323,10 +5323,6 @@ pref("memory.dump_reports_on_oom", false);
|
|||
// Number of stack frames to capture in createObjectURL for about:memory.
|
||||
pref("memory.blob_report.stack_frames", 0);
|
||||
|
||||
// Disable idle observer fuzz, because only privileged content can access idle
|
||||
// observers (bug 780507).
|
||||
pref("dom.idle-observers-api.fuzz_time.disabled", true);
|
||||
|
||||
// Activates the activity monitor
|
||||
pref("io.activity.enabled", false);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче