1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/session_service_test_helper.h"
#include "chrome/browser/session_backend.h"
#include "chrome/browser/session_service.h"
#include "chrome/common/scoped_vector.h"
#include "testing/gtest/include/gtest/gtest.h"
void SessionServiceTestHelper::RestoreSessionFromCommands(
const std::vector<SessionCommand*>& commands,
std::vector<SessionWindow*>* valid_windows) {
service()->RestoreSessionFromCommands(commands, valid_windows);
}
void SessionServiceTestHelper::PrepareTabInWindow(const SessionID& window_id,
const SessionID& tab_id,
int visual_index,
bool select) {
service()->SetTabWindow(window_id, tab_id);
service()->SetTabIndexInWindow(window_id, tab_id, visual_index);
if (select)
service()->SetSelectedTabInWindow(window_id, visual_index);
}
// Be sure and null out service to force closing the file.
void SessionServiceTestHelper::ReadWindows(
std::vector<SessionWindow*>* windows) {
Time last_time;
ScopedVector<SessionCommand> read_commands;
backend()->ReadSessionImpl(false, &(read_commands.get()));
RestoreSessionFromCommands(read_commands.get(), windows);
}
void SessionServiceTestHelper::AssertTabEquals(SessionID& window_id,
SessionID& tab_id,
int visual_index,
int nav_index,
int nav_count,
const SessionTab& session_tab) {
EXPECT_EQ(window_id.id(), session_tab.window_id.id());
EXPECT_EQ(tab_id.id(), session_tab.tab_id.id());
AssertTabEquals(visual_index, nav_index, nav_count, session_tab);
}
void SessionServiceTestHelper::AssertTabEquals(
int visual_index,
int nav_index,
int nav_count,
const SessionTab& session_tab) {
EXPECT_EQ(visual_index, session_tab.tab_visual_index);
EXPECT_EQ(nav_index, session_tab.current_navigation_index);
ASSERT_EQ(nav_count, session_tab.navigations.size());
}
void SessionServiceTestHelper::AssertNavigationEquals(
const TabNavigation& expected,
const TabNavigation& actual) {
EXPECT_EQ(expected.index, actual.index);
EXPECT_TRUE(expected.url == actual.url);
EXPECT_EQ(expected.title, actual.title);
EXPECT_EQ(expected.state, actual.state);
EXPECT_EQ(expected.transition, actual.transition);
EXPECT_EQ(expected.type_mask, actual.type_mask);
}
void SessionServiceTestHelper::AssertSingleWindowWithSingleTab(
const std::vector<SessionWindow*>& windows,
int nav_count) {
EXPECT_EQ(1, windows.size());
EXPECT_EQ(1, windows[0]->tabs.size());
EXPECT_EQ(nav_count, windows[0]->tabs[0]->navigations.size());
}
SessionBackend* SessionServiceTestHelper::backend() {
return service_->backend_.get();
}
|