Fixes possible use after free in SessionService
[chromium-blink-merge.git] / chrome / browser / sessions / session_service_test_helper.h
blob8daadd8e5773ba06b3d276246816403989d455b7
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 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_TEST_HELPER_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_TEST_HELPER_H_
8 #include <string>
9 #include <vector>
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"
16 class SessionBackend;
17 class SessionCommand;
18 class SessionService;
19 struct SessionTab;
20 struct SessionWindow;
22 namespace base {
23 class RunLoop;
26 namespace sessions {
27 class SerializedNavigationEntry;
30 // A simple class that makes writing SessionService related tests easier.
32 class SessionServiceTestHelper {
33 public:
34 SessionServiceTestHelper();
35 explicit SessionServiceTestHelper(SessionService* service);
36 ~SessionServiceTestHelper();
38 void PrepareTabInWindow(const SessionID& window_id,
39 const SessionID& tab_id,
40 int visual_index,
41 bool select);
43 void SetTabExtensionAppID(const SessionID& window_id,
44 const SessionID& tab_id,
45 const std::string& extension_app_id);
47 void SetTabUserAgentOverride(const SessionID& window_id,
48 const SessionID& tab_id,
49 const std::string& user_agent_override);
51 void SetForceBrowserNotAliveWithNoWindows(
52 bool force_browser_not_alive_with_no_windows);
54 // Reads the contents of the last session.
55 void ReadWindows(std::vector<SessionWindow*>* windows,
56 SessionID::id_type* active_window_id);
58 void AssertTabEquals(SessionID& window_id,
59 SessionID& tab_id,
60 int visual_index,
61 int nav_index,
62 size_t nav_count,
63 const SessionTab& session_tab);
65 void AssertTabEquals(int visual_index,
66 int nav_index,
67 size_t nav_count,
68 const SessionTab& session_tab);
70 void AssertNavigationEquals(
71 const sessions::SerializedNavigationEntry& expected,
72 const sessions::SerializedNavigationEntry& actual);
74 void AssertSingleWindowWithSingleTab(
75 const std::vector<SessionWindow*>& windows,
76 size_t nav_count);
78 void SetService(SessionService* service);
79 SessionService* ReleaseService() { return service_.release(); }
80 SessionService* service() { return service_.get(); }
82 SessionBackend* backend();
84 void RunTaskOnBackendThread(const tracked_objects::Location& from_here,
85 const base::Closure& task);
87 private:
88 scoped_ptr<SessionService> service_;
90 DISALLOW_COPY_AND_ASSIGN(SessionServiceTestHelper);
93 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_TEST_HELPER_H_