1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// 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 "chrome/browser/browser_process.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "googleurl/src/gurl.h"
namespace {
class OomPriorityManagerTest : public InProcessBrowserTest {
};
IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) {
using namespace ui_test_utils;
// Get three tabs open. Load asynchronously to speed up the test.
WindowedNotificationObserver load1(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
OpenURLParams open1(GURL("chrome://about"), GURL(),
CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open1);
WindowedNotificationObserver load2(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
OpenURLParams open2(GURL("chrome://credits"), GURL(),
NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
false);
browser()->OpenURL(open2);
WindowedNotificationObserver load3(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
OpenURLParams open3(GURL("chrome://terms"), GURL(),
NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
false);
browser()->OpenURL(open3);
load1.Wait();
load2.Wait();
load3.Wait();
EXPECT_EQ(3, browser()->tab_count());
// Discard a tab. It should kill the first tab, since it was the oldest
// and was not selected.
EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab());
EXPECT_EQ(3, browser()->tab_count());
EXPECT_TRUE(browser()->IsTabDiscarded(0));
EXPECT_FALSE(browser()->IsTabDiscarded(1));
EXPECT_FALSE(browser()->IsTabDiscarded(2));
// Run discard again, make sure it kills the second tab.
g_browser_process->oom_priority_manager()->DiscardTab();
EXPECT_EQ(3, browser()->tab_count());
EXPECT_TRUE(browser()->IsTabDiscarded(0));
EXPECT_TRUE(browser()->IsTabDiscarded(1));
EXPECT_FALSE(browser()->IsTabDiscarded(2));
// Kill the third tab
EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab());
EXPECT_TRUE(browser()->IsTabDiscarded(0));
EXPECT_TRUE(browser()->IsTabDiscarded(1));
EXPECT_TRUE(browser()->IsTabDiscarded(2));
// Running when all tabs are discarded should do nothing.
EXPECT_FALSE(g_browser_process->oom_priority_manager()->DiscardTab());
// Select the first tab. It should reload.
WindowedNotificationObserver reload1(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
browser()->SelectNumberedTab(0);
reload1.Wait();
EXPECT_FALSE(browser()->IsTabDiscarded(0));
EXPECT_TRUE(browser()->IsTabDiscarded(1));
EXPECT_TRUE(browser()->IsTabDiscarded(2));
}
} // namespace
|