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

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

Issue 7621061: Restoring a session should restore window minimization state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Mark's comments. Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sessions/session_service.cc ('k') | chrome/browser/sessions/session_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/scoped_vector.h" 7 #include "base/memory/scoped_vector.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 27 matching lines...) Expand all
38 38
39 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 39 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
40 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); 40 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs"));
41 ASSERT_TRUE(file_util::CreateDirectory(path_)); 41 ASSERT_TRUE(file_util::CreateDirectory(path_));
42 path_ = path_.AppendASCII(b); 42 path_ = path_.AppendASCII(b);
43 43
44 SessionService* session_service = new SessionService(path_); 44 SessionService* session_service = new SessionService(path_);
45 helper_.set_service(session_service); 45 helper_.set_service(session_service);
46 46
47 service()->SetWindowType(window_id, Browser::TYPE_TABBED); 47 service()->SetWindowType(window_id, Browser::TYPE_TABBED);
48 service()->SetWindowBounds(window_id, window_bounds, false); 48 service()->SetWindowBounds(window_id,
49 window_bounds,
50 ui::SHOW_STATE_NORMAL);
49 } 51 }
50 52
51 // Upon notification, increment the sync_save_count variable 53 // Upon notification, increment the sync_save_count variable
52 void Observe(int type, 54 void Observe(int type,
53 const NotificationSource& source, 55 const NotificationSource& source,
54 const NotificationDetails& details) { 56 const NotificationDetails& details) {
55 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); 57 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED);
56 sync_save_count_++; 58 sync_save_count_++;
57 } 59 }
58 60
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 PageTransition::QUALIFIER_MASK); 263 PageTransition::QUALIFIER_MASK);
262 TabNavigation nav2(0, GURL("http://google2.com"), GURL(), 264 TabNavigation nav2(0, GURL("http://google2.com"), GURL(),
263 ASCIIToUTF16("abcd"), "defg", 265 ASCIIToUTF16("abcd"), "defg",
264 PageTransition::AUTO_BOOKMARK); 266 PageTransition::AUTO_BOOKMARK);
265 267
266 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 268 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
267 UpdateNavigation(window_id, tab1_id, nav1, 0, true); 269 UpdateNavigation(window_id, tab1_id, nav1, 0, true);
268 270
269 const gfx::Rect window2_bounds(3, 4, 5, 6); 271 const gfx::Rect window2_bounds(3, 4, 5, 6);
270 service()->SetWindowType(window2_id, Browser::TYPE_TABBED); 272 service()->SetWindowType(window2_id, Browser::TYPE_TABBED);
271 service()->SetWindowBounds(window2_id, window2_bounds, true); 273 service()->SetWindowBounds(window2_id,
274 window2_bounds,
275 ui::SHOW_STATE_MAXIMIZED);
272 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 276 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
273 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); 277 UpdateNavigation(window2_id, tab2_id, nav2, 0, true);
274 278
275 ScopedVector<SessionWindow> windows; 279 ScopedVector<SessionWindow> windows;
276 ReadWindows(&(windows.get())); 280 ReadWindows(&(windows.get()));
277 281
278 ASSERT_EQ(2U, windows->size()); 282 ASSERT_EQ(2U, windows->size());
279 ASSERT_EQ(0, windows[0]->selected_tab_index); 283 ASSERT_EQ(0, windows[0]->selected_tab_index);
280 ASSERT_EQ(0, windows[1]->selected_tab_index); 284 ASSERT_EQ(0, windows[1]->selected_tab_index);
281 ASSERT_EQ(1U, windows[0]->tabs.size()); 285 ASSERT_EQ(1U, windows[0]->tabs.size());
282 ASSERT_EQ(1U, windows[1]->tabs.size()); 286 ASSERT_EQ(1U, windows[1]->tabs.size());
283 287
284 SessionTab* rt1; 288 SessionTab* rt1;
285 SessionTab* rt2; 289 SessionTab* rt2;
286 if (windows[0]->window_id.id() == window_id.id()) { 290 if (windows[0]->window_id.id() == window_id.id()) {
287 ASSERT_EQ(window2_id.id(), windows[1]->window_id.id()); 291 ASSERT_EQ(window2_id.id(), windows[1]->window_id.id());
288 ASSERT_FALSE(windows[0]->is_maximized); 292 ASSERT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state);
289 ASSERT_TRUE(windows[1]->is_maximized); 293 ASSERT_EQ(ui::SHOW_STATE_MAXIMIZED, windows[1]->show_state);
290 rt1 = windows[0]->tabs[0]; 294 rt1 = windows[0]->tabs[0];
291 rt2 = windows[1]->tabs[0]; 295 rt2 = windows[1]->tabs[0];
292 } else { 296 } else {
293 ASSERT_EQ(window2_id.id(), windows[0]->window_id.id()); 297 ASSERT_EQ(window2_id.id(), windows[0]->window_id.id());
294 ASSERT_EQ(window_id.id(), windows[1]->window_id.id()); 298 ASSERT_EQ(window_id.id(), windows[1]->window_id.id());
295 ASSERT_TRUE(windows[0]->is_maximized); 299 ASSERT_EQ(ui::SHOW_STATE_MAXIMIZED, windows[0]->show_state);
296 ASSERT_FALSE(windows[1]->is_maximized); 300 ASSERT_EQ(ui::SHOW_STATE_NORMAL, windows[1]->show_state);
297 rt1 = windows[1]->tabs[0]; 301 rt1 = windows[1]->tabs[0];
298 rt2 = windows[0]->tabs[0]; 302 rt2 = windows[0]->tabs[0];
299 } 303 }
300 SessionTab* tab = rt1; 304 SessionTab* tab = rt1;
301 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab); 305 helper_.AssertTabEquals(window_id, tab1_id, 0, 0, 1, *tab);
302 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 306 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
303 307
304 tab = rt2; 308 tab = rt2;
305 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); 309 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
306 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); 310 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
307 } 311 }
308 312
309 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) { 313 TEST_F(SessionServiceTest, WindowWithNoTabsGetsPruned) {
310 SessionID window2_id; 314 SessionID window2_id;
311 SessionID tab1_id; 315 SessionID tab1_id;
312 SessionID tab2_id; 316 SessionID tab2_id;
313 317
314 TabNavigation nav1(0, GURL("http://google.com"), GURL(), 318 TabNavigation nav1(0, GURL("http://google.com"), GURL(),
315 ASCIIToUTF16("abc"), "def", 319 ASCIIToUTF16("abc"), "def",
316 PageTransition::QUALIFIER_MASK); 320 PageTransition::QUALIFIER_MASK);
317 321
318 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 322 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
319 UpdateNavigation(window_id, tab1_id, nav1, 0, true); 323 UpdateNavigation(window_id, tab1_id, nav1, 0, true);
320 324
321 const gfx::Rect window2_bounds(3, 4, 5, 6); 325 const gfx::Rect window2_bounds(3, 4, 5, 6);
322 service()->SetWindowType(window2_id, Browser::TYPE_TABBED); 326 service()->SetWindowType(window2_id, Browser::TYPE_TABBED);
323 service()->SetWindowBounds(window2_id, window2_bounds, false); 327 service()->SetWindowBounds(window2_id,
328 window2_bounds,
329 ui::SHOW_STATE_NORMAL);
324 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 330 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
325 331
326 ScopedVector<SessionWindow> windows; 332 ScopedVector<SessionWindow> windows;
327 ReadWindows(&(windows.get())); 333 ReadWindows(&(windows.get()));
328 334
329 ASSERT_EQ(1U, windows->size()); 335 ASSERT_EQ(1U, windows->size());
330 ASSERT_EQ(0, windows[0]->selected_tab_index); 336 ASSERT_EQ(0, windows[0]->selected_tab_index);
331 ASSERT_EQ(1U, windows[0]->tabs.size()); 337 ASSERT_EQ(1U, windows[0]->tabs.size());
332 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 338 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
333 339
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); 379 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
374 } 380 }
375 381
376 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) { 382 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) {
377 SessionID window2_id; 383 SessionID window2_id;
378 SessionID tab_id; 384 SessionID tab_id;
379 SessionID tab2_id; 385 SessionID tab2_id;
380 ASSERT_NE(window2_id.id(), window_id.id()); 386 ASSERT_NE(window2_id.id(), window_id.id());
381 387
382 service()->SetWindowType(window2_id, Browser::TYPE_TABBED); 388 service()->SetWindowType(window2_id, Browser::TYPE_TABBED);
383 service()->SetWindowBounds(window2_id, window_bounds, false); 389 service()->SetWindowBounds(window2_id,
390 window_bounds,
391 ui::SHOW_STATE_NORMAL);
384 392
385 TabNavigation nav1(0, GURL("http://google.com"), GURL(), 393 TabNavigation nav1(0, GURL("http://google.com"), GURL(),
386 ASCIIToUTF16("abc"), "def", 394 ASCIIToUTF16("abc"), "def",
387 PageTransition::QUALIFIER_MASK); 395 PageTransition::QUALIFIER_MASK);
388 TabNavigation nav2(0, GURL("http://google2.com"), GURL(), 396 TabNavigation nav2(0, GURL("http://google2.com"), GURL(),
389 ASCIIToUTF16("abcd"), "defg", 397 ASCIIToUTF16("abcd"), "defg",
390 PageTransition::AUTO_BOOKMARK); 398 PageTransition::AUTO_BOOKMARK);
391 399
392 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 400 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
393 UpdateNavigation(window_id, tab_id, nav1, 0, true); 401 UpdateNavigation(window_id, tab_id, nav1, 0, true);
(...skipping 22 matching lines...) Expand all
416 TEST_F(SessionServiceTest, IgnorePopups) { 424 TEST_F(SessionServiceTest, IgnorePopups) {
417 if (browser_defaults::kRestorePopups) 425 if (browser_defaults::kRestorePopups)
418 return; // This test is only applicable if popups aren't restored. 426 return; // This test is only applicable if popups aren't restored.
419 427
420 SessionID window2_id; 428 SessionID window2_id;
421 SessionID tab_id; 429 SessionID tab_id;
422 SessionID tab2_id; 430 SessionID tab2_id;
423 ASSERT_NE(window2_id.id(), window_id.id()); 431 ASSERT_NE(window2_id.id(), window_id.id());
424 432
425 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); 433 service()->SetWindowType(window2_id, Browser::TYPE_POPUP);
426 service()->SetWindowBounds(window2_id, window_bounds, false); 434 service()->SetWindowBounds(window2_id,
435 window_bounds,
436 ui::SHOW_STATE_NORMAL);
427 437
428 TabNavigation nav1(0, GURL("http://google.com"), GURL(), 438 TabNavigation nav1(0, GURL("http://google.com"), GURL(),
429 ASCIIToUTF16("abc"), "def", 439 ASCIIToUTF16("abc"), "def",
430 PageTransition::QUALIFIER_MASK); 440 PageTransition::QUALIFIER_MASK);
431 TabNavigation nav2(0, GURL("http://google2.com"), GURL(), 441 TabNavigation nav2(0, GURL("http://google2.com"), GURL(),
432 ASCIIToUTF16("abcd"), "defg", 442 ASCIIToUTF16("abcd"), "defg",
433 PageTransition::AUTO_BOOKMARK); 443 PageTransition::AUTO_BOOKMARK);
434 444
435 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 445 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
436 UpdateNavigation(window_id, tab_id, nav1, 0, true); 446 UpdateNavigation(window_id, tab_id, nav1, 0, true);
(...skipping 18 matching lines...) Expand all
455 TEST_F(SessionServiceTest, RestorePopup) { 465 TEST_F(SessionServiceTest, RestorePopup) {
456 if (!browser_defaults::kRestorePopups) 466 if (!browser_defaults::kRestorePopups)
457 return; // This test is only applicable if popups are restored. 467 return; // This test is only applicable if popups are restored.
458 468
459 SessionID window2_id; 469 SessionID window2_id;
460 SessionID tab_id; 470 SessionID tab_id;
461 SessionID tab2_id; 471 SessionID tab2_id;
462 ASSERT_NE(window2_id.id(), window_id.id()); 472 ASSERT_NE(window2_id.id(), window_id.id());
463 473
464 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); 474 service()->SetWindowType(window2_id, Browser::TYPE_POPUP);
465 service()->SetWindowBounds(window2_id, window_bounds, false); 475 service()->SetWindowBounds(window2_id,
476 window_bounds,
477 ui::SHOW_STATE_NORMAL);
466 478
467 TabNavigation nav1(0, GURL("http://google.com"), GURL(), 479 TabNavigation nav1(0, GURL("http://google.com"), GURL(),
468 ASCIIToUTF16("abc"), "def", 480 ASCIIToUTF16("abc"), "def",
469 PageTransition::QUALIFIER_MASK); 481 PageTransition::QUALIFIER_MASK);
470 TabNavigation nav2(0, GURL("http://google2.com"), GURL(), 482 TabNavigation nav2(0, GURL("http://google2.com"), GURL(),
471 ASCIIToUTF16("abcd"), "defg", 483 ASCIIToUTF16("abcd"), "defg",
472 PageTransition::AUTO_BOOKMARK); 484 PageTransition::AUTO_BOOKMARK);
473 485
474 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 486 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
475 UpdateNavigation(window_id, tab_id, nav1, 0, true); 487 UpdateNavigation(window_id, tab_id, nav1, 0, true);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 665
654 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 666 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
655 UpdateNavigation(window_id, tab_id, nav1, 0, true); 667 UpdateNavigation(window_id, tab_id, nav1, 0, true);
656 service()->TabClosed(window_id, tab_id, true); 668 service()->TabClosed(window_id, tab_id, true);
657 669
658 ScopedVector<SessionWindow> windows; 670 ScopedVector<SessionWindow> windows;
659 ReadWindows(&(windows.get())); 671 ReadWindows(&(windows.get()));
660 672
661 ASSERT_TRUE(windows->empty()); 673 ASSERT_TRUE(windows->empty());
662 } 674 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.cc ('k') | chrome/browser/sessions/session_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698