Quelle TestAvailableMemoryWatcherMac.cpp
Sprache: C
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The message queue can be empty and the loop stops // waiting for a new event before detecting timeout. // Creating a timer to fire a timeout event.
nsCOMPtr<nsITimer> timer;
NS_NewTimerWithFuncCallback(
getter_AddRefs(timer),
[](nsITimer*, void* isTimeout) {
*reinterpret_cast<bool*>(isTimeout) = true;
},
&isTimeout, aTimeoutMs, nsITimer::TYPE_ONE_SHOT, __func__);
// Force the loop to move in case that there is no event in the queue.
nsCOMPtr<nsIRunnable> dummyEvent = new Runnable(__func__);
NS_DispatchToMainThread(dummyEvent);
} return NS_OK;
}
/* * Test the browser memory pressure reponse by artificially putting the system * into the "critical" level and ensuring 1) a tab unload attempt occurs and * 2) the Gecko memory-pressure notitificiation start and stop events occur.
*/
TEST_F(AvailableMemoryWatcherFixture, MemoryPressureResponse) { // Set the memory pressure state to normal in case we are already // running in a low memory pressure state.
mWatcher->OnMemoryPressureChanged(MacMemoryPressureLevel::Value::eNormal);
// Reset state
mTabUnloader->ResetCounter();
AutoJSContextWithGlobal cx(mCleanGlobal);
MemoryWatcherTelemetryEvent telemetryEvent(cx.GetJSContext());
// Simulate a low memory OS callback and make sure we observe // a memory-pressure event and a tab unload.
mLowMemoryObserver->StartListening();
mWatcher->OnMemoryPressureChanged(MacMemoryPressureLevel::Value::eWarning);
mWatcher->OnMemoryPressureChanged(MacMemoryPressureLevel::Value::eCritical);
EXPECT_TRUE(WaitUntil([this]() { return mTabUnloader->GetCounter() >= 1; },
kStateChangeTimeoutMs));
EXPECT_TRUE(mLowMemoryObserver->Wait(kStateChangeTimeoutMs));
// Simulate the normal memory pressure OS callback and make // sure we observe a memory-pressure-stop event.
mHighMemoryObserver->StartListening();
mWatcher->OnMemoryPressureChanged(MacMemoryPressureLevel::Value::eWarning);
mWatcher->OnMemoryPressureChanged(MacMemoryPressureLevel::Value::eNormal);
EXPECT_TRUE(mHighMemoryObserver->Wait(kStateChangeTimeoutMs));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.