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

Side by Side Diff: chrome/browser/memory/oom_priority_manager_browsertest_chromeos.cc

Issue 1188823002: [MemoryPressure] Move chrome/browser/chromeos/* to chrome/browser/memory/*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed sky@ comments. Created 5 years, 6 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
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/memory_pressure_listener.h" 6 #include "base/memory/memory_pressure_listener.h"
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/browser_process_platform_part_chromeos.h" 8 #include "chrome/browser/browser_process_platform_part_chromeos.h"
9 #include "chrome/browser/chromeos/memory/oom_priority_manager.h" 9 #include "chrome/browser/memory/oom_priority_manager.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h" 11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 12 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chromeos/chromeos_switches.h" 16 #include "chromeos/chromeos_switches.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
19 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
20 #include "url/gurl.h" 20 #include "url/gurl.h"
21 21
22 using content::OpenURLParams; 22 using content::OpenURLParams;
23 23
24 namespace memory {
24 namespace { 25 namespace {
25 26
26 typedef InProcessBrowserTest OomPriorityManagerTest; 27 typedef InProcessBrowserTest OomPriorityManagerTest;
27 28
28 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { 29 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) {
29 using content::WindowedNotificationObserver; 30 using content::WindowedNotificationObserver;
30 31
31 chromeos::OomPriorityManager* oom_priority_manager = 32 OomPriorityManager* oom_priority_manager =
32 g_browser_process->platform_part()->oom_priority_manager(); 33 g_browser_process->platform_part()->oom_priority_manager();
33 EXPECT_FALSE(oom_priority_manager->recent_tab_discard()); 34 EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
34 35
35 // Get three tabs open. 36 // Get three tabs open.
36 WindowedNotificationObserver load1( 37 WindowedNotificationObserver load1(
37 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 38 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
38 content::NotificationService::AllSources()); 39 content::NotificationService::AllSources());
39 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 40 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
40 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); 41 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
41 browser()->OpenURL(open1); 42 browser()->OpenURL(open1);
42 load1.Wait(); 43 load1.Wait();
43 44
44 WindowedNotificationObserver load2( 45 WindowedNotificationObserver load2(
45 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 46 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
46 content::NotificationService::AllSources()); 47 content::NotificationService::AllSources());
47 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(), 48 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
48 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, 49 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false);
49 false);
50 browser()->OpenURL(open2); 50 browser()->OpenURL(open2);
51 load2.Wait(); 51 load2.Wait();
52 52
53 WindowedNotificationObserver load3( 53 WindowedNotificationObserver load3(
54 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 54 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
55 content::NotificationService::AllSources()); 55 content::NotificationService::AllSources());
56 OpenURLParams open3(GURL(chrome::kChromeUITermsURL), content::Referrer(), 56 OpenURLParams open3(GURL(chrome::kChromeUITermsURL), content::Referrer(),
57 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, 57 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false);
58 false);
59 browser()->OpenURL(open3); 58 browser()->OpenURL(open3);
60 load3.Wait(); 59 load3.Wait();
61 60
62 EXPECT_EQ(3, browser()->tab_strip_model()->count()); 61 EXPECT_EQ(3, browser()->tab_strip_model()->count());
63 62
64 // Navigate the current (third) tab to a different URL, so we can test 63 // Navigate the current (third) tab to a different URL, so we can test
65 // back/forward later. 64 // back/forward later.
66 WindowedNotificationObserver load4( 65 WindowedNotificationObserver load4(
67 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 66 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
68 content::NotificationService::AllSources()); 67 content::NotificationService::AllSources());
69 OpenURLParams open4(GURL(chrome::kChromeUIVersionURL), content::Referrer(), 68 OpenURLParams open4(GURL(chrome::kChromeUIVersionURL), content::Referrer(),
70 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 69 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
71 false);
72 browser()->OpenURL(open4); 70 browser()->OpenURL(open4);
73 load4.Wait(); 71 load4.Wait();
74 72
75 // Navigate the third tab again, such that we have three navigation entries. 73 // Navigate the third tab again, such that we have three navigation entries.
76 WindowedNotificationObserver load5( 74 WindowedNotificationObserver load5(
77 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 75 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
78 content::NotificationService::AllSources()); 76 content::NotificationService::AllSources());
79 OpenURLParams open5(GURL("chrome://dns"), content::Referrer(), 77 OpenURLParams open5(GURL("chrome://dns"), content::Referrer(), CURRENT_TAB,
80 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, 78 ui::PAGE_TRANSITION_TYPED, false);
81 false);
82 browser()->OpenURL(open5); 79 browser()->OpenURL(open5);
83 load5.Wait(); 80 load5.Wait();
84 81
85 EXPECT_EQ(3, browser()->tab_strip_model()->count()); 82 EXPECT_EQ(3, browser()->tab_strip_model()->count());
86 83
87 // Discard a tab. It should kill the first tab, since it was the oldest 84 // Discard a tab. It should kill the first tab, since it was the oldest
88 // and was not selected. 85 // and was not selected.
89 EXPECT_TRUE(oom_priority_manager->DiscardTab()); 86 EXPECT_TRUE(oom_priority_manager->DiscardTab());
90 EXPECT_EQ(3, browser()->tab_strip_model()->count()); 87 EXPECT_EQ(3, browser()->tab_strip_model()->count());
91 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); 88 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 content::NotificationService::AllSources()); 155 content::NotificationService::AllSources());
159 chrome::GoBack(browser(), CURRENT_TAB); 156 chrome::GoBack(browser(), CURRENT_TAB);
160 back2.Wait(); 157 back2.Wait();
161 EXPECT_FALSE(chrome::CanGoBack(browser())); 158 EXPECT_FALSE(chrome::CanGoBack(browser()));
162 EXPECT_TRUE(chrome::CanGoForward(browser())); 159 EXPECT_TRUE(chrome::CanGoForward(browser()));
163 } 160 }
164 161
165 // Test that the MemoryPressureListener event is properly triggering a tab 162 // Test that the MemoryPressureListener event is properly triggering a tab
166 // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event. 163 // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event.
167 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPressureListener) { 164 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPressureListener) {
168 chromeos::OomPriorityManager* oom_priority_manager = 165 OomPriorityManager* oom_priority_manager =
169 g_browser_process->platform_part()->oom_priority_manager(); 166 g_browser_process->platform_part()->oom_priority_manager();
170 // Get three tabs open. 167 // Get three tabs open.
171 content::WindowedNotificationObserver load1( 168 content::WindowedNotificationObserver load1(
172 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 169 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
173 content::NotificationService::AllSources()); 170 content::NotificationService::AllSources());
174 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 171 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
175 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); 172 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
176 browser()->OpenURL(open1); 173 browser()->OpenURL(open1);
177 load1.Wait(); 174 load1.Wait();
178 175
179 content::WindowedNotificationObserver load2( 176 content::WindowedNotificationObserver load2(
180 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 177 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
181 content::NotificationService::AllSources()); 178 content::NotificationService::AllSources());
182 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(), 179 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
183 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, 180 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false);
184 false);
185 browser()->OpenURL(open2); 181 browser()->OpenURL(open2);
186 load2.Wait(); 182 load2.Wait();
187 EXPECT_FALSE(oom_priority_manager->recent_tab_discard()); 183 EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
188 184
189 // Nothing should happen with a moderate memory pressure event. 185 // Nothing should happen with a moderate memory pressure event.
190 base::MemoryPressureListener::NotifyMemoryPressure( 186 base::MemoryPressureListener::NotifyMemoryPressure(
191 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); 187 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
192 EXPECT_FALSE(oom_priority_manager->recent_tab_discard()); 188 EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
193 189
194 // A critical memory pressure event should discard a tab. 190 // A critical memory pressure event should discard a tab.
195 base::MemoryPressureListener::NotifyMemoryPressure( 191 base::MemoryPressureListener::NotifyMemoryPressure(
196 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); 192 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
197 // Coming here, an asynchronous operation will collect system stats. Once in, 193 // Coming here, an asynchronous operation will collect system stats. Once in,
198 // a tab should get discarded. As such we need to give it 10s time to discard. 194 // a tab should get discarded. As such we need to give it 10s time to discard.
199 const int kTimeoutTimeInMS = 10000; 195 const int kTimeoutTimeInMS = 10000;
200 const int kIntervalTimeInMS = 5; 196 const int kIntervalTimeInMS = 5;
201 int timeout = kTimeoutTimeInMS / kIntervalTimeInMS; 197 int timeout = kTimeoutTimeInMS / kIntervalTimeInMS;
202 while (--timeout) { 198 while (--timeout) {
203 usleep(kIntervalTimeInMS * 1000); 199 usleep(kIntervalTimeInMS * 1000);
204 base::RunLoop().RunUntilIdle(); 200 base::RunLoop().RunUntilIdle();
205 if (oom_priority_manager->recent_tab_discard()) 201 if (oom_priority_manager->recent_tab_discard())
206 break; 202 break;
207 } 203 }
208 EXPECT_TRUE(oom_priority_manager->recent_tab_discard()); 204 EXPECT_TRUE(oom_priority_manager->recent_tab_discard());
209 } 205 }
210 206
211 } // namespace 207 } // namespace
208 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/memory/oom_priority_manager.h ('k') | chrome/browser/memory/oom_priority_manager_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698