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

Side by Side Diff: chrome/browser/memory/tab_manager_browsertest.cc

Issue 2553993003: PlzNavigate: fix flaky TabManagerTest.TabManagerBasics browser test. (Closed)
Patch Set: Created 4 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 (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 "base/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/memory_pressure_listener.h" 7 #include "base/memory/memory_pressure_listener.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" 12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
13 #include "chrome/browser/memory/tab_manager.h" 13 #include "chrome/browser/memory/tab_manager.h"
14 #include "chrome/browser/memory/tab_manager_web_contents_data.h" 14 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 17 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_features.h" 19 #include "chrome/common/chrome_features.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/interactive_test_utils.h" 22 #include "chrome/test/base/interactive_test_utils.h"
23 #include "content/public/browser/navigation_details.h"
24 #include "content/public/browser/navigation_entry.h"
23 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 26 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_process_host.h" 27 #include "content/public/browser/render_process_host.h"
26 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
27 #include "content/public/test/test_utils.h" 29 #include "content/public/test/test_utils.h"
28 #include "url/gurl.h" 30 #include "url/gurl.h"
29 31
30 using content::OpenURLParams; 32 using content::OpenURLParams;
31 33
32 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) 34 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
33 35
34 namespace memory { 36 namespace memory {
35 37
36 class TabManagerTest : public InProcessBrowserTest { 38 class TabManagerTest : public InProcessBrowserTest {
37 }; 39 };
38 40
41 bool ObserveNavEntryCommitted(const GURL& expected_url,
42 const content::NotificationSource& source,
43 const content::NotificationDetails& details) {
44 return content::Details<content::LoadCommittedDetails>(details)
45 ->entry->GetURL() == expected_url;
46 }
47
39 IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { 48 IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) {
40 using content::WindowedNotificationObserver; 49 using content::WindowedNotificationObserver;
41 TabManager* tab_manager = g_browser_process->GetTabManager(); 50 TabManager* tab_manager = g_browser_process->GetTabManager();
42 EXPECT_FALSE(tab_manager->recent_tab_discard()); 51 EXPECT_FALSE(tab_manager->recent_tab_discard());
43 52
44 // Disable the protection of recent tabs. 53 // Disable the protection of recent tabs.
45 tab_manager->set_minimum_protection_time_for_tests( 54 tab_manager->set_minimum_protection_time_for_tests(
46 base::TimeDelta::FromMinutes(0)); 55 base::TimeDelta::FromMinutes(0));
47 56
48 // Get three tabs open. 57 // Get three tabs open.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); 137 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1)));
129 tab_manager->DiscardWebContentsAt(2, tsm); 138 tab_manager->DiscardWebContentsAt(2, tsm);
130 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); 139 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2)));
131 140
132 // Force creation of the FindBarController. 141 // Force creation of the FindBarController.
133 browser()->GetFindBarController(); 142 browser()->GetFindBarController();
134 143
135 // Select the first tab. It should reload. 144 // Select the first tab. It should reload.
136 WindowedNotificationObserver reload1( 145 WindowedNotificationObserver reload1(
137 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 146 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
138 content::NotificationService::AllSources()); 147 base::Bind(&ObserveNavEntryCommitted,
148 GURL(chrome::kChromeUIChromeURLsURL)));
139 chrome::SelectNumberedTab(browser(), 0); 149 chrome::SelectNumberedTab(browser(), 0);
140 reload1.Wait(); 150 reload1.Wait();
141 // Make sure the FindBarController gets the right WebContents. 151 // Make sure the FindBarController gets the right WebContents.
142 EXPECT_EQ(browser()->GetFindBarController()->web_contents(), 152 EXPECT_EQ(browser()->GetFindBarController()->web_contents(),
143 tsm->GetActiveWebContents()); 153 tsm->GetActiveWebContents());
144 EXPECT_EQ(0, tsm->active_index()); 154 EXPECT_EQ(0, tsm->active_index());
145 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); 155 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0)));
146 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); 156 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1)));
147 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); 157 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2)));
148 158
149 // Select the third tab. It should reload. 159 // Select the third tab. It should reload.
150 WindowedNotificationObserver reload2( 160 WindowedNotificationObserver reload2(
151 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 161 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
152 content::NotificationService::AllSources()); 162 base::Bind(&ObserveNavEntryCommitted, GURL("chrome://dns")));
153 chrome::SelectNumberedTab(browser(), 2); 163 chrome::SelectNumberedTab(browser(), 2);
154 reload2.Wait(); 164 reload2.Wait();
155 EXPECT_EQ(2, tsm->active_index()); 165 EXPECT_EQ(2, tsm->active_index());
156 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); 166 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0)));
157 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1))); 167 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(1)));
158 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2))); 168 EXPECT_FALSE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(2)));
159 169
160 // Navigate the third tab back twice. We used to crash here due to 170 // Navigate the third tab back twice. We used to crash here due to
161 // crbug.com/121373. 171 // crbug.com/121373.
162 EXPECT_TRUE(chrome::CanGoBack(browser())); 172 EXPECT_TRUE(chrome::CanGoBack(browser()));
163 EXPECT_FALSE(chrome::CanGoForward(browser())); 173 EXPECT_FALSE(chrome::CanGoForward(browser()));
164 WindowedNotificationObserver back1( 174 WindowedNotificationObserver back1(
165 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 175 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
166 content::NotificationService::AllSources()); 176 base::Bind(&ObserveNavEntryCommitted, GURL(chrome::kChromeUIVersionURL)));
167 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); 177 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB);
168 back1.Wait(); 178 back1.Wait();
169 EXPECT_TRUE(chrome::CanGoBack(browser())); 179 EXPECT_TRUE(chrome::CanGoBack(browser()));
170 EXPECT_TRUE(chrome::CanGoForward(browser())); 180 EXPECT_TRUE(chrome::CanGoForward(browser()));
171 WindowedNotificationObserver back2( 181 WindowedNotificationObserver back2(
172 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 182 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
173 content::NotificationService::AllSources()); 183 base::Bind(&ObserveNavEntryCommitted, GURL(chrome::kChromeUITermsURL)));
174 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); 184 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB);
175 back2.Wait(); 185 back2.Wait();
176 EXPECT_FALSE(chrome::CanGoBack(browser())); 186 EXPECT_FALSE(chrome::CanGoBack(browser()));
177 EXPECT_TRUE(chrome::CanGoForward(browser())); 187 EXPECT_TRUE(chrome::CanGoForward(browser()));
178 } 188 }
179 189
180 // On Linux, memory pressure listener is not implemented yet. 190 // On Linux, memory pressure listener is not implemented yet.
181 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 191 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
182 192
183 // Test that the MemoryPressureListener event is properly triggering a tab 193 // Test that the MemoryPressureListener event is properly triggering a tab
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true); 477 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true);
468 478
469 // Now it should be able to discard the tab. 479 // Now it should be able to discard the tab.
470 EXPECT_TRUE(tab_manager->DiscardTabImpl()); 480 EXPECT_TRUE(tab_manager->DiscardTabImpl());
471 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); 481 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0)));
472 } 482 }
473 483
474 } // namespace memory 484 } // namespace memory
475 485
476 #endif // OS_WIN || OS_MAXOSX || OS_LINUX 486 #endif // OS_WIN || OS_MAXOSX || OS_LINUX
OLDNEW
« no previous file with comments | « no previous file | content/browser/web_contents/web_contents_impl.cc » ('j') | content/browser/web_contents/web_contents_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698