• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/sessions/session_service_test_helper.h"
6 
7 #include "base/memory/scoped_vector.h"
8 #include "chrome/browser/sessions/session_backend.h"
9 #include "chrome/browser/sessions/session_id.h"
10 #include "chrome/browser/sessions/session_service.h"
11 #include "chrome/browser/sessions/session_types.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 
14 using base::Time;
15 
SessionServiceTestHelper()16 SessionServiceTestHelper::SessionServiceTestHelper() {}
17 
SessionServiceTestHelper(SessionService * service)18 SessionServiceTestHelper::SessionServiceTestHelper(SessionService* service)
19     : service_(service) {}
20 
~SessionServiceTestHelper()21 SessionServiceTestHelper::~SessionServiceTestHelper() {}
22 
RestoreSessionFromCommands(const std::vector<SessionCommand * > & commands,std::vector<SessionWindow * > * valid_windows)23 void SessionServiceTestHelper::RestoreSessionFromCommands(
24     const std::vector<SessionCommand*>& commands,
25     std::vector<SessionWindow*>* valid_windows) {
26   service()->RestoreSessionFromCommands(commands, valid_windows);
27 }
28 
PrepareTabInWindow(const SessionID & window_id,const SessionID & tab_id,int visual_index,bool select)29 void SessionServiceTestHelper::PrepareTabInWindow(const SessionID& window_id,
30                                                   const SessionID& tab_id,
31                                                   int visual_index,
32                                                   bool select) {
33   service()->SetTabWindow(window_id, tab_id);
34   service()->SetTabIndexInWindow(window_id, tab_id, visual_index);
35   if (select)
36     service()->SetSelectedTabInWindow(window_id, visual_index);
37 }
38 
SetTabExtensionAppID(const SessionID & window_id,const SessionID & tab_id,const std::string & extension_app_id)39 void SessionServiceTestHelper::SetTabExtensionAppID(
40     const SessionID& window_id,
41     const SessionID& tab_id,
42     const std::string& extension_app_id) {
43   service()->SetTabExtensionAppID(window_id, tab_id, extension_app_id);
44 }
45 
46 // Be sure and null out service to force closing the file.
ReadWindows(std::vector<SessionWindow * > * windows)47 void SessionServiceTestHelper::ReadWindows(
48     std::vector<SessionWindow*>* windows) {
49   Time last_time;
50   ScopedVector<SessionCommand> read_commands;
51   backend()->ReadLastSessionCommandsImpl(&(read_commands.get()));
52   RestoreSessionFromCommands(read_commands.get(), windows);
53 }
54 
AssertTabEquals(SessionID & window_id,SessionID & tab_id,int visual_index,int nav_index,size_t nav_count,const SessionTab & session_tab)55 void SessionServiceTestHelper::AssertTabEquals(SessionID& window_id,
56                                                SessionID& tab_id,
57                                                int visual_index,
58                                                int nav_index,
59                                                size_t nav_count,
60                                                const SessionTab& session_tab) {
61   EXPECT_EQ(window_id.id(), session_tab.window_id.id());
62   EXPECT_EQ(tab_id.id(), session_tab.tab_id.id());
63   AssertTabEquals(visual_index, nav_index, nav_count, session_tab);
64 }
65 
AssertTabEquals(int visual_index,int nav_index,size_t nav_count,const SessionTab & session_tab)66 void SessionServiceTestHelper::AssertTabEquals(
67     int visual_index,
68     int nav_index,
69     size_t nav_count,
70     const SessionTab& session_tab) {
71   EXPECT_EQ(visual_index, session_tab.tab_visual_index);
72   EXPECT_EQ(nav_index, session_tab.current_navigation_index);
73   ASSERT_EQ(nav_count, session_tab.navigations.size());
74 }
75 
AssertNavigationEquals(const TabNavigation & expected,const TabNavigation & actual)76 void SessionServiceTestHelper::AssertNavigationEquals(
77     const TabNavigation& expected,
78     const TabNavigation& actual) {
79   EXPECT_TRUE(expected.virtual_url() == actual.virtual_url());
80   EXPECT_EQ(expected.referrer(), actual.referrer());
81   EXPECT_EQ(expected.title(), actual.title());
82   EXPECT_EQ(expected.state(), actual.state());
83   EXPECT_EQ(expected.transition(), actual.transition());
84   EXPECT_EQ(expected.type_mask(), actual.type_mask());
85 }
86 
AssertSingleWindowWithSingleTab(const std::vector<SessionWindow * > & windows,size_t nav_count)87 void SessionServiceTestHelper::AssertSingleWindowWithSingleTab(
88     const std::vector<SessionWindow*>& windows,
89     size_t nav_count) {
90   ASSERT_EQ(1U, windows.size());
91   EXPECT_EQ(1U, windows[0]->tabs.size());
92   EXPECT_EQ(nav_count, windows[0]->tabs[0]->navigations.size());
93 }
94 
backend()95 SessionBackend* SessionServiceTestHelper::backend() {
96   return service_->backend();
97 }
98