#include "athena/activity/public/activity_view_model.h"
#include "athena/resource_manager/memory_pressure_notifier.h"
#include "athena/resource_manager/public/resource_manager.h"
-#include "athena/test/athena_test_base.h"
-#include "athena/test/sample_activity.h"
+#include "athena/test/base/athena_test_base.h"
+#include "athena/test/base/sample_activity.h"
#include "athena/wm/public/window_manager.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/gfx/image/image_skia.h"
: SampleActivity(0, 0, base::UTF8ToUTF16(title)),
media_state_(ACTIVITY_MEDIA_STATE_NONE),
is_visible_(false) {}
- virtual ~TestActivity() {}
+ ~TestActivity() override {}
void set_media_state(ActivityMediaState media_state) {
media_state_ = media_state;
void set_visible(bool visible) { is_visible_ = visible; }
// Activity overrides:
- virtual bool IsVisible() OVERRIDE { return is_visible_; }
- virtual ActivityMediaState GetMediaState() OVERRIDE { return media_state_; }
+ virtual bool IsVisible() override { return is_visible_; }
+ virtual ActivityMediaState GetMediaState() override { return media_state_; }
private:
// The current media state.
class ResourceManagerTest : public AthenaTestBase {
public:
ResourceManagerTest() {}
- virtual ~ResourceManagerTest() {}
+ ~ResourceManagerTest() override {}
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
AthenaTestBase::SetUp();
// Override the delay to be instantaneous.
ResourceManager::Get()->SetWaitTimeBetweenResourceManageCalls(0);
}
- virtual void TearDown() OVERRIDE {
+ virtual void TearDown() override {
while (!activity_list_.empty())
DeleteActivity(activity_list_[0]);
AthenaTestBase::TearDown();
// Call the resource manager and say we are in a critical memory condition.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState());
// Calling it a second time will release the second app.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState());
// Calling it once more will change nothing.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable1->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable2->GetCurrentState());
// Calling it with a critical situation first, it will release the non media
// locked app.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_media_locked1->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable->GetCurrentState());
// Calling it the second time, the oldest media playing activity will get
// unloaded.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_media_locked1->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable->GetCurrentState());
// Calling it the third time, the oldest media playing activity will get
// unloaded.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
DCHECK_NE(Activity::ACTIVITY_UNLOADED, app_visible->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_media_locked1->GetCurrentState());
DCHECK_EQ(Activity::ACTIVITY_UNLOADED, app_unloadable->GetCurrentState());
// Applying low resource pressure should keep everything as is.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_LOW);
+ ResourceManager::MEMORY_PRESSURE_LOW);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
// This is testing an internal algorithm constant, but for the time being
// this should suffice.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_MODERATE);
+ ResourceManager::MEMORY_PRESSURE_MODERATE);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
// Applying higher pressure should get rid of everything unneeded.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app3->GetCurrentState());
// Going back to a relaxed memory pressure should reload the old activities.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_LOW);
+ ResourceManager::MEMORY_PRESSURE_LOW);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app3->GetCurrentState());
// Applying low resource pressure should turn one item invisible.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
// Trying to apply the memory pressure again does not do anything.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
// Waiting and applying the pressure again should unload it.
usleep(kTimeoutOverrideInMs * 1000);
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app2->GetCurrentState());
}
// Applying higher pressure should get rid of everything unneeded.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app3->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app3->GetCurrentState());
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
kTimeoutOverrideInMs);
// Applying higher pressure should get unload the oldest activity.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app3->GetCurrentState());
// Trying to apply the resource pressure again within the timeout time should
// not trigger any operation.
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app3->GetCurrentState());
// Passing the timeout however should allow for another call.
usleep(kTimeoutOverrideInMs * 1000);
ResourceManager::Get()->SetMemoryPressureAndStopMonitoring(
- MemoryPressureObserver::MEMORY_PRESSURE_CRITICAL);
+ ResourceManager::MEMORY_PRESSURE_CRITICAL);
EXPECT_EQ(Activity::ACTIVITY_VISIBLE, app1->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_INVISIBLE, app2->GetCurrentState());
EXPECT_EQ(Activity::ACTIVITY_UNLOADED, app3->GetCurrentState());