Chromium Code Reviews| Index: chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc |
| diff --git a/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc b/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc |
| index 8376de345841b58b78e72780cd8b8a3f70e9b88e..f2e436bba824df2218f4822c86f4566260043d8a 100644 |
| --- a/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc |
| +++ b/chrome/browser/chromeos/memory/oom_priority_manager_browsertest.cc |
| @@ -1,7 +1,9 @@ |
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// 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
|
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/command_line.h" |
| +#include "base/memory/memory_pressure_listener.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/browser_process_platform_part_chromeos.h" |
| #include "chrome/browser/chromeos/memory/oom_priority_manager.h" |
| @@ -11,6 +13,7 @@ |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| +#include "chromeos/chromeos_switches.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/test/test_utils.h" |
| @@ -22,6 +25,22 @@ namespace { |
| typedef InProcessBrowserTest OomPriorityManagerTest; |
| +class OomPriorityManagerUsingPressureListenerTest |
| + : public InProcessBrowserTest { |
| + public: |
| + OomPriorityManagerUsingPressureListenerTest() {} |
| + 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.
|
| + |
| + 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.
|
| + command_line->AppendSwitch( |
| + chromeos::switches::kUseMemoryPressureSystemChromeOS); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(OomPriorityManagerUsingPressureListenerTest); |
| +}; |
| + |
| + |
| IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { |
| using content::WindowedNotificationObserver; |
| @@ -159,4 +178,40 @@ IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { |
| EXPECT_TRUE(chrome::CanGoForward(browser())); |
| } |
| +// Test that the MemoryPressureListener event is properly triggering a tab |
| +// discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event. |
| +IN_PROC_BROWSER_TEST_F(OomPriorityManagerUsingPressureListenerTest, |
| + OomPressureListener) { |
| + chromeos::OomPriorityManager* oom_priority_manager = |
| + g_browser_process->platform_part()->oom_priority_manager(); |
| + // Get three tabs open. |
| + content::WindowedNotificationObserver load1( |
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| + content::NotificationService::AllSources()); |
| + OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), |
| + CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); |
| + browser()->OpenURL(open1); |
| + load1.Wait(); |
| + |
| + content::WindowedNotificationObserver load2( |
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| + content::NotificationService::AllSources()); |
| + OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(), |
| + NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_TYPED, |
| + false); |
| + browser()->OpenURL(open2); |
| + load2.Wait(); |
| + EXPECT_FALSE(oom_priority_manager->recent_tab_discard()); |
| + |
| + // Nothing should happen with a moderate memory pressure event. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| + EXPECT_FALSE(oom_priority_manager->recent_tab_discard()); |
| + |
| + // A critical memory pressure event should discard a tab. |
| + base::MemoryPressureListener::NotifyMemoryPressure( |
| + base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| + EXPECT_TRUE(oom_priority_manager->recent_tab_discard()); |
| +} |
|
James Cook
2014/12/19 19:38:08
nice test!
Mr4D (OOO till 08-26)
2014/12/19 23:34:41
Thanks!
|
| + |
| } // namespace |