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

Side by Side Diff: chrome/browser/sessions/session_restore_browsertest_chromeos.cc

Issue 2714483003: cros: Fix restoring session windows after crash inconsistent minimized window counts (Closed)
Patch Set: RestoreSessionAfterCrash on nullptr Created 3 years, 9 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/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
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
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 session windows after crash should keep consistent
217 // minimized window counts (crbug.com/694854).
218 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS,
219 PRE_RestoreSessionWindowsAfterCrash) {
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 RestoreSessionWindowsAfterCrash) {
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 content::WindowedNotificationObserver close_observer(
246 chrome::NOTIFICATION_BROWSER_CLOSED,
247 content::Source<Browser>(default_browser));
248 // |default_browser| will be closed before session restore of last session.
249 SessionRestore::RestoreSessionAfterCrash(default_browser);
250 close_observer.Wait();
251
252 size_t total_count = 0;
253 size_t minimized_count = 0;
254 for (auto* browser : *BrowserList::GetInstance()) {
255 ++total_count;
256 if (browser->window()->IsMinimized())
257 ++minimized_count;
258 }
259 EXPECT_EQ(3u, total_count);
260 EXPECT_EQ(2u, minimized_count);
261 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore_browsertest.cc ('k') | chrome/browser/ui/views/session_crashed_bubble_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698