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

Side by Side Diff: components/metrics/persisted_logs_unittest.cc

Issue 1304563003: Move //components/metrics/compression_utils into standalone component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 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
« no previous file with comments | « components/metrics/persisted_logs.cc ('k') | sync/internal_api/http_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/metrics/persisted_logs.h" 5 #include "components/metrics/persisted_logs.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/scoped_user_pref_update.h" 9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/sha1.h" 12 #include "base/sha1.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "components/metrics/compression_utils.h" 14 #include "components/compression/compression_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace metrics { 17 namespace metrics {
18 18
19 namespace { 19 namespace {
20 20
21 const char kTestPrefName[] = "TestPref"; 21 const char kTestPrefName[] = "TestPref";
22 const size_t kLogCountLimit = 3; 22 const size_t kLogCountLimit = 3;
23 const size_t kLogByteLimit = 1000; 23 const size_t kLogByteLimit = 1000;
24 24
25 // Compresses |log_data| and returns the result. 25 // Compresses |log_data| and returns the result.
26 std::string Compress(const std::string& log_data) { 26 std::string Compress(const std::string& log_data) {
27 std::string compressed_log_data; 27 std::string compressed_log_data;
28 EXPECT_TRUE(GzipCompress(log_data, &compressed_log_data)); 28 EXPECT_TRUE(compression::GzipCompress(log_data, &compressed_log_data));
29 return compressed_log_data; 29 return compressed_log_data;
30 } 30 }
31 31
32 // Generates and returns log data such that its size after compression is at 32 // Generates and returns log data such that its size after compression is at
33 // least |min_compressed_size|. 33 // least |min_compressed_size|.
34 std::string GenerateLogWithMinCompressedSize(size_t min_compressed_size) { 34 std::string GenerateLogWithMinCompressedSize(size_t min_compressed_size) {
35 // Since the size check is done against a compressed log, generate enough 35 // Since the size check is done against a compressed log, generate enough
36 // data that compresses to larger than |log_size|. 36 // data that compresses to larger than |log_size|.
37 std::string rand_bytes = base::RandBytesAsString(min_compressed_size); 37 std::string rand_bytes = base::RandBytesAsString(min_compressed_size);
38 while (Compress(rand_bytes).size() < min_compressed_size) 38 while (Compress(rand_bytes).size() < min_compressed_size)
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 TestPersistedLogs persisted_logs(&prefs_, kLogByteLimit); 278 TestPersistedLogs persisted_logs(&prefs_, kLogByteLimit);
279 persisted_logs.StoreLog(kFooText); 279 persisted_logs.StoreLog(kFooText);
280 persisted_logs.StageLog(); 280 persisted_logs.StageLog();
281 281
282 EXPECT_EQ(Compress(kFooText), persisted_logs.staged_log()); 282 EXPECT_EQ(Compress(kFooText), persisted_logs.staged_log());
283 EXPECT_EQ(foo_hash, persisted_logs.staged_log_hash()); 283 EXPECT_EQ(foo_hash, persisted_logs.staged_log_hash());
284 } 284 }
285 285
286 } // namespace metrics 286 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/persisted_logs.cc ('k') | sync/internal_api/http_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698