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