summaryrefslogtreecommitdiffstats
path: root/chrome/browser/oom_priority_manager_unittest.cc
diff options
context:
space:
mode:
authorgspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-26 22:40:10 +0000
committergspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-26 22:40:10 +0000
commitc777584f655b4e8dcb02a0bb92d0ae2a000612c0 (patch)
tree109a022ea04cd8dec1da51f76c328ae36f1ab236 /chrome/browser/oom_priority_manager_unittest.cc
parent765f4b8657d2b35e820caac25e9f12abb149723b (diff)
downloadchromium_src-c777584f655b4e8dcb02a0bb92d0ae2a000612c0.zip
chromium_src-c777584f655b4e8dcb02a0bb92d0ae2a000612c0.tar.gz
chromium_src-c777584f655b4e8dcb02a0bb92d0ae2a000612c0.tar.bz2
This adds a test for the oom priority manager comparator
so that we know that the priority we get is the one we expect. While writing this, I found a bug in the comparator (time threshold was being incorrectly applied), which I fixed. BUG=none TEST=Passed test on Linux. Review URL: http://codereview.chromium.org/7969006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/oom_priority_manager_unittest.cc')
-rw-r--r--chrome/browser/oom_priority_manager_unittest.cc116
1 files changed, 116 insertions, 0 deletions
diff --git a/chrome/browser/oom_priority_manager_unittest.cc b/chrome/browser/oom_priority_manager_unittest.cc
new file mode 100644
index 0000000..e7f2b58
--- /dev/null
+++ b/chrome/browser/oom_priority_manager_unittest.cc
@@ -0,0 +1,116 @@
+// Copyright (c) 2011 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/oom_priority_manager.h"
+
+#include <vector>
+#include <algorithm>
+
+#include "base/logging.h"
+#include "base/string16.h"
+#include "base/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace browser {
+
+typedef testing::Test OomPriorityManagerTest;
+
+// Tests the sorting comparator so that we know it's producing the
+// desired order.
+TEST_F(OomPriorityManagerTest, Comparator) {
+ browser::OomPriorityManager::TabStatsList test_list;
+ const base::TimeTicks now = base::TimeTicks::Now();
+ enum TestIndicies {
+ kMostImportant,
+ kNotPinned,
+ kNotSelected,
+ kSimilarTime,
+ kSimilarTimeOverThreshold,
+ kReallyOld,
+ kOldButPinned
+ };
+
+ {
+ OomPriorityManager::TabStats stats;
+ stats.is_selected = true;
+ stats.is_pinned = true;
+ stats.last_selected = now;
+ stats.renderer_handle = kMostImportant;
+ test_list.push_back(stats);
+ }
+
+ {
+ OomPriorityManager::TabStats stats;
+ stats.is_selected = true;
+ stats.is_pinned = false;
+ stats.last_selected = now;
+ stats.renderer_handle = kNotPinned;
+ test_list.push_back(stats);
+ }
+
+ {
+ OomPriorityManager::TabStats stats;
+ stats.is_selected = false;
+ stats.is_pinned = false;
+ stats.last_selected = now;
+ stats.renderer_handle = kNotSelected;
+ test_list.push_back(stats);
+ }
+
+ {
+ OomPriorityManager::TabStats stats;
+ stats.is_selected = false;
+ stats.is_pinned = false;
+ stats.last_selected = now - base::TimeDelta::FromSeconds(10);
+ stats.renderer_handle = kSimilarTime;
+ test_list.push_back(stats);
+ }
+
+ {
+ OomPriorityManager::TabStats stats;
+ stats.is_selected = false;
+ stats.is_pinned = false;
+ stats.last_selected = now - base::TimeDelta::FromMinutes(15);
+ stats.renderer_handle = kSimilarTimeOverThreshold;
+ test_list.push_back(stats);
+ }
+
+ {
+ OomPriorityManager::TabStats stats;
+ stats.is_selected = false;
+ stats.is_pinned = false;
+ stats.last_selected = now - base::TimeDelta::FromDays(365);
+ stats.renderer_handle = kReallyOld;
+ test_list.push_back(stats);
+ }
+
+ // This also is out of order, so verifies that we are actually
+ // sorting the array.
+ {
+ OomPriorityManager::TabStats stats;
+ stats.is_selected = false;
+ stats.is_pinned = true;
+ stats.last_selected = now - base::TimeDelta::FromDays(365);
+ stats.renderer_handle = kOldButPinned;
+ test_list.push_back(stats);
+ }
+
+ std::sort(test_list.begin(),
+ test_list.end(),
+ OomPriorityManager::CompareTabStats);
+
+ EXPECT_EQ(test_list[0].renderer_handle, kMostImportant);
+ EXPECT_EQ(test_list[1].renderer_handle, kNotPinned);
+ EXPECT_EQ(test_list[2].renderer_handle, kOldButPinned);
+ // The order of kNotSelected and kSimilarTime is indeterminate:
+ // they are equal in the eyes of the sort.
+ EXPECT_TRUE((test_list[3].renderer_handle == kNotSelected &&
+ test_list[4].renderer_handle == kSimilarTime) ||
+ (test_list[3].renderer_handle == kSimilarTime &&
+ test_list[4].renderer_handle == kNotSelected));
+ EXPECT_EQ(test_list[5].renderer_handle, kSimilarTimeOverThreshold);
+ EXPECT_EQ(test_list[6].renderer_handle, kReallyOld);
+}
+
+} // namespace browser