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

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

Issue 815183002: Using the new MemoryPressureListener instead of the LowMemoryObserver when the enhanced memory mana… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 2012 The Chromium Authors. All rights reserved.
James Cook 2014/12/19 19:38:08 no need to change this
Mr4D (OOO till 08-26) 2014/12/19 23:34:41 Sky asked for it, but I can also leave it this way
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"
6 #include "base/memory/memory_pressure_listener.h"
5 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
6 #include "chrome/browser/browser_process_platform_part_chromeos.h" 8 #include "chrome/browser/browser_process_platform_part_chromeos.h"
7 #include "chrome/browser/chromeos/memory/oom_priority_manager.h" 9 #include "chrome/browser/chromeos/memory/oom_priority_manager.h"
8 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h" 11 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 12 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
13 #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"
14 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
16 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
17 #include "url/gurl.h" 20 #include "url/gurl.h"
18 21
19 using content::OpenURLParams; 22 using content::OpenURLParams;
20 23
21 namespace { 24 namespace {
22 25
23 typedef InProcessBrowserTest OomPriorityManagerTest; 26 typedef InProcessBrowserTest OomPriorityManagerTest;
24 27
28 class OomPriorityManagerUsingPressureListenerTest
29 : public InProcessBrowserTest {
30 public:
31 OomPriorityManagerUsingPressureListenerTest() {}
32 virtual ~OomPriorityManagerUsingPressureListenerTest() {}
James Cook 2014/12/19 19:38:08 nit: no virtual, just "override"
Mr4D (OOO till 08-26) 2014/12/19 23:34:41 Done.
33
34 virtual void SetUpCommandLine(CommandLine* command_line) override {
James Cook 2014/12/19 19:38:08 ditto
Mr4D (OOO till 08-26) 2014/12/19 23:34:41 Done.
35 command_line->AppendSwitch(
36 chromeos::switches::kUseMemoryPressureSystemChromeOS);
37 }
38
39 private:
40 DISALLOW_COPY_AND_ASSIGN(OomPriorityManagerUsingPressureListenerTest);
41 };
42
43
25 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { 44 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) {
26 using content::WindowedNotificationObserver; 45 using content::WindowedNotificationObserver;
27 46
28 chromeos::OomPriorityManager* oom_priority_manager = 47 chromeos::OomPriorityManager* oom_priority_manager =
29 g_browser_process->platform_part()->oom_priority_manager(); 48 g_browser_process->platform_part()->oom_priority_manager();
30 EXPECT_FALSE(oom_priority_manager->recent_tab_discard()); 49 EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
31 50
32 // Get three tabs open. 51 // Get three tabs open.
33 WindowedNotificationObserver load1( 52 WindowedNotificationObserver load1(
34 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 53 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 EXPECT_TRUE(chrome::CanGoForward(browser())); 171 EXPECT_TRUE(chrome::CanGoForward(browser()));
153 WindowedNotificationObserver back2( 172 WindowedNotificationObserver back2(
154 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 173 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
155 content::NotificationService::AllSources()); 174 content::NotificationService::AllSources());
156 chrome::GoBack(browser(), CURRENT_TAB); 175 chrome::GoBack(browser(), CURRENT_TAB);
157 back2.Wait(); 176 back2.Wait();
158 EXPECT_FALSE(chrome::CanGoBack(browser())); 177 EXPECT_FALSE(chrome::CanGoBack(browser()));
159 EXPECT_TRUE(chrome::CanGoForward(browser())); 178 EXPECT_TRUE(chrome::CanGoForward(browser()));
160 } 179 }
161 180
181 // Test that the MemoryPressureListener event is properly triggering a tab
182 // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event.
183 IN_PROC_BROWSER_TEST_F(OomPriorityManagerUsingPressureListenerTest,
184 OomPressureListener) {
185 chromeos::OomPriorityManager* oom_priority_manager =
186 g_browser_process->platform_part()->oom_priority_manager();
187 // Get three tabs open.
188 content::WindowedNotificationObserver load1(
189 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
190 content::NotificationService::AllSources());
191 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
192 CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false);
193 browser()->OpenURL(open1);
194 load1.Wait();
195
196 content::WindowedNotificationObserver load2(
197 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
198 content::NotificationService::AllSources());
199 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
200 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED,
201 false);
202 browser()->OpenURL(open2);
203 load2.Wait();
204 EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
205
206 // Nothing should happen with a moderate memory pressure event.
207 base::MemoryPressureListener::NotifyMemoryPressure(
208 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
209 EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
210
211 // A critical memory pressure event should discard a tab.
212 base::MemoryPressureListener::NotifyMemoryPressure(
213 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
214 EXPECT_TRUE(oom_priority_manager->recent_tab_discard());
215 }
James Cook 2014/12/19 19:38:08 nice test!
Mr4D (OOO till 08-26) 2014/12/19 23:34:41 Thanks!
216
162 } // namespace 217 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698