Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/sync/test/integration/sessions_helper.h

Issue 7966020: [Sync] Fix Session's handling of windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits, rebase. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_ 5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_ 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "chrome/browser/sessions/session_types.h" 13 #include "chrome/browser/sessions/session_types.h"
14 #include "chrome/browser/sync/glue/synced_session.h" 14 #include "chrome/browser/sync/glue/synced_session.h"
15 #include "chrome/browser/sync/engine/nigori_util.h" 15 #include "chrome/browser/sync/engine/nigori_util.h"
16 #include "chrome/browser/sync/test/integration/sync_test.h" 16 #include "chrome/browser/sync/test/integration/sync_test.h"
17 17
18 class GURL; 18 class GURL;
19 19
20 namespace sessions_helper {
21
20 typedef std::vector<const browser_sync::SyncedSession*> SyncedSessionVector; 22 typedef std::vector<const browser_sync::SyncedSession*> SyncedSessionVector;
21 typedef std::vector<SessionWindow*> SessionWindowVector; 23 typedef browser_sync::SyncedSession::SyncedWindowMap SessionWindowMap;
22 24
23 namespace sessions_helper { 25 // Wrapper around a SyncedWindowMap that will automatically delete the
26 // SessionWindow pointers it holds.
27 class ScopedWindowMap {
28 public:
29 ScopedWindowMap();
30 explicit ScopedWindowMap(SessionWindowMap* windows);
31 ~ScopedWindowMap();
32
33 const SessionWindowMap* Get() const;
34 SessionWindowMap* GetMutable();
35 void Reset(SessionWindowMap* windows);
36 private:
37 SessionWindowMap windows_;
38 };
24 39
25 // Copies the local session windows of profile |index| to |local_windows|. 40 // Copies the local session windows of profile |index| to |local_windows|.
26 // Returns true if successful. 41 // Returns true if successful.
27 bool GetLocalWindows(int index, SessionWindowVector& local_windows); 42 bool GetLocalWindows(int index, SessionWindowMap* local_windows);
28 43
29 // Creates and verifies the creation of a new window for profile |index| with 44 // Creates and verifies the creation of a new window for profile |index| with
30 // one tab displaying |url|. Copies the SessionWindow associated with the new 45 // one tab displaying |url|. Copies the SessionWindow associated with the new
31 // window to |local_windows|. Returns true if successful. 46 // window to |local_windows|. Returns true if successful.
32 bool OpenTabAndGetLocalWindows(int index, 47 bool OpenTabAndGetLocalWindows(int index,
33 const GURL& url, 48 const GURL& url,
34 SessionWindowVector& local_windows); 49 SessionWindowMap* local_windows);
35 50
36 // Checks that window count and foreign session count are 0. 51 // Checks that window count and foreign session count are 0.
37 bool CheckInitialState(int index); 52 bool CheckInitialState(int index);
38 53
39 // Returns number of open windows for a profile. 54 // Returns number of open windows for a profile.
40 int GetNumWindows(int index); 55 int GetNumWindows(int index);
41 56
42 // Returns number of foreign sessions for a profile. 57 // Returns number of foreign sessions for a profile.
43 int GetNumForeignSessions(int index); 58 int GetNumForeignSessions(int index);
44 59
45 // Fills the sessions vector with the model associator's foreign session data. 60 // Fills the sessions vector with the model associator's foreign session data.
46 // Caller owns |sessions|, but not SyncedSessions objects within. 61 // Caller owns |sessions|, but not SyncedSessions objects within.
47 bool GetSessionData(int index, SyncedSessionVector* sessions); 62 bool GetSessionData(int index, SyncedSessionVector* sessions);
48 63
49 // Compare session windows based on their first tab's url.
50 // Returns true if the virtual url of the lhs is < the rhs.
51 bool CompareSessionWindows(SessionWindow* lhs, SessionWindow* rhs);
52
53 // Sort session windows using our custom comparator (first tab url
54 // comparison).
55 void SortSessionWindows(SessionWindowVector& windows);
56
57 // Compares a foreign session based on the first session window. 64 // Compares a foreign session based on the first session window.
58 // Returns true based on the comparison of the session windows. 65 // Returns true based on the comparison of the session windows.
59 bool CompareSyncedSessions(const browser_sync::SyncedSession* lhs, 66 bool CompareSyncedSessions(const browser_sync::SyncedSession* lhs,
60 const browser_sync::SyncedSession* rhs); 67 const browser_sync::SyncedSession* rhs);
61 68
62 // Sort a SyncedSession vector using our custom SyncedSession comparator. 69 // Sort a SyncedSession vector using our custom SyncedSession comparator.
63 void SortSyncedSessions(SyncedSessionVector* sessions); 70 void SortSyncedSessions(SyncedSessionVector* sessions);
64 71
65 // Compares two tab navigations base on the parameters we sync. 72 // Compares two tab navigations base on the parameters we sync.
66 // (Namely, we don't sync state or type mask) 73 // (Namely, we don't sync state or type mask)
67 bool NavigationEquals(const TabNavigation& expected, 74 bool NavigationEquals(const TabNavigation& expected,
68 const TabNavigation& actual); 75 const TabNavigation& actual);
69 76
70 // Verifies that two SessionWindows match. 77 // Verifies that two SessionWindows match.
71 // Returns: 78 // Returns:
72 // - true if all the following match: 79 // - true if all the following match:
73 // 1. number of SessionWindows, 80 // 1. number of SessionWindows,
74 // 2. number of tabs per SessionWindow, 81 // 2. number of tabs per SessionWindow,
75 // 3. number of tab navigations per tab, 82 // 3. number of tab navigations per tab,
76 // 4. actual tab navigations contents 83 // 4. actual tab navigations contents
77 // - false otherwise. 84 // - false otherwise.
78 bool WindowsMatch(const SessionWindowVector& win1, 85 bool WindowsMatch(const SessionWindowMap& win1,
79 const SessionWindowVector& win2); 86 const SessionWindowMap& win2);
80 87
81 // Retrieves the foreign sessions for a particular profile and compares them 88 // Retrieves the foreign sessions for a particular profile and compares them
82 // with a reference SessionWindow list. 89 // with a reference SessionWindow list.
83 // Returns true if the session windows of the foreign session matches the 90 // Returns true if the session windows of the foreign session matches the
84 // reference. 91 // reference.
85 bool CheckForeignSessionsAgainst( 92 bool CheckForeignSessionsAgainst(
86 int index, 93 int index,
87 const std::vector<SessionWindowVector*>& windows); 94 const std::vector<ScopedWindowMap>& windows);
88 95
89 // Open a single tab and block until the session model associator is aware 96 // Open a single tab and block until the session model associator is aware
90 // of it. Returns true upon success, false otherwise. 97 // of it. Returns true upon success, false otherwise.
91 bool OpenTab(int index, const GURL& url); 98 bool OpenTab(int index, const GURL& url);
92 99
93 // Open multiple tabs and block until the session model associator is aware 100 // Open multiple tabs and block until the session model associator is aware
94 // of all of them. Returns true on success, false on failure. 101 // of all of them. Returns true on success, false on failure.
95 bool OpenMultipleTabs(int index, const std::vector<GURL>& urls); 102 bool OpenMultipleTabs(int index, const std::vector<GURL>& urls);
96 103
97 // Wait for a session change to propagate to the model associator. Will not 104 // Wait for a session change to propagate to the model associator. Will not
98 // return until each url in |urls| has been found. 105 // return until each url in |urls| has been found.
99 bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls); 106 bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls);
100 107
101 // Check if the session model associator's knows that the current open tab 108 // Check if the session model associator's knows that the current open tab
102 // has this url. 109 // has this url.
103 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url); 110 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url);
104 111
105 // Stores a pointer to the local session for a given profile in |session|. 112 // Stores a pointer to the local session for a given profile in |session|.
106 // Returns true on success, false on failure. 113 // Returns true on success, false on failure.
107 bool GetLocalSession(int index, const browser_sync::SyncedSession** session); 114 bool GetLocalSession(int index, const browser_sync::SyncedSession** session);
108 115
109 } // namespace sessions_helper 116 } // namespace sessions_helper
110 117
111 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_ 118 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698