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_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/sync/test/integration/sync_test.h"
13 #include "components/sessions/session_types.h"
14 #include "components/sync_driver/glue/synced_session.h"
15 #include "sync/syncable/nigori_util.h"
19 namespace sessions_helper
{
21 typedef std::vector
<const sync_driver::SyncedSession
*> SyncedSessionVector
;
22 typedef sync_driver::SyncedSession::SyncedWindowMap SessionWindowMap
;
24 // Wrapper around a SyncedWindowMap that will automatically delete the
25 // SessionWindow pointers it holds.
26 class ScopedWindowMap
{
29 explicit ScopedWindowMap(SessionWindowMap
* windows
);
32 const SessionWindowMap
* Get() const;
33 SessionWindowMap
* GetMutable();
34 void Reset(SessionWindowMap
* windows
);
36 SessionWindowMap windows_
;
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
);
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
,
48 SessionWindowMap
* local_windows
);
50 // Checks that window count and foreign session count are 0.
51 bool CheckInitialState(int index
);
53 // Returns number of open windows for a profile.
54 int GetNumWindows(int index
);
56 // Returns number of foreign sessions for a profile.
57 int GetNumForeignSessions(int index
);
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
);
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 sync_driver::SyncedSession
* lhs
,
67 const sync_driver::SyncedSession
* rhs
);
69 // Sort a SyncedSession vector using our custom SyncedSession comparator.
70 void SortSyncedSessions(SyncedSessionVector
* sessions
);
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
);
77 // Verifies that two SessionWindows match.
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
85 bool WindowsMatch(const SessionWindowMap
& win1
,
86 const SessionWindowMap
& win2
);
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
92 bool CheckForeignSessionsAgainst(
94 const std::vector
<ScopedWindowMap
>& windows
);
96 // Retrieves the foreign sessions for a particular profile and compares them
97 // to the reference windows using CheckForeignSessionsAgains. Returns true if
98 // they match and doesn't time out.
99 bool AwaitCheckForeignSessionsAgainst(
100 int index
, const std::vector
<ScopedWindowMap
>& windows
);
102 // Open a single tab and block until the session model associator is aware
103 // of it. Returns true upon success, false otherwise.
104 bool OpenTab(int index
, const GURL
& url
);
106 // Open multiple tabs and block until the session model associator is aware
107 // of all of them. Returns true on success, false on failure.
108 bool OpenMultipleTabs(int index
, const std::vector
<GURL
>& urls
);
110 // Wait for a session change to propagate to the model associator. Will not
111 // return until each url in |urls| has been found.
112 bool WaitForTabsToLoad(int index
, const std::vector
<GURL
>& urls
);
114 // Check if the session model associator's knows that the current open tab
116 bool ModelAssociatorHasTabWithUrl(int index
, const GURL
& url
);
118 // Stores a pointer to the local session for a given profile in |session|.
119 // Returns true on success, false on failure.
120 bool GetLocalSession(int index
, const sync_driver::SyncedSession
** session
);
122 // Deletes the foreign session with tag |session_tag| from the profile specified
123 // by |index|. This will affect all synced clients.
124 // Note: We pass the session_tag in by value to ensure it's not a reference
125 // to the session tag within the SyncedSession we plan to delete.
126 void DeleteForeignSession(int index
, std::string session_tag
);
128 } // namespace sessions_helper
130 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_