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

Side by Side Diff: components/sync/test/fake_server/fake_server_verifier.cc

Issue 2751333007: [Sync] Try to fix race conditions in CookieJarMismatch. (Closed)
Patch Set: 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "components/sync/test/fake_server/fake_server_verifier.h" 5 #include "components/sync/test/fake_server/fake_server_verifier.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Ensure that all session tags match the first entity. Only one session is 140 // Ensure that all session tags match the first entity. Only one session is
141 // supported for verification at this time. 141 // supported for verification at this time.
142 if (it == sessions.begin()) 142 if (it == sessions.begin())
143 session_tag = session_specifics.session_tag(); 143 session_tag = session_specifics.session_tag();
144 else if (session_specifics.session_tag() != session_tag) 144 else if (session_specifics.session_tag() != session_tag)
145 return AssertionFailure() << "Multiple session tags found."; 145 return AssertionFailure() << "Multiple session tags found.";
146 146
147 if (session_specifics.has_header()) { 147 if (session_specifics.has_header()) {
148 session_header = session_specifics.header(); 148 session_header = session_specifics.header();
149 } else if (session_specifics.has_tab()) { 149 } else if (session_specifics.has_tab()) {
150 sync_pb::SessionTab tab = session_specifics.tab(); 150 const sync_pb::SessionTab& tab = session_specifics.tab();
151 tab_ids_to_window_ids[tab.tab_id()] = tab.window_id(); 151 const sync_pb::TabNavigation& nav =
152 tab_ids_to_urls[tab.tab_id()] = 152 tab.navigation(tab.current_navigation_index());
153 tab.navigation(tab.current_navigation_index()).virtual_url(); 153 // Only read from tabs that have a title on their current navigation
154 // entry. This the result of an oddity around the timing of sessions
155 // related changes. Sometimes when opening a new window, the first
156 // navigation will be committed before the title has been set. Then a
157 // subsequent commit will go through for that same navigation. Because
158 // this logic is used to ensure synchronization, we are going to exclude
159 // partially omitted navigations. The full navigation should typically be
160 // committed in full immediately after we fail a check because of this.
161 if (nav.has_title()) {
162 tab_ids_to_window_ids[tab.tab_id()] = tab.window_id();
163 tab_ids_to_urls[tab.tab_id()] = nav.virtual_url();
164 }
154 } 165 }
155 } 166 }
156 167
157 // Create a SessionsHierarchy from the cached SyncEntity data. This loop over 168 // Create a SessionsHierarchy from the cached SyncEntity data. This loop over
158 // the SessionHeader also ensures its data corresponds to the data stored in 169 // the SessionHeader also ensures its data corresponds to the data stored in
159 // each SessionTab. 170 // each SessionTab.
160 SessionsHierarchy actual_sessions; 171 SessionsHierarchy actual_sessions;
161 ::google::protobuf::RepeatedPtrField<sync_pb::SessionWindow>::const_iterator 172 ::google::protobuf::RepeatedPtrField<sync_pb::SessionWindow>::const_iterator
162 window_it; 173 window_it;
163 for (window_it = session_header.window().begin(); 174 for (window_it = session_header.window().begin();
164 window_it != session_header.window().end(); ++window_it) { 175 window_it != session_header.window().end(); ++window_it) {
165 sync_pb::SessionWindow window = *window_it; 176 sync_pb::SessionWindow window = *window_it;
166 std::multiset<std::string> tab_urls; 177 std::multiset<std::string> tab_urls;
167 ::google::protobuf::RepeatedField<int>::const_iterator tab_it; 178 ::google::protobuf::RepeatedField<int>::const_iterator tab_it;
168 for (tab_it = window.tab().begin(); tab_it != window.tab().end(); 179 for (tab_it = window.tab().begin(); tab_it != window.tab().end();
169 ++tab_it) { 180 ++tab_it) {
170 int tab_id = *tab_it; 181 int tab_id = *tab_it;
171 if (tab_ids_to_window_ids.find(tab_id) == tab_ids_to_window_ids.end()) { 182 if (tab_ids_to_window_ids.find(tab_id) == tab_ids_to_window_ids.end()) {
172 return AssertionFailure() << "Malformed data: Tab entity not found."; 183 return AssertionFailure() << "Malformed data: Tab entity not found.";
173 } 184 }
174 tab_urls.insert(tab_ids_to_urls[tab_id]); 185 tab_urls.insert(tab_ids_to_urls[tab_id]);
175 } 186 }
176 actual_sessions.AddWindow(tab_urls); 187 actual_sessions.AddWindow(tab_urls);
177 } 188 }
178 return VerifySessionsHierarchyEquality(expected_sessions, actual_sessions); 189 return VerifySessionsHierarchyEquality(expected_sessions, actual_sessions);
179 } 190 }
180 191
181 } // namespace fake_server 192 } // namespace fake_server
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698