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

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

Issue 10937028: Do not discard selected tab (Closed) Base URL: http://git.chromium.org/chromium/src.git@new
Patch Set: handle active tab Created 8 years, 3 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 "chrome/browser/browser_process.h" 5 #include "chrome/browser/browser_process.h"
6 #include "chrome/browser/chromeos/oom_priority_manager.h" 6 #include "chrome/browser/chromeos/oom_priority_manager.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_tabstrip.h" 9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 10 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 // Discard a tab. It should kill the first tab, since it was the oldest 80 // Discard a tab. It should kill the first tab, since it was the oldest
81 // and was not selected. 81 // and was not selected.
82 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); 82 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab());
83 EXPECT_EQ(3, browser()->tab_count()); 83 EXPECT_EQ(3, browser()->tab_count());
84 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); 84 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0));
85 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1)); 85 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
86 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); 86 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
87 87
88 // Run discard again, make sure it kills the second tab. 88 // Run discard again, make sure it kills the second tab.
89 g_browser_process->oom_priority_manager()->DiscardTab(); 89 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab());
90 EXPECT_EQ(3, browser()->tab_count()); 90 EXPECT_EQ(3, browser()->tab_count());
91 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); 91 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0));
92 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); 92 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1));
93 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); 93 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
94 94
95 // Kill the third tab 95 // Kill the third tab. It should not kill the last tab, since it is active
96 EXPECT_TRUE(g_browser_process->oom_priority_manager()->DiscardTab()); 96 // tab.
97 EXPECT_FALSE(g_browser_process->oom_priority_manager()->DiscardTab());
97 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0)); 98 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0));
98 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); 99 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1));
100 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
101
102 // Kill the third tab after making second tab active.
103 browser()->tab_strip_model()->ActivateTabAt(1, true);
104 EXPECT_EQ(1, browser()->active_index());
105 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
106 browser()->tab_strip_model()->DiscardTabContentsAt(2);
99 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2)); 107 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2));
100 108
101 // Running when all tabs are discarded should do nothing.
102 EXPECT_FALSE(g_browser_process->oom_priority_manager()->DiscardTab());
103
104 // Force creation of the FindBarController. 109 // Force creation of the FindBarController.
105 browser()->GetFindBarController(); 110 browser()->GetFindBarController();
106 111
107 // Select the first tab. It should reload. 112 // Select the first tab. It should reload.
108 WindowedNotificationObserver reload1( 113 WindowedNotificationObserver reload1(
109 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 114 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
110 content::NotificationService::AllSources()); 115 content::NotificationService::AllSources());
111 chrome::SelectNumberedTab(browser(), 0); 116 chrome::SelectNumberedTab(browser(), 0);
112 reload1.Wait(); 117 reload1.Wait();
113 // Make sure the FindBarController gets the right TabContents. 118 // Make sure the FindBarController gets the right TabContents.
114 EXPECT_EQ(browser()->GetFindBarController()->tab_contents(), 119 EXPECT_EQ(browser()->GetFindBarController()->tab_contents(),
115 chrome::GetActiveTabContents(browser())); 120 chrome::GetActiveTabContents(browser()));
116 EXPECT_EQ(0, browser()->active_index()); 121 EXPECT_EQ(0, browser()->active_index());
117 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0)); 122 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0));
118 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); 123 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
119 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2)); 124 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2));
120 125
121 // Select the third tab. It should reload. 126 // Select the third tab. It should reload.
122 WindowedNotificationObserver reload2( 127 WindowedNotificationObserver reload2(
123 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 128 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
124 content::NotificationService::AllSources()); 129 content::NotificationService::AllSources());
125 chrome::SelectNumberedTab(browser(), 2); 130 chrome::SelectNumberedTab(browser(), 2);
126 reload2.Wait(); 131 reload2.Wait();
127 EXPECT_EQ(2, browser()->active_index()); 132 EXPECT_EQ(2, browser()->active_index());
128 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0)); 133 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0));
129 EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1)); 134 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
130 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2)); 135 EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
131 136
132 // Navigate the third tab back twice. We used to crash here due to 137 // Navigate the third tab back twice. We used to crash here due to
133 // crbug.com/121373. 138 // crbug.com/121373.
134 EXPECT_TRUE(chrome::CanGoBack(browser())); 139 EXPECT_TRUE(chrome::CanGoBack(browser()));
135 EXPECT_FALSE(chrome::CanGoForward(browser())); 140 EXPECT_FALSE(chrome::CanGoForward(browser()));
136 WindowedNotificationObserver back1( 141 WindowedNotificationObserver back1(
137 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 142 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
138 content::NotificationService::AllSources()); 143 content::NotificationService::AllSources());
139 chrome::GoBack(browser(), CURRENT_TAB); 144 chrome::GoBack(browser(), CURRENT_TAB);
140 back1.Wait(); 145 back1.Wait();
141 EXPECT_TRUE(chrome::CanGoBack(browser())); 146 EXPECT_TRUE(chrome::CanGoBack(browser()));
142 EXPECT_TRUE(chrome::CanGoForward(browser())); 147 EXPECT_TRUE(chrome::CanGoForward(browser()));
143 WindowedNotificationObserver back2( 148 WindowedNotificationObserver back2(
144 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 149 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
145 content::NotificationService::AllSources()); 150 content::NotificationService::AllSources());
146 chrome::GoBack(browser(), CURRENT_TAB); 151 chrome::GoBack(browser(), CURRENT_TAB);
147 back2.Wait(); 152 back2.Wait();
148 EXPECT_FALSE(chrome::CanGoBack(browser())); 153 EXPECT_FALSE(chrome::CanGoBack(browser()));
149 EXPECT_TRUE(chrome::CanGoForward(browser())); 154 EXPECT_TRUE(chrome::CanGoForward(browser()));
150 } 155 }
151 156
152 } // namespace 157 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/oom_priority_manager.cc ('k') | chrome/browser/ui/tabs/tab_strip_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698