blob: 16a094599d3e016b7e8bebdaffe4a889e5da8762 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/resource_coordinator/lifecycle_unit.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace resource_coordinator {
namespace {
class DummyLifecycleUnit : public LifecycleUnit {
public:
DummyLifecycleUnit() = default;
// LifecycleUnit:
base::string16 GetTitle() const override { return base::string16(); }
std::string GetIconURL() const override { return std::string(); }
SortKey GetSortKey() const override { return SortKey(); }
State GetState() const override { return State::LOADED; }
int GetEstimatedMemoryFreedOnDiscardKB() const override { return 0; }
bool CanDiscard(DiscardReason reason) const override { return false; }
bool Discard(DiscardReason discard_reason) override { return false; }
private:
DISALLOW_COPY_AND_ASSIGN(DummyLifecycleUnit);
};
} // namespace
TEST(LifecycleUnitTest, SortKeyComparison) {
constexpr base::TimeTicks kBaseTime;
LifecycleUnit::SortKey a(kBaseTime);
LifecycleUnit::SortKey b(kBaseTime + base::TimeDelta::FromHours(1));
LifecycleUnit::SortKey c(kBaseTime + base::TimeDelta::FromHours(2));
EXPECT_FALSE(a < a);
EXPECT_TRUE(a < b);
EXPECT_TRUE(a < c);
EXPECT_FALSE(b < a);
EXPECT_FALSE(b < b);
EXPECT_TRUE(b < c);
EXPECT_FALSE(c < a);
EXPECT_FALSE(c < b);
EXPECT_FALSE(c < c);
EXPECT_FALSE(a > a);
EXPECT_FALSE(a > b);
EXPECT_FALSE(a > c);
EXPECT_TRUE(b > a);
EXPECT_FALSE(b > b);
EXPECT_FALSE(b > c);
EXPECT_TRUE(c > a);
EXPECT_TRUE(c > b);
EXPECT_FALSE(c > c);
}
// Verify that GetID() returns different ids for different LifecycleUnits, but
// always the same id for the same LifecycleUnit.
TEST(LifecycleUnitTest, GetID) {
DummyLifecycleUnit a;
DummyLifecycleUnit b;
DummyLifecycleUnit c;
EXPECT_NE(a.GetID(), b.GetID());
EXPECT_NE(a.GetID(), c.GetID());
EXPECT_NE(b.GetID(), c.GetID());
EXPECT_EQ(a.GetID(), a.GetID());
EXPECT_EQ(b.GetID(), b.GetID());
EXPECT_EQ(c.GetID(), c.GetID());
}
} // namespace resource_coordinator