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.
4
5#ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_TEST_HELPER_H_
6#define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_TEST_HELPER_H_
7
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/message_loop/message_loop.h"
14#include "components/sessions/session_id.h"
15
16class SessionBackend;
17class SessionCommand;
18class SessionService;
19struct SessionTab;
20struct SessionWindow;
21
22namespace base {
23class RunLoop;
24}
25
26namespace sessions {
27class SerializedNavigationEntry;
28}
29
30// A simple class that makes writing SessionService related tests easier.
31
32class SessionServiceTestHelper {
33 public:
34  SessionServiceTestHelper();
35  explicit SessionServiceTestHelper(SessionService* service);
36  ~SessionServiceTestHelper();
37
38  void PrepareTabInWindow(const SessionID& window_id,
39                          const SessionID& tab_id,
40                          int visual_index,
41                          bool select);
42
43  void SetTabExtensionAppID(const SessionID& window_id,
44                            const SessionID& tab_id,
45                            const std::string& extension_app_id);
46
47  void SetTabUserAgentOverride(const SessionID& window_id,
48                               const SessionID& tab_id,
49                               const std::string& user_agent_override);
50
51  void SetForceBrowserNotAliveWithNoWindows(
52      bool force_browser_not_alive_with_no_windows);
53
54  // Reads the contents of the last session.
55  void ReadWindows(std::vector<SessionWindow*>* windows,
56                   SessionID::id_type* active_window_id);
57
58  void AssertTabEquals(const SessionID& window_id,
59                       const SessionID& tab_id,
60                       int visual_index,
61                       int nav_index,
62                       size_t nav_count,
63                       const SessionTab& session_tab);
64
65  void AssertTabEquals(int visual_index,
66                       int nav_index,
67                       size_t nav_count,
68                       const SessionTab& session_tab);
69
70  void AssertNavigationEquals(
71      const sessions::SerializedNavigationEntry& expected,
72      const sessions::SerializedNavigationEntry& actual);
73
74  void AssertSingleWindowWithSingleTab(
75      const std::vector<SessionWindow*>& windows,
76      size_t nav_count);
77
78  void SetService(SessionService* service);
79  SessionService* ReleaseService() { return service_.release(); }
80  SessionService* service() { return service_.get(); }
81
82  SessionBackend* backend();
83
84  void RunTaskOnBackendThread(const tracked_objects::Location& from_here,
85                              const base::Closure& task);
86
87 private:
88  scoped_ptr<SessionService> service_;
89
90  DISALLOW_COPY_AND_ASSIGN(SessionServiceTestHelper);
91};
92
93#endif  // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_TEST_HELPER_H_
94