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

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: Fixing windows compile problem 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,
65 window_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 65 Browser::TYPE_TABBED,
66 SessionService::TYPE_NORMAL);
66 service()->SetWindowBounds(window_id, 67 service()->SetWindowBounds(window_id,
67 window_bounds, 68 window_bounds,
68 ui::SHOW_STATE_NORMAL); 69 ui::SHOW_STATE_NORMAL);
69 } 70 }
70 71
71 // Upon notification, increment the sync_save_count variable 72 // Upon notification, increment the sync_save_count variable
72 void Observe(int type, 73 void Observe(int type,
73 const content::NotificationSource& source, 74 const content::NotificationSource& source,
74 const content::NotificationDetails& details) override { 75 const content::NotificationDetails& details) override {
75 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED); 76 ASSERT_EQ(type, chrome::NOTIFICATION_SESSION_SERVICE_SAVED);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 SerializedNavigationEntry* nav2) { 149 SerializedNavigationEntry* nav2) {
149 *nav1 = SerializedNavigationEntryTestHelper::CreateNavigation( 150 *nav1 = SerializedNavigationEntryTestHelper::CreateNavigation(
150 "http://google.com", "abc"); 151 "http://google.com", "abc");
151 *nav2 = SerializedNavigationEntryTestHelper::CreateNavigation( 152 *nav2 = SerializedNavigationEntryTestHelper::CreateNavigation(
152 "http://google2.com", "abcd"); 153 "http://google2.com", "abcd");
153 154
154 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 155 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
155 UpdateNavigation(window_id, tab1_id, *nav1, true); 156 UpdateNavigation(window_id, tab1_id, *nav1, true);
156 157
157 const gfx::Rect window2_bounds(3, 4, 5, 6); 158 const gfx::Rect window2_bounds(3, 4, 5, 6);
158 service()->SetWindowType( 159 service()->SetWindowType(window2_id,
159 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 160 Browser::TYPE_TABBED,
161 SessionService::TYPE_NORMAL);
160 service()->SetWindowBounds(window2_id, 162 service()->SetWindowBounds(window2_id,
161 window2_bounds, 163 window2_bounds,
162 ui::SHOW_STATE_MAXIMIZED); 164 ui::SHOW_STATE_MAXIMIZED);
163 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 165 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
164 UpdateNavigation(window2_id, tab2_id, *nav2, true); 166 UpdateNavigation(window2_id, tab2_id, *nav2, true);
165 } 167 }
166 168
167 SessionService* service() { return helper_.service(); } 169 SessionService* service() { return helper_.service(); }
168 170
169 const gfx::Rect window_bounds; 171 const gfx::Rect window_bounds;
(...skipping 24 matching lines...) Expand all
194 UpdateNavigation(window_id, tab_id, nav1, true); 196 UpdateNavigation(window_id, tab_id, nav1, true);
195 197
196 ScopedVector<SessionWindow> windows; 198 ScopedVector<SessionWindow> windows;
197 ReadWindows(&(windows.get()), NULL); 199 ReadWindows(&(windows.get()), NULL);
198 200
199 ASSERT_EQ(1U, windows.size()); 201 ASSERT_EQ(1U, windows.size());
200 ASSERT_TRUE(window_bounds == windows[0]->bounds); 202 ASSERT_TRUE(window_bounds == windows[0]->bounds);
201 ASSERT_EQ(0, windows[0]->selected_tab_index); 203 ASSERT_EQ(0, windows[0]->selected_tab_index);
202 ASSERT_EQ(window_id.id(), windows[0]->window_id.id()); 204 ASSERT_EQ(window_id.id(), windows[0]->window_id.id());
203 ASSERT_EQ(1U, windows[0]->tabs.size()); 205 ASSERT_EQ(1U, windows[0]->tabs.size());
204 ASSERT_EQ(Browser::TYPE_TABBED, windows[0]->type); 206 ASSERT_EQ(SessionWindow::TYPE_TABBED, windows[0]->type);
205 207
206 SessionTab* tab = windows[0]->tabs[0]; 208 SessionTab* tab = windows[0]->tabs[0];
207 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); 209 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
208 210
209 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 211 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
210 } 212 }
211 213
212 // Make sure we persist post entries. 214 // Make sure we persist post entries.
213 TEST_F(SessionServiceTest, PersistPostData) { 215 TEST_F(SessionServiceTest, PersistPostData) {
214 SessionID tab_id; 216 SessionID tab_id;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 SessionID tab2_id; 349 SessionID tab2_id;
348 350
349 SerializedNavigationEntry nav1 = 351 SerializedNavigationEntry nav1 =
350 SerializedNavigationEntryTestHelper::CreateNavigation( 352 SerializedNavigationEntryTestHelper::CreateNavigation(
351 "http://google.com", "abc"); 353 "http://google.com", "abc");
352 354
353 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true); 355 helper_.PrepareTabInWindow(window_id, tab1_id, 0, true);
354 UpdateNavigation(window_id, tab1_id, nav1, true); 356 UpdateNavigation(window_id, tab1_id, nav1, true);
355 357
356 const gfx::Rect window2_bounds(3, 4, 5, 6); 358 const gfx::Rect window2_bounds(3, 4, 5, 6);
357 service()->SetWindowType( 359 service()->SetWindowType(window2_id,
358 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 360 Browser::TYPE_TABBED,
361 SessionService::TYPE_NORMAL);
359 service()->SetWindowBounds(window2_id, 362 service()->SetWindowBounds(window2_id,
360 window2_bounds, 363 window2_bounds,
361 ui::SHOW_STATE_NORMAL); 364 ui::SHOW_STATE_NORMAL);
362 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true); 365 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, true);
363 366
364 ScopedVector<SessionWindow> windows; 367 ScopedVector<SessionWindow> windows;
365 ReadWindows(&(windows.get()), NULL); 368 ReadWindows(&(windows.get()), NULL);
366 369
367 ASSERT_EQ(1U, windows.size()); 370 ASSERT_EQ(1U, windows.size());
368 ASSERT_EQ(0, windows[0]->selected_tab_index); 371 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()); 445 ASSERT_EQ(1U, windows[0]->tabs.size());
443 ASSERT_EQ(1U, windows[1]->tabs.size()); 446 ASSERT_EQ(1U, windows[1]->tabs.size());
444 } 447 }
445 448
446 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) { 449 TEST_F(SessionServiceTest, WindowCloseCommittedAfterNavigate) {
447 SessionID window2_id; 450 SessionID window2_id;
448 SessionID tab_id; 451 SessionID tab_id;
449 SessionID tab2_id; 452 SessionID tab2_id;
450 ASSERT_NE(window2_id.id(), window_id.id()); 453 ASSERT_NE(window2_id.id(), window_id.id());
451 454
452 service()->SetWindowType( 455 service()->SetWindowType(window2_id,
453 window2_id, Browser::TYPE_TABBED, SessionService::TYPE_NORMAL); 456 Browser::TYPE_TABBED,
457 SessionService::TYPE_NORMAL);
454 service()->SetWindowBounds(window2_id, 458 service()->SetWindowBounds(window2_id,
455 window_bounds, 459 window_bounds,
456 ui::SHOW_STATE_NORMAL); 460 ui::SHOW_STATE_NORMAL);
457 461
458 SerializedNavigationEntry nav1 = 462 SerializedNavigationEntry nav1 =
459 SerializedNavigationEntryTestHelper::CreateNavigation( 463 SerializedNavigationEntryTestHelper::CreateNavigation(
460 "http://google.com", "abc"); 464 "http://google.com", "abc");
461 SerializedNavigationEntry nav2 = 465 SerializedNavigationEntry nav2 =
462 SerializedNavigationEntryTestHelper::CreateNavigation( 466 SerializedNavigationEntryTestHelper::CreateNavigation(
463 "http://google2.com", "abcd"); 467 "http://google2.com", "abcd");
(...skipping 21 matching lines...) Expand all
485 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 489 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
486 } 490 }
487 491
488 // Makes sure we don't track popups. 492 // Makes sure we don't track popups.
489 TEST_F(SessionServiceTest, IgnorePopups) { 493 TEST_F(SessionServiceTest, IgnorePopups) {
490 SessionID window2_id; 494 SessionID window2_id;
491 SessionID tab_id; 495 SessionID tab_id;
492 SessionID tab2_id; 496 SessionID tab2_id;
493 ASSERT_NE(window2_id.id(), window_id.id()); 497 ASSERT_NE(window2_id.id(), window_id.id());
494 498
495 service()->SetWindowType( 499 service()->SetWindowType(window2_id,
496 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_NORMAL); 500 Browser::TYPE_POPUP,
501 SessionService::TYPE_NORMAL);
497 service()->SetWindowBounds(window2_id, 502 service()->SetWindowBounds(window2_id,
498 window_bounds, 503 window_bounds,
499 ui::SHOW_STATE_NORMAL); 504 ui::SHOW_STATE_NORMAL);
500 505
501 SerializedNavigationEntry nav1 = 506 SerializedNavigationEntry nav1 =
502 SerializedNavigationEntryTestHelper::CreateNavigation( 507 SerializedNavigationEntryTestHelper::CreateNavigation(
503 "http://google.com", "abc"); 508 "http://google.com", "abc");
504 SerializedNavigationEntry nav2 = 509 SerializedNavigationEntry nav2 =
505 SerializedNavigationEntryTestHelper::CreateNavigation( 510 SerializedNavigationEntryTestHelper::CreateNavigation(
506 "http://google2.com", "abcd"); 511 "http://google2.com", "abcd");
(...skipping 18 matching lines...) Expand all
525 } 530 }
526 531
527 #if defined (OS_CHROMEOS) 532 #if defined (OS_CHROMEOS)
528 // Makes sure we track apps. Only applicable on chromeos. 533 // Makes sure we track apps. Only applicable on chromeos.
529 TEST_F(SessionServiceTest, RestoreApp) { 534 TEST_F(SessionServiceTest, RestoreApp) {
530 SessionID window2_id; 535 SessionID window2_id;
531 SessionID tab_id; 536 SessionID tab_id;
532 SessionID tab2_id; 537 SessionID tab2_id;
533 ASSERT_NE(window2_id.id(), window_id.id()); 538 ASSERT_NE(window2_id.id(), window_id.id());
534 539
535 service()->SetWindowType( 540 service()->SetWindowType(window2_id,
536 window2_id, Browser::TYPE_POPUP, SessionService::TYPE_APP); 541 Browser::TYPE_POPUP,
542 SessionService::TYPE_APP);
537 service()->SetWindowBounds(window2_id, 543 service()->SetWindowBounds(window2_id,
538 window_bounds, 544 window_bounds,
539 ui::SHOW_STATE_NORMAL); 545 ui::SHOW_STATE_NORMAL);
540 service()->SetWindowAppName(window2_id, "TestApp"); 546 service()->SetWindowAppName(window2_id, "TestApp");
541 547
542 SerializedNavigationEntry nav1 = 548 SerializedNavigationEntry nav1 =
543 SerializedNavigationEntryTestHelper::CreateNavigation( 549 SerializedNavigationEntryTestHelper::CreateNavigation(
544 "http://google.com", "abc"); 550 "http://google.com", "abc");
545 SerializedNavigationEntry nav2 = 551 SerializedNavigationEntry nav2 =
546 SerializedNavigationEntryTestHelper::CreateNavigation( 552 SerializedNavigationEntryTestHelper::CreateNavigation(
547 "http://google2.com", "abcd"); 553 "http://google2.com", "abcd");
548 554
549 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 555 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
550 UpdateNavigation(window_id, tab_id, nav1, true); 556 UpdateNavigation(window_id, tab_id, nav1, true);
551 557
552 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false); 558 helper_.PrepareTabInWindow(window2_id, tab2_id, 0, false);
553 UpdateNavigation(window2_id, tab2_id, nav2, true); 559 UpdateNavigation(window2_id, tab2_id, nav2, true);
554 560
555 ScopedVector<SessionWindow> windows; 561 ScopedVector<SessionWindow> windows;
556 ReadWindows(&(windows.get()), NULL); 562 ReadWindows(&(windows.get()), NULL);
557 563
558 ASSERT_EQ(2U, windows.size()); 564 ASSERT_EQ(2U, windows.size());
559 int tabbed_index = windows[0]->type == Browser::TYPE_TABBED ? 565 int tabbed_index = windows[0]->type == SessionWindow::TYPE_TABBED ?
560 0 : 1; 566 0 : 1;
561 int app_index = tabbed_index == 0 ? 1 : 0; 567 int app_index = tabbed_index == 0 ? 1 : 0;
562 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index); 568 ASSERT_EQ(0, windows[tabbed_index]->selected_tab_index);
563 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id()); 569 ASSERT_EQ(window_id.id(), windows[tabbed_index]->window_id.id());
564 ASSERT_EQ(1U, windows[tabbed_index]->tabs.size()); 570 ASSERT_EQ(1U, windows[tabbed_index]->tabs.size());
565 571
566 SessionTab* tab = windows[tabbed_index]->tabs[0]; 572 SessionTab* tab = windows[tabbed_index]->tabs[0];
567 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab); 573 helper_.AssertTabEquals(window_id, tab_id, 0, 0, 1, *tab);
568 helper_.AssertNavigationEquals(nav1, tab->navigations[0]); 574 helper_.AssertNavigationEquals(nav1, tab->navigations[0]);
569 575
570 ASSERT_EQ(0, windows[app_index]->selected_tab_index); 576 ASSERT_EQ(0, windows[app_index]->selected_tab_index);
571 ASSERT_EQ(window2_id.id(), windows[app_index]->window_id.id()); 577 ASSERT_EQ(window2_id.id(), windows[app_index]->window_id.id());
572 ASSERT_EQ(1U, windows[app_index]->tabs.size()); 578 ASSERT_EQ(1U, windows[app_index]->tabs.size());
573 ASSERT_TRUE(windows[app_index]->type == Browser::TYPE_POPUP); 579 ASSERT_TRUE(windows[app_index]->type == SessionWindow::TYPE_POPUP);
574 ASSERT_EQ("TestApp", windows[app_index]->app_name); 580 ASSERT_EQ("TestApp", windows[app_index]->app_name);
575 581
576 tab = windows[app_index]->tabs[0]; 582 tab = windows[app_index]->tabs[0];
577 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab); 583 helper_.AssertTabEquals(window2_id, tab2_id, 0, 0, 1, *tab);
578 helper_.AssertNavigationEquals(nav2, tab->navigations[0]); 584 helper_.AssertNavigationEquals(nav2, tab->navigations[0]);
579 } 585 }
580 #endif // defined (OS_CHROMEOS) 586 #endif // defined (OS_CHROMEOS)
581 587
582 // Tests pruning from the front. 588 // Tests pruning from the front.
583 TEST_F(SessionServiceTest, PruneFromFront) { 589 TEST_F(SessionServiceTest, PruneFromFront) {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 TEST_F(SessionServiceTest, RestoreActivation1) { 906 TEST_F(SessionServiceTest, RestoreActivation1) {
901 SessionID window2_id; 907 SessionID window2_id;
902 SessionID tab1_id; 908 SessionID tab1_id;
903 SessionID tab2_id; 909 SessionID tab2_id;
904 SerializedNavigationEntry nav1; 910 SerializedNavigationEntry nav1;
905 SerializedNavigationEntry nav2; 911 SerializedNavigationEntry nav2;
906 912
907 CreateAndWriteSessionWithTwoWindows( 913 CreateAndWriteSessionWithTwoWindows(
908 window2_id, tab1_id, tab2_id, &nav1, &nav2); 914 window2_id, tab1_id, tab2_id, &nav1, &nav2);
909 915
910 service()->ScheduleCommand( 916 service()->ScheduleCommand(CreateSetActiveWindowCommand(window2_id));
911 service()->CreateSetActiveWindowCommand(window2_id)); 917 service()->ScheduleCommand(CreateSetActiveWindowCommand(window_id));
912 service()->ScheduleCommand(
913 service()->CreateSetActiveWindowCommand(window_id));
914 918
915 ScopedVector<SessionWindow> windows; 919 ScopedVector<SessionWindow> windows;
916 SessionID::id_type active_window_id = 0; 920 SessionID::id_type active_window_id = 0;
917 ReadWindows(&(windows.get()), &active_window_id); 921 ReadWindows(&(windows.get()), &active_window_id);
918 EXPECT_EQ(window_id.id(), active_window_id); 922 EXPECT_EQ(window_id.id(), active_window_id);
919 } 923 }
920 924
921 // It's easier to have two separate tests with setup/teardown than to manualy 925 // 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. 926 // reset the state for the different flavors of the test.
923 TEST_F(SessionServiceTest, RestoreActivation2) { 927 TEST_F(SessionServiceTest, RestoreActivation2) {
924 SessionID window2_id; 928 SessionID window2_id;
925 SessionID tab1_id; 929 SessionID tab1_id;
926 SessionID tab2_id; 930 SessionID tab2_id;
927 SerializedNavigationEntry nav1; 931 SerializedNavigationEntry nav1;
928 SerializedNavigationEntry nav2; 932 SerializedNavigationEntry nav2;
929 933
930 CreateAndWriteSessionWithTwoWindows( 934 CreateAndWriteSessionWithTwoWindows(
931 window2_id, tab1_id, tab2_id, &nav1, &nav2); 935 window2_id, tab1_id, tab2_id, &nav1, &nav2);
932 936
933 service()->ScheduleCommand( 937 service()->ScheduleCommand(CreateSetActiveWindowCommand(window2_id));
934 service()->CreateSetActiveWindowCommand(window2_id)); 938 service()->ScheduleCommand(CreateSetActiveWindowCommand(window_id));
935 service()->ScheduleCommand( 939 service()->ScheduleCommand(CreateSetActiveWindowCommand(window2_id));
936 service()->CreateSetActiveWindowCommand(window_id));
937 service()->ScheduleCommand(
938 service()->CreateSetActiveWindowCommand(window2_id));
939 940
940 ScopedVector<SessionWindow> windows; 941 ScopedVector<SessionWindow> windows;
941 SessionID::id_type active_window_id = 0; 942 SessionID::id_type active_window_id = 0;
942 ReadWindows(&(windows.get()), &active_window_id); 943 ReadWindows(&(windows.get()), &active_window_id);
943 EXPECT_EQ(window2_id.id(), active_window_id); 944 EXPECT_EQ(window2_id.id(), active_window_id);
944 } 945 }
945 946
946 // Makes sure we don't track blacklisted URLs. 947 // Makes sure we don't track blacklisted URLs.
947 TEST_F(SessionServiceTest, IgnoreBlacklistedUrls) { 948 TEST_F(SessionServiceTest, IgnoreBlacklistedUrls) {
948 SessionID tab_id; 949 SessionID tab_id;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 &cancelable_task_tracker); 1017 &cancelable_task_tracker);
1017 helper_.RunTaskOnBackendThread( 1018 helper_.RunTaskOnBackendThread(
1018 FROM_HERE, 1019 FROM_HERE,
1019 base::Bind(&PostBackToThread, 1020 base::Bind(&PostBackToThread,
1020 base::Unretained(base::MessageLoop::current()), 1021 base::Unretained(base::MessageLoop::current()),
1021 base::Unretained(&run_loop))); 1022 base::Unretained(&run_loop)));
1022 delete helper_.ReleaseService(); 1023 delete helper_.ReleaseService();
1023 event.Signal(); 1024 event.Signal();
1024 run_loop.Run(); 1025 run_loop.Run();
1025 } 1026 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service_test_helper.cc ('k') | chrome/browser/sessions/session_service_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698