Roll src/third_party/WebKit 4652693:6e25bba (svn 187518:187521)
[chromium-blink-merge.git] / chrome / browser / upload_list_unittest.cc
blob9dfa9eb425a05f240d5fededa30301d8e4acefd0
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 <string>
7 #include "base/files/file_path.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/time/time.h"
11 #include "chrome/browser/upload_list.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 // Test that UploadList can parse a vector of log entry strings to a vector of
15 // UploadInfo objects. See the UploadList declaration for a description of the
16 // log entry string format.
17 TEST(UploadListTest, ParseLogEntries) {
18 const char kTestTime[] = "1234567890";
19 const char kTestID[] = "0123456789abcdef";
20 std::string test_entry = kTestTime;
21 test_entry += ",";
22 test_entry.append(kTestID, sizeof(kTestID));
24 scoped_refptr<UploadList> upload_list =
25 new UploadList(NULL, base::FilePath());
27 // 1 entry.
28 std::vector<std::string> log_entries;
29 log_entries.push_back(test_entry);
30 upload_list->ParseLogEntries(log_entries);
31 EXPECT_EQ(1u, upload_list->uploads_.size());
32 double time_double = upload_list->uploads_[0].time.ToDoubleT();
33 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
34 EXPECT_STREQ(kTestID, upload_list->uploads_[0].id.c_str());
35 EXPECT_STREQ("", upload_list->uploads_[0].local_id.c_str());
37 // Add 3 more entries.
38 log_entries.push_back(test_entry);
39 log_entries.push_back(test_entry);
40 upload_list->ParseLogEntries(log_entries);
41 EXPECT_EQ(4u, upload_list->uploads_.size());
42 time_double = upload_list->uploads_[3].time.ToDoubleT();
43 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
44 EXPECT_STREQ(kTestID, upload_list->uploads_[3].id.c_str());
45 EXPECT_STREQ("", upload_list->uploads_[3].local_id.c_str());
48 TEST(UploadListTest, ParseLogEntriesWithLocalId) {
49 const char kTestTime[] = "1234567890";
50 const char kTestID[] = "0123456789abcdef";
51 const char kTestLocalID[] = "fedcba9876543210";
52 std::string test_entry = kTestTime;
53 test_entry += ",";
54 test_entry.append(kTestID, sizeof(kTestID));
55 test_entry += ",";
56 test_entry.append(kTestLocalID, sizeof(kTestLocalID));
58 scoped_refptr<UploadList> upload_list =
59 new UploadList(NULL, base::FilePath());
61 // 1 entry.
62 std::vector<std::string> log_entries;
63 log_entries.push_back(test_entry);
64 upload_list->ParseLogEntries(log_entries);
65 EXPECT_EQ(1u, upload_list->uploads_.size());
66 double time_double = upload_list->uploads_[0].time.ToDoubleT();
67 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
68 EXPECT_STREQ(kTestID, upload_list->uploads_[0].id.c_str());
69 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[0].local_id.c_str());
71 // Add 3 more entries.
72 log_entries.push_back(test_entry);
73 log_entries.push_back(test_entry);
74 upload_list->ParseLogEntries(log_entries);
75 EXPECT_EQ(4u, upload_list->uploads_.size());
76 time_double = upload_list->uploads_[3].time.ToDoubleT();
77 EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str());
78 EXPECT_STREQ(kTestID, upload_list->uploads_[3].id.c_str());
79 EXPECT_STREQ(kTestLocalID, upload_list->uploads_[3].local_id.c_str());