| 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 "chrome/browser/sessions/session_restore.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | 8 |
| 7 #include <list> | 9 #include <list> |
| 8 #include <vector> | 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/defaults.h" | 15 #include "chrome/browser/defaults.h" |
| 14 #include "chrome/browser/prefs/session_startup_pref.h" | 16 #include "chrome/browser/prefs/session_startup_pref.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return Browser::CreateParams::CreateForApp(name, trusted, gfx::Rect(), | 73 return Browser::CreateParams::CreateForApp(name, trusted, gfx::Rect(), |
| 72 profile(), true); | 74 profile(), true); |
| 73 } | 75 } |
| 74 | 76 |
| 75 // Turn on session restore before we restart. | 77 // Turn on session restore before we restart. |
| 76 void TurnOnSessionRestore() { | 78 void TurnOnSessionRestore() { |
| 77 SessionStartupPref::SetStartupPref( | 79 SessionStartupPref::SetStartupPref( |
| 78 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); | 80 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 79 } | 81 } |
| 80 | 82 |
| 81 Profile* profile() { return browser()->profile(); } | 83 Profile* profile() { |
| 84 if (!profile_) |
| 85 profile_ = browser()->profile(); |
| 82 | 86 |
| 87 return profile_; |
| 88 } |
| 89 |
| 90 private: |
| 83 std::list<Browser*> browser_list_; | 91 std::list<Browser*> browser_list_; |
| 92 Profile* profile_ = nullptr; |
| 84 }; | 93 }; |
| 85 | 94 |
| 86 // Thse tests are in pairs. The PRE_ test creates some browser windows and | 95 // Thse tests are in pairs. The PRE_ test creates some browser windows and |
| 87 // the following test confirms that the correct windows are restored after a | 96 // the following test confirms that the correct windows are restored after a |
| 88 // restart. | 97 // restart. |
| 89 | 98 |
| 90 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) { | 99 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) { |
| 91 // One browser window is always created by default. | 100 // One browser window is always created by default. |
| 92 EXPECT_TRUE(browser()); | 101 EXPECT_TRUE(browser()); |
| 93 // Create a second normal browser window. | 102 // Create a second normal browser window. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 ++total_count; | 205 ++total_count; |
| 197 if (browser->window()->IsMinimized()) | 206 if (browser->window()->IsMinimized()) |
| 198 ++minimized_count; | 207 ++minimized_count; |
| 199 } | 208 } |
| 200 EXPECT_EQ(2u, total_count); | 209 EXPECT_EQ(2u, total_count); |
| 201 // Chrome OS always activates the last browser window on login, which results | 210 // Chrome OS always activates the last browser window on login, which results |
| 202 // in one window being restored. This seems reasonable as it reminds users | 211 // in one window being restored. This seems reasonable as it reminds users |
| 203 // they have a browser running instead of just showing them an empty desktop. | 212 // they have a browser running instead of just showing them an empty desktop. |
| 204 EXPECT_EQ(1u, minimized_count); | 213 EXPECT_EQ(1u, minimized_count); |
| 205 } | 214 } |
| 215 |
| 216 // Tests that restoring pages to minimized browsers should keep those minimized, |
| 217 // with Chrome OS always activate and show at least one browser window. |
| 218 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, |
| 219 PRE_RestoreTabsToMinimizedBrowser) { |
| 220 // One browser window is always created by default. |
| 221 ASSERT_TRUE(browser()); |
| 222 browser()->window()->Minimize(); |
| 223 |
| 224 Browser* browser2 = |
| 225 CreateBrowserWithParams(Browser::CreateParams(profile(), true)); |
| 226 browser2->window()->Minimize(); |
| 227 |
| 228 Browser* browser3 = |
| 229 CreateBrowserWithParams(Browser::CreateParams(profile(), true)); |
| 230 browser3->window()->Minimize(); |
| 231 |
| 232 EXPECT_TRUE(browser()->window()->IsMinimized()); |
| 233 EXPECT_TRUE(browser2->window()->IsMinimized()); |
| 234 EXPECT_TRUE(browser3->window()->IsMinimized()); |
| 235 |
| 236 // Do not turn on startup session restore. |
| 237 } |
| 238 |
| 239 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, |
| 240 RestoreTabsToMinimizedBrowser) { |
| 241 // By default, there will be one browser window opened. |
| 242 ASSERT_EQ(1u, BrowserList::GetInstance()->size()); |
| 243 Browser* default_browser = BrowserList::GetInstance()->GetLastActive(); |
| 244 |
| 245 SessionRestore::RestoreSession( |
| 246 profile(), default_browser, |
| 247 SessionRestore::CLOBBER_CURRENT_TAB | SessionRestore::SYNCHRONOUS, |
| 248 std::vector<GURL>()); |
| 249 |
| 250 size_t total_count = 0; |
| 251 size_t minimized_count = 0; |
| 252 for (auto* browser : *BrowserList::GetInstance()) { |
| 253 ++total_count; |
| 254 if (browser->window()->IsMinimized()) |
| 255 ++minimized_count; |
| 256 } |
| 257 EXPECT_EQ(3u, total_count); |
| 258 EXPECT_EQ(2u, minimized_count); |
| 259 } |
| OLD | NEW |