OLD | NEW |
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" |
(...skipping 10 matching lines...) Expand all Loading... |
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/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
28 | 28 |
29 using content::OpenURLParams; | 29 using content::OpenURLParams; |
30 | 30 |
31 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 31 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
32 | 32 |
33 namespace memory { | 33 namespace memory { |
34 | 34 |
35 class TabManagerTest : public InProcessBrowserTest { | 35 class TabManagerTest : public InProcessBrowserTest { |
36 public: | 36 public: |
37 // Tab discarding is enabled by default on CrOS. On other platforms, force it | 37 // Tab discarding is enabled by default on CrOS. On other platforms, force it |
38 // by turning on the corresponding experiment as some tests assume this | 38 // by turning on the corresponding experiment as some tests assume this |
39 // behavior it turned on. | 39 // behavior it turned on. |
40 void SetUpCommandLine(base::CommandLine* command_line) override { | 40 void SetUpCommandLine(base::CommandLine* command_line) override { |
41 #if !defined(OS_CHROMEOS) | 41 #if !defined(OS_LINUX) |
42 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 42 command_line->AppendSwitchASCII(switches::kEnableFeatures, |
43 features::kAutomaticTabDiscarding.name); | 43 features::kAutomaticTabDiscarding.name); |
44 #endif | 44 #endif |
45 } | 45 } |
46 }; | 46 }; |
47 | 47 |
48 IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { | 48 IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { |
49 using content::WindowedNotificationObserver; | 49 using content::WindowedNotificationObserver; |
50 TabManager* tab_manager = g_browser_process->GetTabManager(); | 50 TabManager* tab_manager = g_browser_process->GetTabManager(); |
51 ASSERT_TRUE(tab_manager); | 51 ASSERT_TRUE(tab_manager); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 EXPECT_TRUE(chrome::CanGoForward(browser())); | 174 EXPECT_TRUE(chrome::CanGoForward(browser())); |
175 WindowedNotificationObserver back2( | 175 WindowedNotificationObserver back2( |
176 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 176 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
177 content::NotificationService::AllSources()); | 177 content::NotificationService::AllSources()); |
178 chrome::GoBack(browser(), CURRENT_TAB); | 178 chrome::GoBack(browser(), CURRENT_TAB); |
179 back2.Wait(); | 179 back2.Wait(); |
180 EXPECT_FALSE(chrome::CanGoBack(browser())); | 180 EXPECT_FALSE(chrome::CanGoBack(browser())); |
181 EXPECT_TRUE(chrome::CanGoForward(browser())); | 181 EXPECT_TRUE(chrome::CanGoForward(browser())); |
182 } | 182 } |
183 | 183 |
| 184 // On Linux, memory pressure listener is not implemented yet. |
| 185 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 186 |
184 // Test that the MemoryPressureListener event is properly triggering a tab | 187 // Test that the MemoryPressureListener event is properly triggering a tab |
185 // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event. | 188 // discard upon |MEMORY_PRESSURE_LEVEL_CRITICAL| event. |
186 IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) { | 189 IN_PROC_BROWSER_TEST_F(TabManagerTest, OomPressureListener) { |
187 TabManager* tab_manager = g_browser_process->GetTabManager(); | 190 TabManager* tab_manager = g_browser_process->GetTabManager(); |
188 ASSERT_TRUE(tab_manager); | 191 ASSERT_TRUE(tab_manager); |
189 | 192 |
190 // Disable the protection of recent tabs. | 193 // Disable the protection of recent tabs. |
191 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); | 194 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); |
192 | 195 |
193 // Get three tabs open. | 196 // Get three tabs open. |
(...skipping 30 matching lines...) Expand all Loading... |
224 while (--timeout) { | 227 while (--timeout) { |
225 base::PlatformThread::Sleep( | 228 base::PlatformThread::Sleep( |
226 base::TimeDelta::FromMilliseconds(kIntervalTimeInMS)); | 229 base::TimeDelta::FromMilliseconds(kIntervalTimeInMS)); |
227 base::RunLoop().RunUntilIdle(); | 230 base::RunLoop().RunUntilIdle(); |
228 if (tab_manager->recent_tab_discard()) | 231 if (tab_manager->recent_tab_discard()) |
229 break; | 232 break; |
230 } | 233 } |
231 EXPECT_TRUE(tab_manager->recent_tab_discard()); | 234 EXPECT_TRUE(tab_manager->recent_tab_discard()); |
232 } | 235 } |
233 | 236 |
| 237 #endif |
| 238 |
234 IN_PROC_BROWSER_TEST_F(TabManagerTest, InvalidOrEmptyURL) { | 239 IN_PROC_BROWSER_TEST_F(TabManagerTest, InvalidOrEmptyURL) { |
235 TabManager* tab_manager = g_browser_process->GetTabManager(); | 240 TabManager* tab_manager = g_browser_process->GetTabManager(); |
236 ASSERT_TRUE(tab_manager); | 241 ASSERT_TRUE(tab_manager); |
237 | 242 |
238 // Disable the protection of recent tabs. | 243 // Disable the protection of recent tabs. |
239 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); | 244 tab_manager->minimum_protection_time_ = base::TimeDelta::FromMinutes(0); |
240 | 245 |
241 // Open two tabs. Wait for the foreground one to load but do not wait for the | 246 // Open two tabs. Wait for the foreground one to load but do not wait for the |
242 // background one. | 247 // background one. |
243 content::WindowedNotificationObserver load1( | 248 content::WindowedNotificationObserver load1( |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 // Remove the video stream. | 389 // Remove the video stream. |
385 video_stream_ui.reset(); | 390 video_stream_ui.reset(); |
386 | 391 |
387 // Should be able to discard the background tab now. | 392 // Should be able to discard the background tab now. |
388 EXPECT_TRUE(tab_manager->DiscardTabImpl()); | 393 EXPECT_TRUE(tab_manager->DiscardTabImpl()); |
389 } | 394 } |
390 | 395 |
391 } // namespace memory | 396 } // namespace memory |
392 | 397 |
393 #endif // OS_WIN || OS_CHROMEOS | 398 #endif // OS_WIN || OS_CHROMEOS |
OLD | NEW |