Roll src/third_party/WebKit 605a979:06cb9e9 (svn 202556:202558)
[chromium-blink-merge.git] / components / upload_list / upload_list_unittest.cc
blob59c80cefbd3221067bf45ede7f6f9e2fae23156f
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
3 // found in the LICENSE file.
5 #include "components/upload_list/upload_list.h"
7 #include <string>
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/time/time.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 // Test that UploadList can parse a vector of log entry strings to a vector of
17 // UploadInfo objects. See the UploadList declaration for a description of the
18 // log entry string format.
19 TEST(UploadListTest, ParseLogEntries) {
20 const char kTestTime[] = "1234567890";
21 const char kTestID[] = "0123456789abcdef";
22 std::string test_entry = kTestTime;
23 test_entry += ",";
24 test_entry.append(kTestID, sizeof(kTestID));
26 scoped_refptr<UploadList> upload_list =
27 new UploadList(nullptr, base::FilePath(), nullptr);
29 // 1 entry.
30 std::vector<std::string> log_entries;
31 log_entries.push_back(test_entry);
32 upload_list->ParseLogEntries(log_entries);
33 EXPECT_EQ(1u, upload_list->uploads_.size());
34 double time_double = upload_list->uploads_[0].time.ToDoubleT();
35 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
36 EXPECT_STREQ(kTestID, upload_list->uploads_[0].id.c_str());
37 EXPECT_STREQ("", upload_list->uploads_[0].local_id.c_str());
39 // Add 3 more entries.
40 log_entries.push_back(test_entry);
41 log_entries.push_back(test_entry);
42 upload_list->ParseLogEntries(log_entries);
43 EXPECT_EQ(4u, upload_list->uploads_.size());
44 time_double = upload_list->uploads_[3].time.ToDoubleT();
45 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
46 EXPECT_STREQ(kTestID, upload_list->uploads_[3].id.c_str());
47 EXPECT_STREQ("", upload_list->uploads_[3].local_id.c_str());
50 TEST(UploadListTest, ParseLogEntriesWithLocalId) {
51 const char kTestTime[] = "1234567890";
52 const char kTestID[] = "0123456789abcdef";
53 const char kTestLocalID[] = "fedcba9876543210";
54 std::string test_entry = kTestTime;
55 test_entry += ",";
56 test_entry.append(kTestID, sizeof(kTestID));
57 test_entry += ",";
58 test_entry.append(kTestLocalID, sizeof(kTestLocalID));
60 scoped_refptr<UploadList> upload_list =
61 new UploadList(nullptr, base::FilePath(), nullptr);
63 // 1 entry.
64 std::vector<std::string> log_entries;
65 log_entries.push_back(test_entry);
66 upload_list->ParseLogEntries(log_entries);
67 EXPECT_EQ(1u, upload_list->uploads_.size());
68 double time_double = upload_list->uploads_[0].time.ToDoubleT();
69 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
70 EXPECT_STREQ(kTestID, upload_list->uploads_[0].id.c_str());
71 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[0].local_id.c_str());
73 // Add 3 more entries.
74 log_entries.push_back(test_entry);
75 log_entries.push_back(test_entry);
76 upload_list->ParseLogEntries(log_entries);
77 EXPECT_EQ(4u, upload_list->uploads_.size());
78 time_double = upload_list->uploads_[3].time.ToDoubleT();
79 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
80 EXPECT_STREQ(kTestID, upload_list->uploads_[3].id.c_str());
81 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[3].local_id.c_str());