OLD | NEW |
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 "chrome/browser/browser_process.h" | 5 #include "chrome/browser/browser_process.h" |
6 #include "chrome/browser/chromeos/memory/oom_priority_manager.h" | 6 #include "chrome/browser/chromeos/memory/oom_priority_manager.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
9 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 9 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 | 17 |
18 using content::OpenURLParams; | 18 using content::OpenURLParams; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 typedef InProcessBrowserTest OomPriorityManagerTest; | 22 typedef InProcessBrowserTest OomPriorityManagerTest; |
23 | 23 |
24 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { | 24 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { |
25 using content::WindowedNotificationObserver; | 25 using content::WindowedNotificationObserver; |
26 | 26 |
| 27 chromeos::OomPriorityManager* oom_priority_manager = |
| 28 g_browser_process->oom_priority_manager(); |
| 29 EXPECT_FALSE(oom_priority_manager->recent_tab_discard()); |
| 30 |
27 // Get three tabs open. | 31 // Get three tabs open. |
28 WindowedNotificationObserver load1( | 32 WindowedNotificationObserver load1( |
29 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 33 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
30 content::NotificationService::AllSources()); | 34 content::NotificationService::AllSources()); |
31 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), | 35 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), |
32 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); | 36 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); |
33 browser()->OpenURL(open1); | 37 browser()->OpenURL(open1); |
34 load1.Wait(); | 38 load1.Wait(); |
35 | 39 |
36 WindowedNotificationObserver load2( | 40 WindowedNotificationObserver load2( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 80 |
77 EXPECT_EQ(3, browser()->tab_strip_model()->count()); | 81 EXPECT_EQ(3, browser()->tab_strip_model()->count()); |
78 | 82 |
79 // Discard a tab. It should kill the first tab, since it was the oldest | 83 // Discard a tab. It should kill the first tab, since it was the oldest |
80 // and was not selected. | 84 // and was not selected. |
81 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); | 85 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); |
82 EXPECT_EQ(3, browser()->tab_strip_model()->count()); | 86 EXPECT_EQ(3, browser()->tab_strip_model()->count()); |
83 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); | 87 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); |
84 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1)); | 88 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1)); |
85 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); | 89 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); |
| 90 EXPECT_TRUE(oom_priority_manager->recent_tab_discard()); |
86 | 91 |
87 // Run discard again, make sure it kills the second tab. | 92 // Run discard again, make sure it kills the second tab. |
88 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); | 93 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); |
89 EXPECT_EQ(3, browser()->tab_strip_model()->count()); | 94 EXPECT_EQ(3, browser()->tab_strip_model()->count()); |
90 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); | 95 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); |
91 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); | 96 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); |
92 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); | 97 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); |
93 | 98 |
94 // Kill the third tab. It should not kill the last tab, since it is active | 99 // Kill the third tab. It should not kill the last tab, since it is active |
95 // tab. | 100 // tab. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 WindowedNotificationObserver back2( | 152 WindowedNotificationObserver back2( |
148 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 153 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
149 content::NotificationService::AllSources()); | 154 content::NotificationService::AllSources()); |
150 chrome::GoBack(browser(), CURRENT_TAB); | 155 chrome::GoBack(browser(), CURRENT_TAB); |
151 back2.Wait(); | 156 back2.Wait(); |
152 EXPECT_FALSE(chrome::CanGoBack(browser())); | 157 EXPECT_FALSE(chrome::CanGoBack(browser())); |
153 EXPECT_TRUE(chrome::CanGoForward(browser())); | 158 EXPECT_TRUE(chrome::CanGoForward(browser())); |
154 } | 159 } |
155 | 160 |
156 } // namespace | 161 } // namespace |
OLD | NEW |