Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / memory / oom_priority_manager_unittest.cc
blobb7eb8eb0d04172d74437ee4a6e1170fcd27ea21b
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
3 // found in the LICENSE file.
5 #include "chrome/browser/memory/oom_priority_manager.h"
7 #include <algorithm>
8 #include <vector>
10 #include "base/logging.h"
11 #include "base/strings/string16.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/memory/tab_stats.h"
14 #include "chrome/common/url_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h"
18 namespace memory {
20 typedef testing::Test OomPriorityManagerTest;
22 namespace {
23 enum TestIndicies {
24 kSelected,
25 kPinned,
26 kApp,
27 kPlayingAudio,
28 kRecent,
29 kOld,
30 kReallyOld,
31 kOldButPinned,
32 kInternalPage,
34 } // namespace
36 // Tests the sorting comparator so that we know it's producing the
37 // desired order.
38 TEST_F(OomPriorityManagerTest, Comparator) {
39 TabStatsList test_list;
40 const base::TimeTicks now = base::TimeTicks::Now();
42 // Add kSelected last to verify we are sorting the array.
45 TabStats stats;
46 stats.is_pinned = true;
47 stats.child_process_host_id = kPinned;
48 test_list.push_back(stats);
52 TabStats stats;
53 stats.is_app = true;
54 stats.child_process_host_id = kApp;
55 test_list.push_back(stats);
59 TabStats stats;
60 stats.is_playing_audio = true;
61 stats.child_process_host_id = kPlayingAudio;
62 test_list.push_back(stats);
66 TabStats stats;
67 stats.last_active = now - base::TimeDelta::FromSeconds(10);
68 stats.child_process_host_id = kRecent;
69 test_list.push_back(stats);
73 TabStats stats;
74 stats.last_active = now - base::TimeDelta::FromMinutes(15);
75 stats.child_process_host_id = kOld;
76 test_list.push_back(stats);
80 TabStats stats;
81 stats.last_active = now - base::TimeDelta::FromDays(365);
82 stats.child_process_host_id = kReallyOld;
83 test_list.push_back(stats);
87 TabStats stats;
88 stats.is_pinned = true;
89 stats.last_active = now - base::TimeDelta::FromDays(365);
90 stats.child_process_host_id = kOldButPinned;
91 test_list.push_back(stats);
95 TabStats stats;
96 stats.is_internal_page = true;
97 stats.child_process_host_id = kInternalPage;
98 test_list.push_back(stats);
101 // This entry sorts to the front, so by adding it last we verify that
102 // we are actually sorting the array.
104 TabStats stats;
105 stats.is_selected = true;
106 stats.child_process_host_id = kSelected;
107 test_list.push_back(stats);
110 std::sort(test_list.begin(), test_list.end(),
111 OomPriorityManager::CompareTabStats);
113 int index = 0;
114 EXPECT_EQ(kSelected, test_list[index++].child_process_host_id);
115 EXPECT_EQ(kPlayingAudio, test_list[index++].child_process_host_id);
116 EXPECT_EQ(kPinned, test_list[index++].child_process_host_id);
117 EXPECT_EQ(kOldButPinned, test_list[index++].child_process_host_id);
118 EXPECT_EQ(kApp, test_list[index++].child_process_host_id);
119 EXPECT_EQ(kRecent, test_list[index++].child_process_host_id);
120 EXPECT_EQ(kOld, test_list[index++].child_process_host_id);
121 EXPECT_EQ(kReallyOld, test_list[index++].child_process_host_id);
122 EXPECT_EQ(kInternalPage, test_list[index++].child_process_host_id);
125 TEST_F(OomPriorityManagerTest, IsInternalPage) {
126 EXPECT_TRUE(
127 OomPriorityManager::IsInternalPage(GURL(chrome::kChromeUIDownloadsURL)));
128 EXPECT_TRUE(
129 OomPriorityManager::IsInternalPage(GURL(chrome::kChromeUIHistoryURL)));
130 EXPECT_TRUE(
131 OomPriorityManager::IsInternalPage(GURL(chrome::kChromeUINewTabURL)));
132 EXPECT_TRUE(
133 OomPriorityManager::IsInternalPage(GURL(chrome::kChromeUISettingsURL)));
135 // Debugging URLs are not included.
136 #if defined(OS_CHROMEOS)
137 EXPECT_FALSE(
138 OomPriorityManager::IsInternalPage(GURL(chrome::kChromeUIDiscardsURL)));
139 #endif
140 EXPECT_FALSE(OomPriorityManager::IsInternalPage(
141 GURL(chrome::kChromeUINetInternalsURL)));
143 // Prefix matches are included.
144 EXPECT_TRUE(OomPriorityManager::IsInternalPage(
145 GURL("chrome://settings/fakeSetting")));
148 } // namespace memory