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

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

Issue 9359022: Aura: Support hovering restore & close buttons for full screen apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added new test for tab restore Created 8 years, 10 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
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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 30 matching lines...) Expand all
41 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); 41 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue());
42 42
43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
44 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs")); 44 path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("SessionTestDirs"));
45 ASSERT_TRUE(file_util::CreateDirectory(path_)); 45 ASSERT_TRUE(file_util::CreateDirectory(path_));
46 path_ = path_.AppendASCII(b); 46 path_ = path_.AppendASCII(b);
47 47
48 SessionService* session_service = new SessionService(path_); 48 SessionService* session_service = new SessionService(path_);
49 helper_.set_service(session_service); 49 helper_.set_service(session_service);
50 50
51 service()->SetWindowType(window_id, Browser::TYPE_TABBED); 51 service()->SetWindowType(window_id, Browser::TYPE_TABBED, false);
52 service()->SetWindowBounds(window_id, 52 service()->SetWindowBounds(window_id,
53 window_bounds, 53 window_bounds,
54 ui::SHOW_STATE_NORMAL); 54 ui::SHOW_STATE_NORMAL);
55 } 55 }
56 56
57 // Upon notification, increment the sync_save_count variable 57 // Upon notification, increment the sync_save_count variable
58 void Observe(int type, 58 void Observe(int type,
59 const content::NotificationSource& source, 59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) { 60 const content::NotificationDetails& details) {
61 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); 61 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ASCIIToUTF16("abc"), "def", 268 ASCIIToUTF16("abc"), "def",
269 content::PAGE_TRANSITION_QUALIFIER_MASK); 269 content::PAGE_TRANSITION_QUALIFIER_MASK);
270 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 270 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(),
271 ASCIIToUTF16("abcd"), "defg", 271 ASCIIToUTF16("abcd"), "defg",
272 content::PAGE_TRANSITION_AUTO_BOOKMARK); 272 content::PAGE_TRANSITION_AUTO_BOOKMARK);
273 273
274 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 274 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
275 UpdateNavigation(window_id, tab1_id, nav1, 0, true); 275 UpdateNavigation(window_id, tab1_id, nav1, 0, true);
276 276
277 const gfx::Rect window2_bounds(3, 4, 5, 6); 277 const gfx::Rect window2_bounds(3, 4, 5, 6);
278 service()->SetWindowType(window2_id, Browser::TYPE_TABBED); 278 service()->SetWindowType(window2_id, Browser::TYPE_TABBED, false);
279 service()->SetWindowBounds(window2_id, 279 service()->SetWindowBounds(window2_id,
280 window2_bounds, 280 window2_bounds,
281 ui::SHOW_STATE_MAXIMIZED); 281 ui::SHOW_STATE_MAXIMIZED);
282 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 282 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
283 UpdateNavigation(window2_id, tab2_id, nav2, 0, true); 283 UpdateNavigation(window2_id, tab2_id, nav2, 0, true);
284 284
285 ScopedVector<SessionWindow> windows; 285 ScopedVector<SessionWindow> windows;
286 ReadWindows(&(windows.get())); 286 ReadWindows(&(windows.get()));
287 287
288 ASSERT_EQ(2U, windows->size()); 288 ASSERT_EQ(2U, windows->size());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 SessionID tab2_id; 322 SessionID tab2_id;
323 323
324 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 324 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(),
325 ASCIIToUTF16("abc"), "def", 325 ASCIIToUTF16("abc"), "def",
326 content::PAGE_TRANSITION_QUALIFIER_MASK); 326 content::PAGE_TRANSITION_QUALIFIER_MASK);
327 327
328 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 328 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
329 UpdateNavigation(window_id, tab1_id, nav1, 0, true); 329 UpdateNavigation(window_id, tab1_id, nav1, 0, true);
330 330
331 const gfx::Rect window2_bounds(3, 4, 5, 6); 331 const gfx::Rect window2_bounds(3, 4, 5, 6);
332 service()->SetWindowType(window2_id, Browser::TYPE_TABBED); 332 service()->SetWindowType(window2_id, Browser::TYPE_TABBED, false);
333 service()->SetWindowBounds(window2_id, 333 service()->SetWindowBounds(window2_id,
334 window2_bounds, 334 window2_bounds,
335 ui::SHOW_STATE_NORMAL); 335 ui::SHOW_STATE_NORMAL);
336 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 336 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
337 337
338 ScopedVector<SessionWindow> windows; 338 ScopedVector<SessionWindow> windows;
339 ReadWindows(&(windows.get())); 339 ReadWindows(&(windows.get()));
340 340
341 ASSERT_EQ(1U, windows->size()); 341 ASSERT_EQ(1U, windows->size());
342 ASSERT_EQ(0, windows[0]->selected_tab_index); 342 ASSERT_EQ(0, windows[0]->selected_tab_index);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 helper_.AssertTabEquals(window_id, tab2_id, 1, 0, 1, *tab); 384 helper_.AssertTabEquals(window_id, tab2_id, 1, 0, 1, *tab);
385 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); 385 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
386 } 386 }
387 387
388 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) { 388 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) {
389 SessionID window2_id; 389 SessionID window2_id;
390 SessionID tab_id; 390 SessionID tab_id;
391 SessionID tab2_id; 391 SessionID tab2_id;
392 ASSERT_NE(window2_id.id(), window_id.id()); 392 ASSERT_NE(window2_id.id(), window_id.id());
393 393
394 service()->SetWindowType(window2_id, Browser::TYPE_TABBED); 394 service()->SetWindowType(window2_id, Browser::TYPE_TABBED, false);
395 service()->SetWindowBounds(window2_id, 395 service()->SetWindowBounds(window2_id,
396 window_bounds, 396 window_bounds,
397 ui::SHOW_STATE_NORMAL); 397 ui::SHOW_STATE_NORMAL);
398 398
399 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 399 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(),
400 ASCIIToUTF16("abc"), "def", 400 ASCIIToUTF16("abc"), "def",
401 content::PAGE_TRANSITION_QUALIFIER_MASK); 401 content::PAGE_TRANSITION_QUALIFIER_MASK);
402 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 402 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(),
403 ASCIIToUTF16("abcd"), "defg", 403 ASCIIToUTF16("abcd"), "defg",
404 content::PAGE_TRANSITION_AUTO_BOOKMARK); 404 content::PAGE_TRANSITION_AUTO_BOOKMARK);
(...skipping 24 matching lines...) Expand all
429 // Makes sure we don't track popups. 429 // Makes sure we don't track popups.
430 TEST_F(SessionServiceTest, IgnorePopups) { 430 TEST_F(SessionServiceTest, IgnorePopups) {
431 if (browser_defaults::kRestorePopups) 431 if (browser_defaults::kRestorePopups)
432 return; // This test is only applicable if popups aren't restored. 432 return; // This test is only applicable if popups aren't restored.
433 433
434 SessionID window2_id; 434 SessionID window2_id;
435 SessionID tab_id; 435 SessionID tab_id;
436 SessionID tab2_id; 436 SessionID tab2_id;
437 ASSERT_NE(window2_id.id(), window_id.id()); 437 ASSERT_NE(window2_id.id(), window_id.id());
438 438
439 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); 439 service()->SetWindowType(window2_id, Browser::TYPE_POPUP, false);
440 service()->SetWindowBounds(window2_id, 440 service()->SetWindowBounds(window2_id,
441 window_bounds, 441 window_bounds,
442 ui::SHOW_STATE_NORMAL); 442 ui::SHOW_STATE_NORMAL);
443 443
444 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 444 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(),
445 ASCIIToUTF16("abc"), "def", 445 ASCIIToUTF16("abc"), "def",
446 content::PAGE_TRANSITION_QUALIFIER_MASK); 446 content::PAGE_TRANSITION_QUALIFIER_MASK);
447 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 447 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(),
448 ASCIIToUTF16("abcd"), "defg", 448 ASCIIToUTF16("abcd"), "defg",
449 content::PAGE_TRANSITION_AUTO_BOOKMARK); 449 content::PAGE_TRANSITION_AUTO_BOOKMARK);
(...skipping 20 matching lines...) Expand all
470 // Makes sure we track popups. 470 // Makes sure we track popups.
471 TEST_F(SessionServiceTest, RestorePopup) { 471 TEST_F(SessionServiceTest, RestorePopup) {
472 if (!browser_defaults::kRestorePopups) 472 if (!browser_defaults::kRestorePopups)
473 return; // This test is only applicable if popups are restored. 473 return; // This test is only applicable if popups are restored.
474 474
475 SessionID window2_id; 475 SessionID window2_id;
476 SessionID tab_id; 476 SessionID tab_id;
477 SessionID tab2_id; 477 SessionID tab2_id;
478 ASSERT_NE(window2_id.id(), window_id.id()); 478 ASSERT_NE(window2_id.id(), window_id.id());
479 479
480 service()->SetWindowType(window2_id, Browser::TYPE_POPUP); 480 service()->SetWindowType(window2_id, Browser::TYPE_POPUP, false);
481 service()->SetWindowBounds(window2_id, 481 service()->SetWindowBounds(window2_id,
482 window_bounds, 482 window_bounds,
483 ui::SHOW_STATE_NORMAL); 483 ui::SHOW_STATE_NORMAL);
484 484
485 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(), 485 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(),
486 ASCIIToUTF16("abc"), "def", 486 ASCIIToUTF16("abc"), "def",
487 content::PAGE_TRANSITION_QUALIFIER_MASK); 487 content::PAGE_TRANSITION_QUALIFIER_MASK);
488 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(), 488 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(),
489 ASCIIToUTF16("abcd"), "defg", 489 ASCIIToUTF16("abcd"), "defg",
490 content::PAGE_TRANSITION_AUTO_BOOKMARK); 490 content::PAGE_TRANSITION_AUTO_BOOKMARK);
(...skipping 21 matching lines...) Expand all
512 512
513 ASSERT_EQ(0, windows[popup_index]->selected_tab_index); 513 ASSERT_EQ(0, windows[popup_index]->selected_tab_index);
514 ASSERT_EQ(window2_id.id(), windows[popup_index]->window_id.id()); 514 ASSERT_EQ(window2_id.id(), windows[popup_index]->window_id.id());
515 ASSERT_EQ(1U, windows[popup_index]->tabs.size()); 515 ASSERT_EQ(1U, windows[popup_index]->tabs.size());
516 516
517 tab = windows[popup_index]->tabs[0]; 517 tab = windows[popup_index]->tabs[0];
518 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); 518 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
519 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); 519 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
520 } 520 }
521 521
522 #if defined (USE_AURA)
523 // Makes sure we track apps. Only applicable on aura.
524 TEST_F(SessionServiceTest, RestoreApp) {
525 SessionID window2_id;
526 SessionID tab_id;
527 SessionID tab2_id;
528 ASSERT_NE(window2_id.id(), window_id.id());
529
530 service()->SetWindowType(window2_id, Browser::TYPE_POPUP, true);
531 service()->SetWindowBounds(window2_id,
532 window_bounds,
533 ui::SHOW_STATE_NORMAL);
534 service()->SetWindowAppName(window2_id, "TestApp");
535
536 TabNavigation nav1(0, GURL("http://google.com"), content::Referrer(),
537 ASCIIToUTF16("abc"), "def",
538 content::PAGE_TRANSITION_QUALIFIER_MASK);
539 TabNavigation nav2(0, GURL("http://google2.com"), content::Referrer(),
540 ASCIIToUTF16("abcd"), "defg",
541 content::PAGE_TRANSITION_AUTO_BOOKMARK);
542
543 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
544 UpdateNavigation(window_id, tab_id, nav1, 0, true);
545
546 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
547 UpdateNavigation(window2_id, tab2_id, nav2, 0, true);
548
549 ScopedVector<SessionWindow> windows;
550 ReadWindows(&(windows.get()));
551
552 ASSERT_EQ(2U, windows->size());
553 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ?
554 0 : 1;
555 int app_index = tabbed_index == 0 ? 1 : 0;
556 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index);
557 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id());
558 ASSERT_EQ(1U, windows[tabbed_index]->tabs.size());
559
560 SessionTab* tab = windows[tabbed_index]->tabs[0];
561 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
562 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
563
564 ASSERT_EQ(0, windows[app_index]->selected_tab_index);
565 ASSERT_EQ(window2_id.id(), windows[app_index]->window_id.id());
566 ASSERT_EQ(1U, windows[app_index]->tabs.size());
567 ASSERT_EQ(1U, windows[app_index]->type == Browser::TYPE_POPUP);
568 ASSERT_EQ("TestApp", windows[app_index]->app_name);
569
570 tab = windows[app_index]->tabs[0];
571 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
572 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
573 }
574 #endif
575
522 // Tests pruning from the front. 576 // Tests pruning from the front.
523 TEST_F(SessionServiceTest, PruneFromFront) { 577 TEST_F(SessionServiceTest, PruneFromFront) {
524 const std::string base_url("http://google.com/"); 578 const std::string base_url("http://google.com/");
525 SessionID tab_id; 579 SessionID tab_id;
526 580
527 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 581 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
528 582
529 // Add 5 navigations, with the 4th selected. 583 // Add 5 navigations, with the 4th selected.
530 for (int i = 0; i < 5; ++i) { 584 for (int i = 0; i < 5; ++i) {
531 TabNavigation nav(0, GURL(base_url + base::IntToString(i)), 585 TabNavigation nav(0, GURL(base_url + base::IntToString(i)),
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 790
737 ScopedVector<SessionWindow> windows; 791 ScopedVector<SessionWindow> windows;
738 ReadWindows(&(windows.get())); 792 ReadWindows(&(windows.get()));
739 793
740 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); 794 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2);
741 795
742 // Expected: the content state of both navigations was saved and restored. 796 // Expected: the content state of both navigations was saved and restored.
743 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]); 797 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]);
744 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]); 798 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]);
745 } 799 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698