| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/oom_priority_manager.h" | 5 #include "chrome/browser/oom_priority_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/public/browser/notification_types.h" | 11 #include "content/public/browser/notification_types.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class OomPriorityManagerTest : public InProcessBrowserTest { | 16 class OomPriorityManagerTest : public InProcessBrowserTest { |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { | 19 IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) { |
| 20 using namespace ui_test_utils; | 20 using namespace ui_test_utils; |
| 21 | 21 |
| 22 // Get three tabs open. Load asynchronously to speed up the test. | 22 // Get three tabs open. Load asynchronously to speed up the test. |
| 23 WindowedNotificationObserver load1(content::NOTIFICATION_LOAD_STOP, | 23 WindowedNotificationObserver load1( |
| 24 NotificationService::AllSources()); | 24 content::NOTIFICATION_LOAD_STOP, |
| 25 content::NotificationService::AllSources()); |
| 25 OpenURLParams open1(GURL("chrome://about"), GURL(), | 26 OpenURLParams open1(GURL("chrome://about"), GURL(), |
| 26 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); | 27 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false); |
| 27 browser()->OpenURL(open1); | 28 browser()->OpenURL(open1); |
| 28 | 29 |
| 29 WindowedNotificationObserver load2(content::NOTIFICATION_LOAD_STOP, | 30 WindowedNotificationObserver load2( |
| 30 NotificationService::AllSources()); | 31 content::NOTIFICATION_LOAD_STOP, |
| 32 content::NotificationService::AllSources()); |
| 31 OpenURLParams open2(GURL("chrome://credits"), GURL(), | 33 OpenURLParams open2(GURL("chrome://credits"), GURL(), |
| 32 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, | 34 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, |
| 33 false); | 35 false); |
| 34 browser()->OpenURL(open2); | 36 browser()->OpenURL(open2); |
| 35 | 37 |
| 36 WindowedNotificationObserver load3(content::NOTIFICATION_LOAD_STOP, | 38 WindowedNotificationObserver load3( |
| 37 NotificationService::AllSources()); | 39 content::NOTIFICATION_LOAD_STOP, |
| 40 content::NotificationService::AllSources()); |
| 38 OpenURLParams open3(GURL("chrome://terms"), GURL(), | 41 OpenURLParams open3(GURL("chrome://terms"), GURL(), |
| 39 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, | 42 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, |
| 40 false); | 43 false); |
| 41 browser()->OpenURL(open3); | 44 browser()->OpenURL(open3); |
| 42 | 45 |
| 43 load1.Wait(); | 46 load1.Wait(); |
| 44 load2.Wait(); | 47 load2.Wait(); |
| 45 load3.Wait(); | 48 load3.Wait(); |
| 46 | 49 |
| 47 EXPECT_EQ(3, browser()->tab_count()); | 50 EXPECT_EQ(3, browser()->tab_count()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 64 // Kill the third tab | 67 // Kill the third tab |
| 65 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); | 68 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); |
| 66 EXPECT_TRUE(browser()->IsTabDiscarded(0)); | 69 EXPECT_TRUE(browser()->IsTabDiscarded(0)); |
| 67 EXPECT_TRUE(browser()->IsTabDiscarded(1)); | 70 EXPECT_TRUE(browser()->IsTabDiscarded(1)); |
| 68 EXPECT_TRUE(browser()->IsTabDiscarded(2)); | 71 EXPECT_TRUE(browser()->IsTabDiscarded(2)); |
| 69 | 72 |
| 70 // Running when all tabs are discarded should do nothing. | 73 // Running when all tabs are discarded should do nothing. |
| 71 EXPECT_FALSE(g_browser_process->oom_priority_manager()->DiscardTab()); | 74 EXPECT_FALSE(g_browser_process->oom_priority_manager()->DiscardTab()); |
| 72 | 75 |
| 73 // Select the first tab. It should reload. | 76 // Select the first tab. It should reload. |
| 74 WindowedNotificationObserver reload1(content::NOTIFICATION_LOAD_STOP, | 77 WindowedNotificationObserver reload1( |
| 75 NotificationService::AllSources()); | 78 content::NOTIFICATION_LOAD_STOP, |
| 79 content::NotificationService::AllSources()); |
| 76 browser()->SelectNumberedTab(0); | 80 browser()->SelectNumberedTab(0); |
| 77 reload1.Wait(); | 81 reload1.Wait(); |
| 78 EXPECT_FALSE(browser()->IsTabDiscarded(0)); | 82 EXPECT_FALSE(browser()->IsTabDiscarded(0)); |
| 79 EXPECT_TRUE(browser()->IsTabDiscarded(1)); | 83 EXPECT_TRUE(browser()->IsTabDiscarded(1)); |
| 80 EXPECT_TRUE(browser()->IsTabDiscarded(2)); | 84 EXPECT_TRUE(browser()->IsTabDiscarded(2)); |
| 81 } | 85 } |
| 82 | 86 |
| 83 } // namespace | 87 } // namespace |
| OLD | NEW |