Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: chrome/browser/chromeos/memory/oom_priority_manager_unittest.cc

Issue 11879029: CrOS: Prefer discarding internal web UI pages when out of memory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit, rebase Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "chrome/browser/chromeos/memory/oom_priority_manager.h" 11 #include "chrome/browser/chromeos/memory/oom_priority_manager.h"
12 #include "chrome/common/url_constants.h"
13 #include "googleurl/src/gurl.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 namespace chromeos { 16 namespace chromeos {
15 17
16 typedef testing::Test OomPriorityManagerTest; 18 typedef testing::Test OomPriorityManagerTest;
17 19
18 namespace { 20 namespace {
19 enum TestIndicies { 21 enum TestIndicies {
20 kSelected, 22 kSelected,
21 kPinned, 23 kPinned,
22 kApp, 24 kApp,
23 kRecent, 25 kRecent,
24 kOld, 26 kOld,
25 kReallyOld, 27 kReallyOld,
26 kOldButPinned 28 kOldButPinned,
29 kReloadableUI,
27 }; 30 };
28 } // namespace 31 } // namespace
29 32
30 // Tests the sorting comparator so that we know it's producing the 33 // Tests the sorting comparator so that we know it's producing the
31 // desired order. 34 // desired order.
32 TEST_F(OomPriorityManagerTest, Comparator) { 35 TEST_F(OomPriorityManagerTest, Comparator) {
33 chromeos::OomPriorityManager::TabStatsList test_list; 36 chromeos::OomPriorityManager::TabStatsList test_list;
34 const base::TimeTicks now = base::TimeTicks::Now(); 37 const base::TimeTicks now = base::TimeTicks::Now();
35 38
36 // Add kSelected last to verify we are sorting the array. 39 // Add kSelected last to verify we are sorting the array.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 74 }
72 75
73 { 76 {
74 OomPriorityManager::TabStats stats; 77 OomPriorityManager::TabStats stats;
75 stats.is_pinned = true; 78 stats.is_pinned = true;
76 stats.last_selected = now - base::TimeDelta::FromDays(365); 79 stats.last_selected = now - base::TimeDelta::FromDays(365);
77 stats.renderer_handle = kOldButPinned; 80 stats.renderer_handle = kOldButPinned;
78 test_list.push_back(stats); 81 test_list.push_back(stats);
79 } 82 }
80 83
84 {
85 OomPriorityManager::TabStats stats;
86 stats.is_reloadable_ui = true;
87 stats.renderer_handle = kReloadableUI;
88 test_list.push_back(stats);
89 }
90
81 // This entry sorts to the front, so by adding it last we verify that 91 // This entry sorts to the front, so by adding it last we verify that
82 // we are actually sorting the array. 92 // we are actually sorting the array.
83 { 93 {
84 OomPriorityManager::TabStats stats; 94 OomPriorityManager::TabStats stats;
85 stats.is_selected = true; 95 stats.is_selected = true;
86 stats.renderer_handle = kSelected; 96 stats.renderer_handle = kSelected;
87 test_list.push_back(stats); 97 test_list.push_back(stats);
88 } 98 }
89 99
90 std::sort(test_list.begin(), 100 std::sort(test_list.begin(),
91 test_list.end(), 101 test_list.end(),
92 OomPriorityManager::CompareTabStats); 102 OomPriorityManager::CompareTabStats);
93 103
94 EXPECT_EQ(kSelected, test_list[0].renderer_handle); 104 EXPECT_EQ(kSelected, test_list[0].renderer_handle);
95 EXPECT_EQ(kPinned, test_list[1].renderer_handle); 105 EXPECT_EQ(kPinned, test_list[1].renderer_handle);
96 EXPECT_EQ(kOldButPinned, test_list[2].renderer_handle); 106 EXPECT_EQ(kOldButPinned, test_list[2].renderer_handle);
97 EXPECT_EQ(kApp, test_list[3].renderer_handle); 107 EXPECT_EQ(kApp, test_list[3].renderer_handle);
98 EXPECT_EQ(kRecent, test_list[4].renderer_handle); 108 EXPECT_EQ(kRecent, test_list[4].renderer_handle);
99 EXPECT_EQ(kOld, test_list[5].renderer_handle); 109 EXPECT_EQ(kOld, test_list[5].renderer_handle);
100 EXPECT_EQ(kReallyOld, test_list[6].renderer_handle); 110 EXPECT_EQ(kReallyOld, test_list[6].renderer_handle);
111 EXPECT_EQ(kReloadableUI, test_list[7].renderer_handle);
112 }
113
114 TEST_F(OomPriorityManagerTest, IsReloadableUI) {
115 EXPECT_TRUE(OomPriorityManager::IsReloadableUI(
116 GURL(chrome::kChromeUIDownloadsURL)));
117 EXPECT_TRUE(OomPriorityManager::IsReloadableUI(
118 GURL(chrome::kChromeUIHistoryURL)));
119 EXPECT_TRUE(OomPriorityManager::IsReloadableUI(
120 GURL(chrome::kChromeUINewTabURL)));
121 EXPECT_TRUE(OomPriorityManager::IsReloadableUI(
122 GURL(chrome::kChromeUISettingsURL)));
123
124 // Debugging URLs are not included.
125 EXPECT_FALSE(OomPriorityManager::IsReloadableUI(
126 GURL(chrome::kChromeUIDiscardsURL)));
127 EXPECT_FALSE(OomPriorityManager::IsReloadableUI(
128 GURL(chrome::kChromeUINetInternalsURL)));
129
130 // Prefix matches are included.
131 EXPECT_TRUE(OomPriorityManager::IsReloadableUI(
132 GURL("chrome://settings/fakeSetting")));
101 } 133 }
102 134
103 } // namespace chromeos 135 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698