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

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

Issue 2713913002: [sync] Add Sessions integration tests (Closed)
Patch Set: Update commit message Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke r.h" 15 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke r.h"
16 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
16 #include "chrome/browser/sync/test/integration/sync_test.h" 17 #include "chrome/browser/sync/test/integration/sync_test.h"
17 #include "components/sessions/core/session_types.h" 18 #include "components/sessions/core/session_types.h"
18 #include "components/sync/syncable/nigori_util.h" 19 #include "components/sync/syncable/nigori_util.h"
20 #include "components/sync/test/fake_server/fake_server_verifier.h"
21 #include "components/sync/test/fake_server/sessions_hierarchy.h"
19 #include "components/sync_sessions/synced_session.h" 22 #include "components/sync_sessions/synced_session.h"
20 23
21 class GURL; 24 class GURL;
22 25
26 namespace fake_server {
27 class SessionsHierarchy;
28 class FakeServer;
29 class FakeServerVerifier;
30 }
31
23 namespace sessions_helper { 32 namespace sessions_helper {
24 33
25 using SyncedSessionVector = std::vector<const sync_sessions::SyncedSession*>; 34 using SyncedSessionVector = std::vector<const sync_sessions::SyncedSession*>;
26 using SessionWindowMap = std::map<SessionID::id_type, sessions::SessionWindow*>; 35 using SessionWindowMap = std::map<SessionID::id_type, sessions::SessionWindow*>;
27 using ScopedWindowMap = 36 using ScopedWindowMap =
28 std::map<SessionID::id_type, std::unique_ptr<sessions::SessionWindow>>; 37 std::map<SessionID::id_type, std::unique_ptr<sessions::SessionWindow>>;
29 38
30 // Copies the local session windows of profile |index| to |local_windows|. 39 // Copies the local session windows of profileat |profile_index| to
Nicolas Zea 2017/02/24 20:25:30 nit: profileat
Patrick Noland 2017/02/27 18:53:25 Done.
31 // Returns true if successful. 40 // |local_windows|. Returns true if successful.
32 bool GetLocalWindows(int index, ScopedWindowMap* local_windows); 41 bool GetLocalWindows(int profile_index, ScopedWindowMap* local_windows);
33 42
34 // Creates and verifies the creation of a new window for profile |index| with 43 // Creates and verifies the creation of a new window for profile |profile_index|
44 // with
35 // one tab displaying |url|. Copies the SessionWindow associated with the new 45 // one tab displaying |url|. Copies the SessionWindow associated with the new
36 // window to |local_windows|. Returns true if successful. This call results in 46 // window to |local_windows|. Returns true if successful. This call results in
37 // multiple sessions changes, and performs synchronous blocking. It is rare, but 47 // multiple sessions changes, and performs synchronous blocking. It is rare, but
38 // possible, that multiple sync cycle commits occur as a result of this call. 48 // possible, that multiple sync cycle commits occur as a result of this call.
39 // Test cases should be written to handle this possibility, otherwise they may 49 // Test cases should be written to handle this possibility, otherwise they may
40 // flake. 50 // flake.
41 bool OpenTabAndGetLocalWindows(int index, 51 bool OpenTabAndGetLocalWindows(int profile_index,
42 const GURL& url, 52 const GURL& url,
43 ScopedWindowMap* local_windows); 53 ScopedWindowMap* local_windows);
44 54
45 // Checks that window count and foreign session count are 0. 55 // Checks that window count and foreign session count are 0.
46 bool CheckInitialState(int index); 56 bool CheckInitialState(int profile_index);
47 57
48 // Returns number of open windows for a profile. 58 // Returns number of open windows for a profile.
49 int GetNumWindows(int index); 59 int GetNumWindows(int profile_index);
50 60
51 // Returns number of foreign sessions for a profile. 61 // Returns number of foreign sessions for a profile.
52 int GetNumForeignSessions(int index); 62 int GetNumForeignSessions(int profile_index);
53 63
54 // Fills the sessions vector with the model associator's foreign session data. 64 // Fills the sessions vector with the model associator's foreign session data.
55 // Caller owns |sessions|, but not SyncedSessions objects within. 65 // Caller owns |sessions|, but not SyncedSessions objects within.
56 // Returns true if foreign sessions were found, false otherwise. 66 // Returns true if foreign sessions were found, false otherwise.
57 bool GetSessionData(int index, SyncedSessionVector* sessions); 67 bool GetSessionData(int profile_index, SyncedSessionVector* sessions);
58 68
59 // Compares a foreign session based on the first session window. 69 // Compares a foreign session based on the first session window.
60 // Returns true based on the comparison of the session windows. 70 // Returns true based on the comparison of the session windows.
61 bool CompareSyncedSessions(const sync_sessions::SyncedSession* lhs, 71 bool CompareSyncedSessions(const sync_sessions::SyncedSession* lhs,
62 const sync_sessions::SyncedSession* rhs); 72 const sync_sessions::SyncedSession* rhs);
63 73
64 // Sort a SyncedSession vector using our custom SyncedSession comparator. 74 // Sort a SyncedSession vector using our custom SyncedSession comparator.
65 void SortSyncedSessions(SyncedSessionVector* sessions); 75 void SortSyncedSessions(SyncedSessionVector* sessions);
66 76
67 // Compares two tab navigations base on the parameters we sync. 77 // Compares two tab navigations base on the parameters we sync.
68 // (Namely, we don't sync state or type mask) 78 // (Namely, we don't sync state or type mask)
69 bool NavigationEquals(const sessions::SerializedNavigationEntry& expected, 79 bool NavigationEquals(const sessions::SerializedNavigationEntry& expected,
70 const sessions::SerializedNavigationEntry& actual); 80 const sessions::SerializedNavigationEntry& actual);
71 81
72 // Verifies that two SessionWindows match. 82 // Verifies that two SessionWindows match.
73 // Returns: 83 // Returns:
74 // - true if all the following match: 84 // - true if all the following match:
75 // 1. number of SessionWindows, 85 // 1. number of SessionWindows,
76 // 2. number of tabs per SessionWindow, 86 // 2. number of tabs per SessionWindow,
77 // 3. number of tab navigations per tab, 87 // 3. number of tab navigations per tab,
78 // 4. actual tab navigations contents 88 // 4. actual tab navigations contents
79 // - false otherwise. 89 // - false otherwise.
80 bool WindowsMatch(const ScopedWindowMap& win1, const ScopedWindowMap& win2); 90 bool WindowsMatch(const ScopedWindowMap& win1, const ScopedWindowMap& win2);
81 bool WindowsMatch(const SessionWindowMap& win1, const ScopedWindowMap& win2); 91 bool WindowsMatch(const SessionWindowMap& win1, const ScopedWindowMap& win2);
82 92
83 // Retrieves the foreign sessions for a particular profile and compares them 93 // Retrieves the foreign sessions for a particular profile and compares them
84 // with a reference SessionWindow list. 94 // with a reference SessionWindow list.
85 // Returns true if the session windows of the foreign session matches the 95 // Returns true if the session windows of the foreign session matches the
86 // reference. 96 // reference.
87 bool CheckForeignSessionsAgainst( 97 bool CheckForeignSessionsAgainst(int profile_index,
88 int index, 98 const std::vector<ScopedWindowMap>& windows);
89 const std::vector<ScopedWindowMap>& windows);
90 99
91 // Open a single tab and block until the session model associator is aware 100 // Open a single tab in the browser at |browser_index| and block until the
92 // of it. Returns true upon success, false otherwise. 101 // session model associator is aware of it. Returns true upon success, false
93 bool OpenTab(int index, const GURL& url); 102 // otherwise.
103 bool OpenTab(int browser_index, const GURL& url);
Nicolas Zea 2017/02/24 20:25:29 I think window_index might be clearer than browser
Patrick Noland 2017/02/27 18:53:25 After discussing with sky, we think just "index" i
104
105 // See OpenTab, except that the tab is opened in position |tab_index|.
Nicolas Zea 2017/02/24 20:25:30 Comment about behavior if tab_index is greater tha
Patrick Noland 2017/02/27 18:53:25 Done.
106 bool OpenTabAtIndex(int browser_index, int tab_index, const GURL& url);
107
108 // Moves the tab in position |tab_index| in the TabStrip for browser at
109 // |from_browser_index| to the TabStrip for browser at |to_browser_index|.
110 void MoveTab(int from_browser_index, int to_browser_index, int tab_index);
111
112 // Navigate the active tab for browser in position |browser_index| to the given
113 // url.
114 bool NavigateTab(int browser_index, const GURL& url);
115
116 // Navigate the active tab for browser in position |browser_index| back by one;
117 // if this isn't possible, does nothing
118 void NavigateTabBack(int browser_index);
119
120 // Navigate the active tab for browser in position |browser_index| forward by
121 // one; if this isn't possible, does nothing
122 void NavigateTabForward(int browser_index);
94 123
95 // Open multiple tabs and block until the session model associator is aware 124 // Open multiple tabs and block until the session model associator is aware
96 // of all of them. Returns true on success, false on failure. 125 // of all of them. Returns true on success, false on failure.
97 bool OpenMultipleTabs(int index, const std::vector<GURL>& urls); 126 bool OpenMultipleTabs(int profile_index, const std::vector<GURL>& urls);
98 127
99 // Wait for a session change to propagate to the model associator. Will not 128 // Wait for a session change to propagate to the model associator. Will not
100 // return until each url in |urls| has been found. 129 // return until each url in |urls| has been found.
101 bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls); 130 bool WaitForTabsToLoad(int profile_index, const std::vector<GURL>& urls);
102 131
103 // Check if the session model associator's knows that the current open tab 132 // Check if the session model associator's knows that the current open tab
104 // has this url. 133 // has this url.
105 bool ModelAssociatorHasTabWithUrl(int index, const GURL& url); 134 bool ModelAssociatorHasTabWithUrl(int profile_index, const GURL& url);
106 135
107 // Stores a pointer to the local session for a given profile in |session|. 136 // Stores a pointer to the local session for a given profile in |session|.
108 // Returns true on success, false on failure. 137 // Returns true on success, false on failure.
109 bool GetLocalSession(int index, const sync_sessions::SyncedSession** session); 138 bool GetLocalSession(int profile_index,
139 const sync_sessions::SyncedSession** session);
110 140
111 // Deletes the foreign session with tag |session_tag| from the profile specified 141 // Deletes the foreign session with tag |session_tag| from the profile specified
112 // by |index|. This will affect all synced clients. 142 // by |index|. This will affect all synced clients.
113 // Note: We pass the session_tag in by value to ensure it's not a reference 143 // Note: We pass the session_tag in by value to ensure it's not a reference
114 // to the session tag within the SyncedSession we plan to delete. 144 // to the session tag within the SyncedSession we plan to delete.
115 void DeleteForeignSession(int index, std::string session_tag); 145 void DeleteForeignSession(int profile_index, std::string session_tag);
116 146
117 } // namespace sessions_helper 147 } // namespace sessions_helper
118 148
119 // Checker to block until the foreign sessions for a particular profile matches 149 // Checker to block until the foreign sessions for a particular profile matches
120 // the reference windows. 150 // the reference windows.
121 class ForeignSessionsMatchChecker : public MultiClientStatusChangeChecker { 151 class ForeignSessionsMatchChecker : public MultiClientStatusChangeChecker {
122 public: 152 public:
123 ForeignSessionsMatchChecker( 153 ForeignSessionsMatchChecker(
124 int index, 154 int profile_index,
125 const std::vector<sessions_helper::ScopedWindowMap>& windows); 155 const std::vector<sessions_helper::ScopedWindowMap>& windows);
126 156
127 // StatusChangeChecker implementation. 157 // StatusChangeChecker implementation.
128 bool IsExitConditionSatisfied() override; 158 bool IsExitConditionSatisfied() override;
129 std::string GetDebugMessage() const override; 159 std::string GetDebugMessage() const override;
130 160
131 private: 161 private:
132 int index_; 162 int profile_index_;
133 const std::vector<sessions_helper::ScopedWindowMap>& windows_; 163 const std::vector<sessions_helper::ScopedWindowMap>& windows_;
134 }; 164 };
135 165
166 // Checker to block until the FakeServer records a SessionsHierarchy identical
167 // to the SessionsHierarchy specified in the constructor.
168 class SessionHierarchyMatchChecker : public SingleClientStatusChangeChecker {
Nicolas Zea 2017/02/24 20:25:30 nit: prefer having this in its own file. It's conf
Patrick Noland 2017/02/27 18:53:26 Done.
169 public:
170 SessionHierarchyMatchChecker(
171 browser_sync::ProfileSyncService* service,
172 const fake_server::SessionsHierarchy& sessions_hierarchy,
Nicolas Zea 2017/02/24 20:25:30 nit: prefer having const inputs at start, and muta
Patrick Noland 2017/02/27 18:53:25 Done.
173 fake_server::FakeServer* fake_server);
174
175 // StatusChangeChecker implementation.
176 bool IsExitConditionSatisfied() override;
177 std::string GetDebugMessage() const override;
178
179 private:
180 const fake_server::SessionsHierarchy& sessions_hierarchy_;
Nicolas Zea 2017/02/24 20:25:29 Is sessions_hierarchy_ guaranteed to outlive this
Patrick Noland 2017/02/27 18:53:25 Done, although this requires an out of line copy c
181 fake_server::FakeServerVerifier verifier_;
182 };
183
136 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_ 184 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_SESSIONS_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698