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

Side by Side Diff: components/sync_sessions/favicon_cache_unittest.cc

Issue 2121513002: Replace string::find(prefix) == 0 pattern with base::StartsWith(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos Created 4 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_sessions/favicon_cache.h" 5 #include "components/sync_sessions/favicon_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "sync/api/attachments/attachment_id.h" 17 #include "sync/api/attachments/attachment_id.h"
17 #include "sync/api/sync_change_processor_wrapper_for_test.h" 18 #include "sync/api/sync_change_processor_wrapper_for_test.h"
18 #include "sync/api/sync_error_factory_mock.h" 19 #include "sync/api/sync_error_factory_mock.h"
19 #include "sync/api/time.h" 20 #include "sync/api/time.h"
20 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h" 21 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h"
21 #include "sync/protocol/favicon_image_specifics.pb.h" 22 #include "sync/protocol/favicon_image_specifics.pb.h"
22 #include "sync/protocol/favicon_tracking_specifics.pb.h" 23 #include "sync/protocol/favicon_tracking_specifics.pb.h"
23 #include "sync/protocol/sync.pb.h" 24 #include "sync/protocol/sync.pb.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 238 }
238 return testing::AssertionSuccess(); 239 return testing::AssertionSuccess();
239 } 240 }
240 241
241 // Helper to extract the favicon id embedded in the tag of a sync 242 // Helper to extract the favicon id embedded in the tag of a sync
242 // change. 243 // change.
243 int GetFaviconId(const syncer::SyncChange change) { 244 int GetFaviconId(const syncer::SyncChange change) {
244 std::string tag = syncer::SyncDataLocal(change.sync_data()).GetTag(); 245 std::string tag = syncer::SyncDataLocal(change.sync_data()).GetTag();
245 const std::string kPrefix = "http://bla.com/"; 246 const std::string kPrefix = "http://bla.com/";
246 const std::string kSuffix = ".ico"; 247 const std::string kSuffix = ".ico";
247 if (tag.find(kPrefix) != 0) 248 if (!base::StartsWith(tag, kPrefix, base::CompareCase::SENSITIVE))
248 return -1; 249 return -1;
249 std::string temp = tag.substr(kPrefix.length()); 250 std::string temp = tag.substr(kPrefix.length());
250 if (temp.rfind(kSuffix) <= 0) 251 if (temp.rfind(kSuffix) <= 0)
251 return -1; 252 return -1;
252 temp = temp.substr(0, temp.rfind(kSuffix)); 253 temp = temp.substr(0, temp.rfind(kSuffix));
253 int result = -1; 254 int result = -1;
254 if (!base::StringToInt(temp, &result)) 255 if (!base::StringToInt(temp, &result))
255 return -1; 256 return -1;
256 return result; 257 return result;
257 } 258 }
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD); 1928 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD);
1928 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING); 1929 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING);
1929 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4])); 1930 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4]));
1930 // Expire tracking for favicon[0]. 1931 // Expire tracking for favicon[0].
1931 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE); 1932 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE);
1932 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING); 1933 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING);
1933 EXPECT_EQ(0, GetFaviconId(changes[5])); 1934 EXPECT_EQ(0, GetFaviconId(changes[5]));
1934 } 1935 }
1935 1936
1936 } // namespace browser_sync 1937 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698