1 // Copyright (c) 2011 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 #pragma once 8 9 #include <string> 10 #include <vector> 11 12 #include "base/memory/ref_counted.h" 13 14 class SessionBackend; 15 class SessionCommand; 16 class SessionID; 17 class SessionService; 18 struct SessionTab; 19 struct SessionWindow; 20 class TabNavigation; 21 22 // A simple class that makes writing SessionService related tests easier. 23 24 class SessionServiceTestHelper { 25 public: 26 explicit SessionServiceTestHelper(); 27 explicit SessionServiceTestHelper(SessionService* service); 28 ~SessionServiceTestHelper(); 29 30 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands, 31 std::vector<SessionWindow*>* valid_windows); 32 33 void PrepareTabInWindow(const SessionID& window_id, 34 const SessionID& tab_id, 35 int visual_index, 36 bool select); 37 38 void SetTabExtensionAppID(const SessionID& window_id, 39 const SessionID& tab_id, 40 const std::string& extension_app_id); 41 42 // Reads the contents of the last session. 43 void ReadWindows(std::vector<SessionWindow*>* windows); 44 45 void AssertTabEquals(SessionID& window_id, 46 SessionID& tab_id, 47 int visual_index, 48 int nav_index, 49 size_t nav_count, 50 const SessionTab& session_tab); 51 52 void AssertTabEquals(int visual_index, 53 int nav_index, 54 size_t nav_count, 55 const SessionTab& session_tab); 56 57 void AssertNavigationEquals(const TabNavigation& expected, 58 const TabNavigation& actual); 59 60 void AssertSingleWindowWithSingleTab( 61 const std::vector<SessionWindow*>& windows, 62 size_t nav_count); 63 64 void set_service(SessionService* service) { service_ = service; } 65 SessionService* ReleaseService() { return service_.release(); } 66 SessionService* service() { return service_.get(); } 67 68 SessionBackend* backend(); 69 70 private: 71 scoped_refptr<SessionService> service_; 72 73 DISALLOW_COPY_AND_ASSIGN(SessionServiceTestHelper); 74 }; 75 76 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_TEST_HELPER_H_ 77