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

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

Issue 672083002: Refactoring of SessionService to get componentized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 1 month 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 54 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
55 ASSERT_TRUE(profile_manager_->SetUp()); 55 ASSERT_TRUE(profile_manager_->SetUp());
56 56
57 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue()); 57 std::string b = base::Int64ToString(base::Time::Now().ToInternalValue());
58 TestingProfile* profile = profile_manager_->CreateTestingProfile(b); 58 TestingProfile* profile = profile_manager_->CreateTestingProfile(b);
59 SessionService* session_service = new SessionService(profile); 59 SessionService* session_service = new SessionService(profile);
60 path_ = profile->GetPath(); 60 path_ = profile->GetPath();
61 61
62 helper_.SetService(session_service); 62 helper_.SetService(session_service);
63 63
64 service()->SetWindowType( 64 service()->SetWindowType(window_id, Browser::TYPE_TABBED, TYPE_NORMAL);
65 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
66 service()->SetWindowBounds(window_id, 65 service()->SetWindowBounds(window_id,
67 window_bounds, 66 window_bounds,
68 ui::SHOW_STATE_NORMAL); 67 ui::SHOW_STATE_NORMAL);
69 } 68 }
70 69
71 // Upon notification, increment the sync_save_count variable 70 // Upon notification, increment the sync_save_count variable
72 void Observe(int type, 71 void Observe(int type,
73 const content::NotificationSource& source, 72 const content::NotificationSource& source,
74 const content::NotificationDetails& details) override { 73 const content::NotificationDetails& details) override {
75 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); 74 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 SerializedNavigationEntry* nav2) { 147 SerializedNavigationEntry* nav2) {
149 *nav1 = SerializedNavigationEntryTestHelper::CreateNavigation( 148 *nav1 = SerializedNavigationEntryTestHelper::CreateNavigation(
150 "http://google.com", "abc"); 149 "http://google.com", "abc");
151 *nav2 = SerializedNavigationEntryTestHelper::CreateNavigation( 150 *nav2 = SerializedNavigationEntryTestHelper::CreateNavigation(
152 "http://google2.com", "abcd"); 151 "http://google2.com", "abcd");
153 152
154 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 153 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
155 UpdateNavigation(window_id, tab1_id, *nav1, true); 154 UpdateNavigation(window_id, tab1_id, *nav1, true);
156 155
157 const gfx::Rect window2_bounds(3, 4, 5, 6); 156 const gfx::Rect window2_bounds(3, 4, 5, 6);
158 service()->SetWindowType( 157 service()->SetWindowType(window2_id, Browser::TYPE_TABBED, TYPE_NORMAL);
159 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
160 service()->SetWindowBounds(window2_id, 158 service()->SetWindowBounds(window2_id,
161 window2_bounds, 159 window2_bounds,
162 ui::SHOW_STATE_MAXIMIZED); 160 ui::SHOW_STATE_MAXIMIZED);
163 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 161 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
164 UpdateNavigation(window2_id, tab2_id, *nav2, true); 162 UpdateNavigation(window2_id, tab2_id, *nav2, true);
165 } 163 }
166 164
167 SessionService* service() { return helper_.service(); } 165 SessionService* service() { return helper_.service(); }
168 166
169 const gfx::Rect window_bounds; 167 const gfx::Rect window_bounds;
(...skipping 24 matching lines...) Expand all
194 UpdateNavigation(window_id, tab_id, nav1, true); 192 UpdateNavigation(window_id, tab_id, nav1, true);
195 193
196 ScopedVector<SessionWindow> windows; 194 ScopedVector<SessionWindow> windows;
197 ReadWindows(&(windows.get()), NULL); 195 ReadWindows(&(windows.get()), NULL);
198 196
199 ASSERT_EQ(1U, windows.size()); 197 ASSERT_EQ(1U, windows.size());
200 ASSERT_TRUE(window_bounds == windows[0]->bounds); 198 ASSERT_TRUE(window_bounds == windows[0]->bounds);
201 ASSERT_EQ(0, windows[0]->selected_tab_index); 199 ASSERT_EQ(0, windows[0]->selected_tab_index);
202 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 200 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
203 ASSERT_EQ(1U, windows[0]->tabs.size()); 201 ASSERT_EQ(1U, windows[0]->tabs.size());
204 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type); 202 ASSERT_EQ(SessionWindow::TYPE_TABBED, windows[0]->type);
205 203
206 SessionTab* tab = windows[0]->tabs[0]; 204 SessionTab* tab = windows[0]->tabs[0];
207 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); 205 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
208 206
209 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 207 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
210 } 208 }
211 209
212 // Make sure we persist post entries. 210 // Make sure we persist post entries.
213 TEST_F(SessionServiceTest, PersistPostData) { 211 TEST_F(SessionServiceTest, PersistPostData) {
214 SessionID tab_id; 212 SessionID tab_id;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 SessionID tab2_id; 345 SessionID tab2_id;
348 346
349 SerializedNavigationEntry nav1 = 347 SerializedNavigationEntry nav1 =
350 SerializedNavigationEntryTestHelper::CreateNavigation( 348 SerializedNavigationEntryTestHelper::CreateNavigation(
351 "http://google.com", "abc"); 349 "http://google.com", "abc");
352 350
353 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 351 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
354 UpdateNavigation(window_id, tab1_id, nav1, true); 352 UpdateNavigation(window_id, tab1_id, nav1, true);
355 353
356 const gfx::Rect window2_bounds(3, 4, 5, 6); 354 const gfx::Rect window2_bounds(3, 4, 5, 6);
357 service()->SetWindowType( 355 service()->SetWindowType(window2_id, Browser::TYPE_TABBED, TYPE_NORMAL);
358 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
359 service()->SetWindowBounds(window2_id, 356 service()->SetWindowBounds(window2_id,
360 window2_bounds, 357 window2_bounds,
361 ui::SHOW_STATE_NORMAL); 358 ui::SHOW_STATE_NORMAL);
362 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 359 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
363 360
364 ScopedVector<SessionWindow> windows; 361 ScopedVector<SessionWindow> windows;
365 ReadWindows(&(windows.get()), NULL); 362 ReadWindows(&(windows.get()), NULL);
366 363
367 ASSERT_EQ(1U, windows.size()); 364 ASSERT_EQ(1U, windows.size());
368 ASSERT_EQ(0, windows[0]->selected_tab_index); 365 ASSERT_EQ(0, windows[0]->selected_tab_index);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 ASSERT_EQ(1U, windows[0]->tabs.size()); 439 ASSERT_EQ(1U, windows[0]->tabs.size());
443 ASSERT_EQ(1U, windows[1]->tabs.size()); 440 ASSERT_EQ(1U, windows[1]->tabs.size());
444 } 441 }
445 442
446 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) { 443 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) {
447 SessionID window2_id; 444 SessionID window2_id;
448 SessionID tab_id; 445 SessionID tab_id;
449 SessionID tab2_id; 446 SessionID tab2_id;
450 ASSERT_NE(window2_id.id(), window_id.id()); 447 ASSERT_NE(window2_id.id(), window_id.id());
451 448
452 service()->SetWindowType( 449 service()->SetWindowType(window2_id, Browser::TYPE_TABBED, TYPE_NORMAL);
453 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL);
454 service()->SetWindowBounds(window2_id, 450 service()->SetWindowBounds(window2_id,
455 window_bounds, 451 window_bounds,
456 ui::SHOW_STATE_NORMAL); 452 ui::SHOW_STATE_NORMAL);
457 453
458 SerializedNavigationEntry nav1 = 454 SerializedNavigationEntry nav1 =
459 SerializedNavigationEntryTestHelper::CreateNavigation( 455 SerializedNavigationEntryTestHelper::CreateNavigation(
460 "http://google.com", "abc"); 456 "http://google.com", "abc");
461 SerializedNavigationEntry nav2 = 457 SerializedNavigationEntry nav2 =
462 SerializedNavigationEntryTestHelper::CreateNavigation( 458 SerializedNavigationEntryTestHelper::CreateNavigation(
463 "http://google2.com", "abcd"); 459 "http://google2.com", "abcd");
(...skipping 21 matching lines...) Expand all
485 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 481 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
486 } 482 }
487 483
488 // Makes sure we don't track popups. 484 // Makes sure we don't track popups.
489 TEST_F(SessionServiceTest, IgnorePopups) { 485 TEST_F(SessionServiceTest, IgnorePopups) {
490 SessionID window2_id; 486 SessionID window2_id;
491 SessionID tab_id; 487 SessionID tab_id;
492 SessionID tab2_id; 488 SessionID tab2_id;
493 ASSERT_NE(window2_id.id(), window_id.id()); 489 ASSERT_NE(window2_id.id(), window_id.id());
494 490
495 service()->SetWindowType( 491 service()->SetWindowType(window2_id, Browser::TYPE_POPUP, TYPE_NORMAL);
496 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL);
497 service()->SetWindowBounds(window2_id, 492 service()->SetWindowBounds(window2_id,
498 window_bounds, 493 window_bounds,
499 ui::SHOW_STATE_NORMAL); 494 ui::SHOW_STATE_NORMAL);
500 495
501 SerializedNavigationEntry nav1 = 496 SerializedNavigationEntry nav1 =
502 SerializedNavigationEntryTestHelper::CreateNavigation( 497 SerializedNavigationEntryTestHelper::CreateNavigation(
503 "http://google.com", "abc"); 498 "http://google.com", "abc");
504 SerializedNavigationEntry nav2 = 499 SerializedNavigationEntry nav2 =
505 SerializedNavigationEntryTestHelper::CreateNavigation( 500 SerializedNavigationEntryTestHelper::CreateNavigation(
506 "http://google2.com", "abcd"); 501 "http://google2.com", "abcd");
(...skipping 18 matching lines...) Expand all
525 } 520 }
526 521
527 #if defined (OS_CHROMEOS) 522 #if defined (OS_CHROMEOS)
528 // Makes sure we track apps. Only applicable on chromeos. 523 // Makes sure we track apps. Only applicable on chromeos.
529 TEST_F(SessionServiceTest, RestoreApp) { 524 TEST_F(SessionServiceTest, RestoreApp) {
530 SessionID window2_id; 525 SessionID window2_id;
531 SessionID tab_id; 526 SessionID tab_id;
532 SessionID tab2_id; 527 SessionID tab2_id;
533 ASSERT_NE(window2_id.id(), window_id.id()); 528 ASSERT_NE(window2_id.id(), window_id.id());
534 529
535 service()->SetWindowType( 530 service()->SetWindowType(window2_id, Browser::TYPE_POPUP, TYPE_APP);
536 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP);
537 service()->SetWindowBounds(window2_id, 531 service()->SetWindowBounds(window2_id,
538 window_bounds, 532 window_bounds,
539 ui::SHOW_STATE_NORMAL); 533 ui::SHOW_STATE_NORMAL);
540 service()->SetWindowAppName(window2_id, "TestApp"); 534 service()->SetWindowAppName(window2_id, "TestApp");
541 535
542 SerializedNavigationEntry nav1 = 536 SerializedNavigationEntry nav1 =
543 SerializedNavigationEntryTestHelper::CreateNavigation( 537 SerializedNavigationEntryTestHelper::CreateNavigation(
544 "http://google.com", "abc"); 538 "http://google.com", "abc");
545 SerializedNavigationEntry nav2 = 539 SerializedNavigationEntry nav2 =
546 SerializedNavigationEntryTestHelper::CreateNavigation( 540 SerializedNavigationEntryTestHelper::CreateNavigation(
547 "http://google2.com", "abcd"); 541 "http://google2.com", "abcd");
548 542
549 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 543 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
550 UpdateNavigation(window_id, tab_id, nav1, true); 544 UpdateNavigation(window_id, tab_id, nav1, true);
551 545
552 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); 546 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
553 UpdateNavigation(window2_id, tab2_id, nav2, true); 547 UpdateNavigation(window2_id, tab2_id, nav2, true);
554 548
555 ScopedVector<SessionWindow> windows; 549 ScopedVector<SessionWindow> windows;
556 ReadWindows(&(windows.get()), NULL); 550 ReadWindows(&(windows.get()), NULL);
557 551
558 ASSERT_EQ(2U, windows.size()); 552 ASSERT_EQ(2U, windows.size());
559 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? 553 int tabbed_index = windows[0]->type == SessionWindow::TYPE_TABBED ?
560 0 : 1; 554 0 : 1;
561 int app_index = tabbed_index == 0 ? 1 : 0; 555 int app_index = tabbed_index == 0 ? 1 : 0;
562 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); 556 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index);
563 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); 557 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id());
564 ASSERT_EQ(1U, windows[tabbed_index]->tabs.size()); 558 ASSERT_EQ(1U, windows[tabbed_index]->tabs.size());
565 559
566 SessionTab* tab = windows[tabbed_index]->tabs[0]; 560 SessionTab* tab = windows[tabbed_index]->tabs[0];
567 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); 561 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
568 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 562 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
569 563
570 ASSERT_EQ(0, windows[app_index]->selected_tab_index); 564 ASSERT_EQ(0, windows[app_index]->selected_tab_index);
571 ASSERT_EQ(window2_id.id(), windows[app_index]->window_id.id()); 565 ASSERT_EQ(window2_id.id(), windows[app_index]->window_id.id());
572 ASSERT_EQ(1U, windows[app_index]->tabs.size()); 566 ASSERT_EQ(1U, windows[app_index]->tabs.size());
573 ASSERT_TRUE(windows[app_index]->type == Browser::TYPE_POPUP); 567 ASSERT_TRUE(windows[app_index]->type == SessionWindow::TYPE_POPUP);
574 ASSERT_EQ("TestApp", windows[app_index]->app_name); 568 ASSERT_EQ("TestApp", windows[app_index]->app_name);
575 569
576 tab = windows[app_index]->tabs[0]; 570 tab = windows[app_index]->tabs[0];
577 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); 571 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
578 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); 572 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
579 } 573 }
580 #endif // defined (OS_CHROMEOS) 574 #endif // defined (OS_CHROMEOS)
581 575
582 // Tests pruning from the front. 576 // Tests pruning from the front.
583 TEST_F(SessionServiceTest, PruneFromFront) { 577 TEST_F(SessionServiceTest, PruneFromFront) {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 TEST_F(SessionServiceTest, RestoreActivation1) { 894 TEST_F(SessionServiceTest, RestoreActivation1) {
901 SessionID window2_id; 895 SessionID window2_id;
902 SessionID tab1_id; 896 SessionID tab1_id;
903 SessionID tab2_id; 897 SessionID tab2_id;
904 SerializedNavigationEntry nav1; 898 SerializedNavigationEntry nav1;
905 SerializedNavigationEntry nav2; 899 SerializedNavigationEntry nav2;
906 900
907 CreateAndWriteSessionWithTwoWindows( 901 CreateAndWriteSessionWithTwoWindows(
908 window2_id, tab1_id, tab2_id, &nav1, &nav2); 902 window2_id, tab1_id, tab2_id, &nav1, &nav2);
909 903
910 service()->ScheduleCommand( 904 service()->ScheduleCommand(CreateSetActiveWindowCommand(window2_id));
911 service()->CreateSetActiveWindowCommand(window2_id)); 905 service()->ScheduleCommand(CreateSetActiveWindowCommand(window_id));
912 service()->ScheduleCommand(
913 service()->CreateSetActiveWindowCommand(window_id));
914 906
915 ScopedVector<SessionWindow> windows; 907 ScopedVector<SessionWindow> windows;
916 SessionID::id_type active_window_id = 0; 908 SessionID::id_type active_window_id = 0;
917 ReadWindows(&(windows.get()), &active_window_id); 909 ReadWindows(&(windows.get()), &active_window_id);
918 EXPECT_EQ(window_id.id(), active_window_id); 910 EXPECT_EQ(window_id.id(), active_window_id);
919 } 911 }
920 912
921 // It's easier to have two separate tests with setup/teardown than to manualy 913 // It's easier to have two separate tests with setup/teardown than to manualy
922 // reset the state for the different flavors of the test. 914 // reset the state for the different flavors of the test.
923 TEST_F(SessionServiceTest, RestoreActivation2) { 915 TEST_F(SessionServiceTest, RestoreActivation2) {
924 SessionID window2_id; 916 SessionID window2_id;
925 SessionID tab1_id; 917 SessionID tab1_id;
926 SessionID tab2_id; 918 SessionID tab2_id;
927 SerializedNavigationEntry nav1; 919 SerializedNavigationEntry nav1;
928 SerializedNavigationEntry nav2; 920 SerializedNavigationEntry nav2;
929 921
930 CreateAndWriteSessionWithTwoWindows( 922 CreateAndWriteSessionWithTwoWindows(
931 window2_id, tab1_id, tab2_id, &nav1, &nav2); 923 window2_id, tab1_id, tab2_id, &nav1, &nav2);
932 924
933 service()->ScheduleCommand( 925 service()->ScheduleCommand(CreateSetActiveWindowCommand(window2_id));
934 service()->CreateSetActiveWindowCommand(window2_id)); 926 service()->ScheduleCommand(CreateSetActiveWindowCommand(window_id));
935 service()->ScheduleCommand( 927 service()->ScheduleCommand(CreateSetActiveWindowCommand(window2_id));
936 service()->CreateSetActiveWindowCommand(window_id));
937 service()->ScheduleCommand(
938 service()->CreateSetActiveWindowCommand(window2_id));
939 928
940 ScopedVector<SessionWindow> windows; 929 ScopedVector<SessionWindow> windows;
941 SessionID::id_type active_window_id = 0; 930 SessionID::id_type active_window_id = 0;
942 ReadWindows(&(windows.get()), &active_window_id); 931 ReadWindows(&(windows.get()), &active_window_id);
943 EXPECT_EQ(window2_id.id(), active_window_id); 932 EXPECT_EQ(window2_id.id(), active_window_id);
944 } 933 }
945 934
946 // Makes sure we don't track blacklisted URLs. 935 // Makes sure we don't track blacklisted URLs.
947 TEST_F(SessionServiceTest, IgnoreBlacklistedUrls) { 936 TEST_F(SessionServiceTest, IgnoreBlacklistedUrls) {
948 SessionID tab_id; 937 SessionID tab_id;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 &cancelable_task_tracker); 1005 &cancelable_task_tracker);
1017 helper_.RunTaskOnBackendThread( 1006 helper_.RunTaskOnBackendThread(
1018 FROM_HERE, 1007 FROM_HERE,
1019 base::Bind(&PostBackToThread, 1008 base::Bind(&PostBackToThread,
1020 base::Unretained(base::MessageLoop::current()), 1009 base::Unretained(base::MessageLoop::current()),
1021 base::Unretained(&run_loop))); 1010 base::Unretained(&run_loop)));
1022 delete helper_.ReleaseService(); 1011 delete helper_.ReleaseService();
1023 event.Signal(); 1012 event.Signal();
1024 run_loop.Run(); 1013 run_loop.Run();
1025 } 1014 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698