Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sessions / session_service_test_helper.cc
blobf81769c1db8e3c892b84bf975feacbb1652e4ff1
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 "components/sessions/serialized_navigation_entry_test_helper.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using base::Time;
18 SessionServiceTestHelper::SessionServiceTestHelper() {}
20 SessionServiceTestHelper::SessionServiceTestHelper(SessionService* service)
21 : service_(service) {}
23 SessionServiceTestHelper::~SessionServiceTestHelper() {}
25 void SessionServiceTestHelper::PrepareTabInWindow(const SessionID& window_id,
26 const SessionID& tab_id,
27 int visual_index,
28 bool select) {
29 service()->SetTabWindow(window_id, tab_id);
30 service()->SetTabIndexInWindow(window_id, tab_id, visual_index);
31 if (select)
32 service()->SetSelectedTabInWindow(window_id, visual_index);
35 void SessionServiceTestHelper::SetTabExtensionAppID(
36 const SessionID& window_id,
37 const SessionID& tab_id,
38 const std::string& extension_app_id) {
39 service()->SetTabExtensionAppID(window_id, tab_id, extension_app_id);
42 void SessionServiceTestHelper::SetTabUserAgentOverride(
43 const SessionID& window_id,
44 const SessionID& tab_id,
45 const std::string& user_agent_override) {
46 service()->SetTabUserAgentOverride(window_id, tab_id, user_agent_override);
49 void SessionServiceTestHelper::SetForceBrowserNotAliveWithNoWindows(
50 bool force_browser_not_alive_with_no_windows) {
51 service()->force_browser_not_alive_with_no_windows_ =
52 force_browser_not_alive_with_no_windows;
55 // Be sure and null out service to force closing the file.
56 void SessionServiceTestHelper::ReadWindows(
57 std::vector<SessionWindow*>* windows,
58 SessionID::id_type* active_window_id) {
59 Time last_time;
60 ScopedVector<SessionCommand> read_commands;
61 backend()->ReadLastSessionCommandsImpl(&(read_commands.get()));
62 service()->RestoreSessionFromCommands(
63 read_commands.get(), windows, active_window_id);
66 void SessionServiceTestHelper::AssertTabEquals(SessionID& window_id,
67 SessionID& tab_id,
68 int visual_index,
69 int nav_index,
70 size_t nav_count,
71 const SessionTab& session_tab) {
72 EXPECT_EQ(window_id.id(), session_tab.window_id.id());
73 EXPECT_EQ(tab_id.id(), session_tab.tab_id.id());
74 AssertTabEquals(visual_index, nav_index, nav_count, session_tab);
77 void SessionServiceTestHelper::AssertTabEquals(
78 int visual_index,
79 int nav_index,
80 size_t nav_count,
81 const SessionTab& session_tab) {
82 EXPECT_EQ(visual_index, session_tab.tab_visual_index);
83 EXPECT_EQ(nav_index, session_tab.current_navigation_index);
84 ASSERT_EQ(nav_count, session_tab.navigations.size());
87 // TODO(sky): nuke this and change to call directly into
88 // SerializedNavigationEntryTestHelper.
89 void SessionServiceTestHelper::AssertNavigationEquals(
90 const sessions::SerializedNavigationEntry& expected,
91 const sessions::SerializedNavigationEntry& actual) {
92 sessions::SerializedNavigationEntryTestHelper::ExpectNavigationEquals(
93 expected, actual);
96 void SessionServiceTestHelper::AssertSingleWindowWithSingleTab(
97 const std::vector<SessionWindow*>& windows,
98 size_t nav_count) {
99 ASSERT_EQ(1U, windows.size());
100 EXPECT_EQ(1U, windows[0]->tabs.size());
101 EXPECT_EQ(nav_count, windows[0]->tabs[0]->navigations.size());
104 SessionBackend* SessionServiceTestHelper::backend() {
105 return service_->backend();
108 void SessionServiceTestHelper::SetService(SessionService* service) {
109 service_.reset(service);
110 // Execute IO tasks posted by the SessionService.
111 content::BrowserThread::GetBlockingPool()->FlushForTesting();