• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
7 
8 #include <algorithm>
9 #include <vector>
10 
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/sessions/session_types.h"
13 #include "chrome/browser/sync/glue/synced_session.h"
14 #include "chrome/browser/sync/test/integration/sync_test.h"
15 #include "sync/syncable/nigori_util.h"
16 
17 class GURL;
18 
19 namespace sessions_helper {
20 
21 typedef std::vector<const browser_sync::SyncedSession*> SyncedSessionVector;
22 typedef browser_sync::SyncedSession::SyncedWindowMap SessionWindowMap;
23 
24 // Wrapper around a SyncedWindowMap that will automatically delete the
25 // SessionWindow pointers it holds.
26 class ScopedWindowMap {
27  public:
28   ScopedWindowMap();
29   explicit ScopedWindowMap(SessionWindowMap* windows);
30   ~ScopedWindowMap();
31 
32   const SessionWindowMap* Get() const;
33   SessionWindowMap* GetMutable();
34   void Reset(SessionWindowMap* windows);
35  private:
36   SessionWindowMap windows_;
37 };
38 
39 // Copies the local session windows of profile |index| to |local_windows|.
40 // Returns true if successful.
41 bool GetLocalWindows(int index, SessionWindowMap* local_windows);
42 
43 // Creates and verifies the creation of a new window for profile |index| with
44 // one tab displaying |url|. Copies the SessionWindow associated with the new
45 // window to |local_windows|. Returns true if successful.
46 bool OpenTabAndGetLocalWindows(int index,
47                                const GURL& url,
48                                SessionWindowMap* local_windows);
49 
50 // Checks that window count and foreign session count are 0.
51 bool CheckInitialState(int index);
52 
53 // Returns number of open windows for a profile.
54 int GetNumWindows(int index);
55 
56 // Returns number of foreign sessions for a profile.
57 int GetNumForeignSessions(int index);
58 
59 // Fills the sessions vector with the model associator's foreign session data.
60 // Caller owns |sessions|, but not SyncedSessions objects within.
61 // Returns true if foreign sessions were found, false otherwise.
62 bool GetSessionData(int index, SyncedSessionVector* sessions);
63 
64 // Compares a foreign session based on the first session window.
65 // Returns true based on the comparison of the session windows.
66 bool CompareSyncedSessions(const browser_sync::SyncedSession* lhs,
67                            const browser_sync::SyncedSession* rhs);
68 
69 // Sort a SyncedSession vector using our custom SyncedSession comparator.
70 void SortSyncedSessions(SyncedSessionVector* sessions);
71 
72 // Compares two tab navigations base on the parameters we sync.
73 // (Namely, we don't sync state or type mask)
74 bool NavigationEquals(const sessions::SerializedNavigationEntry& expected,
75                       const sessions::SerializedNavigationEntry& actual);
76 
77 // Verifies that two SessionWindows match.
78 // Returns:
79 //  - true if all the following match:
80 //    1. number of SessionWindows,
81 //    2. number of tabs per SessionWindow,
82 //    3. number of tab navigations per tab,
83 //    4. actual tab navigations contents
84 // - false otherwise.
85 bool WindowsMatch(const SessionWindowMap& win1,
86                   const SessionWindowMap& win2);
87 
88 // Retrieves the foreign sessions for a particular profile and compares them
89 // with a reference SessionWindow list.
90 // Returns true if the session windows of the foreign session matches the
91 // reference.
92 bool CheckForeignSessionsAgainst(
93     int index,
94     const std::vector<ScopedWindowMap>& windows);
95 
96 // Open a single tab and block until the session model associator is aware
97 // of it. Returns true upon success, false otherwise.
98 bool OpenTab(int index, const GURL& url);
99 
100 // Open multiple tabs and block until the session model associator is aware
101 // of all of them.  Returns true on success, false on failure.
102 bool OpenMultipleTabs(int index, const std::vector<GURL>& urls);
103 
104 // Wait for a session change to propagate to the model associator.  Will not
105 // return until each url in |urls| has been found.
106 bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls);
107 
108 // Check if the session model associator's knows that the current open tab
109 // has this url.
110 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url);
111 
112 // Stores a pointer to the local session for a given profile in |session|.
113 // Returns true on success, false on failure.
114 bool GetLocalSession(int index, const browser_sync::SyncedSession** session);
115 
116 // Deletes the foreign session with tag |session_tag| from the profile specified
117 // by |index|. This will affect all synced clients.
118 // Note: We pass the session_tag in by value to ensure it's not a reference
119 // to the session tag within the SyncedSession we plan to delete.
120 void DeleteForeignSession(int index, std::string session_tag);
121 
122 }  // namespace sessions_helper
123 
124 #endif  // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
125