Fix build break
[chromium-blink-merge.git] / chrome / browser / sessions / session_service_test_helper.cc
blobfc2108e7866f06f9aaf23ffb16e62b6550210847
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
3 // found in the LICENSE file.
5 #include "chrome/browser/sessions/session_service_test_helper.h"
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 "chrome/browser/sessions/session_types_test_helper.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using base::Time;
17 SessionServiceTestHelper::SessionServiceTestHelper() {}
19 SessionServiceTestHelper::SessionServiceTestHelper(SessionService* service)
20 : service_(service) {}
22 SessionServiceTestHelper::~SessionServiceTestHelper() {}
24 void SessionServiceTestHelper::PrepareTabInWindow(const SessionID& window_id,
25 const SessionID& tab_id,
26 int visual_index,
27 bool select) {
28 service()->SetTabWindow(window_id, tab_id);
29 service()->SetTabIndexInWindow(window_id, tab_id, visual_index);
30 if (select)
31 service()->SetSelectedTabInWindow(window_id, visual_index);
34 void SessionServiceTestHelper::SetTabExtensionAppID(
35 const SessionID& window_id,
36 const SessionID& tab_id,
37 const std::string& extension_app_id) {
38 service()->SetTabExtensionAppID(window_id, tab_id, extension_app_id);
41 void SessionServiceTestHelper::SetTabUserAgentOverride(
42 const SessionID& window_id,
43 const SessionID& tab_id,
44 const std::string& user_agent_override) {
45 service()->SetTabUserAgentOverride(window_id, tab_id, user_agent_override);
48 void SessionServiceTestHelper::SetForceBrowserNotAliveWithNoWindows(
49 bool force_browser_not_alive_with_no_windows) {
50 service()->force_browser_not_alive_with_no_windows_ =
51 force_browser_not_alive_with_no_windows;
54 // Be sure and null out service to force closing the file.
55 void SessionServiceTestHelper::ReadWindows(
56 std::vector<SessionWindow*>* windows,
57 SessionID::id_type* active_window_id) {
58 Time last_time;
59 ScopedVector<SessionCommand> read_commands;
60 backend()->ReadLastSessionCommandsImpl(&(read_commands.get()));
61 service()->RestoreSessionFromCommands(
62 read_commands.get(), windows, active_window_id);
65 void SessionServiceTestHelper::AssertTabEquals(SessionID& window_id,
66 SessionID& tab_id,
67 int visual_index,
68 int nav_index,
69 size_t nav_count,
70 const SessionTab& session_tab) {
71 EXPECT_EQ(window_id.id(), session_tab.window_id.id());
72 EXPECT_EQ(tab_id.id(), session_tab.tab_id.id());
73 AssertTabEquals(visual_index, nav_index, nav_count, session_tab);
76 void SessionServiceTestHelper::AssertTabEquals(
77 int visual_index,
78 int nav_index,
79 size_t nav_count,
80 const SessionTab& session_tab) {
81 EXPECT_EQ(visual_index, session_tab.tab_visual_index);
82 EXPECT_EQ(nav_index, session_tab.current_navigation_index);
83 ASSERT_EQ(nav_count, session_tab.navigations.size());
86 void SessionServiceTestHelper::AssertNavigationEquals(
87 const TabNavigation& expected,
88 const TabNavigation& actual) {
89 SessionTypesTestHelper::ExpectNavigationEquals(expected, actual);
92 void SessionServiceTestHelper::AssertSingleWindowWithSingleTab(
93 const std::vector<SessionWindow*>& windows,
94 size_t nav_count) {
95 ASSERT_EQ(1U, windows.size());
96 EXPECT_EQ(1U, windows[0]->tabs.size());
97 EXPECT_EQ(nav_count, windows[0]->tabs[0]->navigations.size());
100 SessionBackend* SessionServiceTestHelper::backend() {
101 return service_->backend();