Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chrome / browser / sessions / session_service_test_helper.cc
blob0a1f98289f14d9709a01949f75a5ae72ce0017d5
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 "base/message_loop/message_loop.h"
9 #include "chrome/browser/sessions/session_backend.h"
10 #include "chrome/browser/sessions/session_service.h"
11 #include "chrome/browser/sessions/session_types.h"
12 #include "components/sessions/serialized_navigation_entry_test_helper.h"
13 #include "components/sessions/session_id.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 using base::Time;
19 SessionServiceTestHelper::SessionServiceTestHelper() {}
21 SessionServiceTestHelper::SessionServiceTestHelper(SessionService* service)
22 : service_(service) {}
24 SessionServiceTestHelper::~SessionServiceTestHelper() {}
26 void SessionServiceTestHelper::PrepareTabInWindow(const SessionID& window_id,
27 const SessionID& tab_id,
28 int visual_index,
29 bool select) {
30 service()->SetTabWindow(window_id, tab_id);
31 service()->SetTabIndexInWindow(window_id, tab_id, visual_index);
32 if (select)
33 service()->SetSelectedTabInWindow(window_id, visual_index);
36 void SessionServiceTestHelper::SetTabExtensionAppID(
37 const SessionID& window_id,
38 const SessionID& tab_id,
39 const std::string& extension_app_id) {
40 service()->SetTabExtensionAppID(window_id, tab_id, extension_app_id);
43 void SessionServiceTestHelper::SetTabUserAgentOverride(
44 const SessionID& window_id,
45 const SessionID& tab_id,
46 const std::string& user_agent_override) {
47 service()->SetTabUserAgentOverride(window_id, tab_id, user_agent_override);
50 void SessionServiceTestHelper::SetForceBrowserNotAliveWithNoWindows(
51 bool force_browser_not_alive_with_no_windows) {
52 service()->force_browser_not_alive_with_no_windows_ =
53 force_browser_not_alive_with_no_windows;
56 // Be sure and null out service to force closing the file.
57 void SessionServiceTestHelper::ReadWindows(
58 std::vector<SessionWindow*>* windows,
59 SessionID::id_type* active_window_id) {
60 Time last_time;
61 ScopedVector<SessionCommand> read_commands;
62 backend()->ReadLastSessionCommandsImpl(&(read_commands.get()));
63 service()->RestoreSessionFromCommands(
64 read_commands.get(), windows, active_window_id);
67 void SessionServiceTestHelper::AssertTabEquals(SessionID& window_id,
68 SessionID& tab_id,
69 int visual_index,
70 int nav_index,
71 size_t nav_count,
72 const SessionTab& session_tab) {
73 EXPECT_EQ(window_id.id(), session_tab.window_id.id());
74 EXPECT_EQ(tab_id.id(), session_tab.tab_id.id());
75 AssertTabEquals(visual_index, nav_index, nav_count, session_tab);
78 void SessionServiceTestHelper::AssertTabEquals(
79 int visual_index,
80 int nav_index,
81 size_t nav_count,
82 const SessionTab& session_tab) {
83 EXPECT_EQ(visual_index, session_tab.tab_visual_index);
84 EXPECT_EQ(nav_index, session_tab.current_navigation_index);
85 ASSERT_EQ(nav_count, session_tab.navigations.size());
88 // TODO(sky): nuke this and change to call directly into
89 // SerializedNavigationEntryTestHelper.
90 void SessionServiceTestHelper::AssertNavigationEquals(
91 const sessions::SerializedNavigationEntry& expected,
92 const sessions::SerializedNavigationEntry& actual) {
93 sessions::SerializedNavigationEntryTestHelper::ExpectNavigationEquals(
94 expected, actual);
97 void SessionServiceTestHelper::AssertSingleWindowWithSingleTab(
98 const std::vector<SessionWindow*>& windows,
99 size_t nav_count) {
100 ASSERT_EQ(1U, windows.size());
101 EXPECT_EQ(1U, windows[0]->tabs.size());
102 EXPECT_EQ(nav_count, windows[0]->tabs[0]->navigations.size());
105 SessionBackend* SessionServiceTestHelper::backend() {
106 return service_->backend();
109 void SessionServiceTestHelper::SetService(SessionService* service) {
110 service_.reset(service);
111 // Execute IO tasks posted by the SessionService.
112 content::BrowserThread::GetBlockingPool()->FlushForTesting();
115 void SessionServiceTestHelper::RunTaskOnBackendThread(
116 const tracked_objects::Location& from_here,
117 const base::Closure& task) {
118 service_->RunTaskOnBackendThread(from_here, task);