Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / android / history_report / delta_file_commons_unittest.cc
blob11a6f207178fcbe94748327689872287030757e7
1 // Copyright 2015 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 "chrome/browser/android/history_report/delta_file_commons.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/history/core/browser/history_types.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using bookmarks::BookmarkModel;
14 namespace history_report {
16 class DeltaFileEntryWithDataTest : public testing::Test {
17 public:
18 DeltaFileEntryWithDataTest()
19 : entry_(),
20 data_(entry_) {}
21 ~DeltaFileEntryWithDataTest() override {}
23 protected:
24 void SetUp() override {}
26 DeltaFileEntry entry_;
27 DeltaFileEntryWithData data_;
29 private:
30 DISALLOW_COPY_AND_ASSIGN(DeltaFileEntryWithDataTest);
33 TEST_F(DeltaFileEntryWithDataTest, NotValid) {
34 EXPECT_FALSE(data_.Valid());
37 TEST_F(DeltaFileEntryWithDataTest, ValidDelEntry) {
38 DeltaFileEntry entry;
39 entry.set_type("del");
40 DeltaFileEntryWithData data(entry);
41 EXPECT_TRUE(data.Valid());
44 TEST_F(DeltaFileEntryWithDataTest, DelEntryWithData) {
45 DeltaFileEntry entry;
46 entry.set_type("del");
47 DeltaFileEntryWithData data(entry);
48 history::URLRow row;
49 row.set_hidden(false);
50 data.SetData(row);
51 EXPECT_TRUE(data.Valid());
52 // If deletion entry turns out to have data
53 // then it's an update entry instead.
54 EXPECT_EQ("add", data.Type());
57 TEST_F(DeltaFileEntryWithDataTest, Valid) {
58 history::URLRow row;
59 row.set_hidden(false);
60 data_.SetData(row);
61 EXPECT_TRUE(data_.Valid());
64 TEST_F(DeltaFileEntryWithDataTest, Hidden) {
65 history::URLRow row;
66 row.set_hidden(true);
67 data_.SetData(row);
68 EXPECT_FALSE(data_.Valid());
71 TEST_F(DeltaFileEntryWithDataTest, NoBookmarkScore) {
72 history::URLRow row;
73 row.set_hidden(false);
74 row.set_typed_count(2);
75 row.set_visit_count(3);
76 data_.SetData(row);
77 EXPECT_TRUE(data_.Valid());
78 EXPECT_EQ(5, data_.Score());
81 TEST_F(DeltaFileEntryWithDataTest, BookmarkScore) {
82 BookmarkModel::URLAndTitle bookmark;
83 history::URLRow row;
84 row.set_hidden(false);
85 row.set_typed_count(2);
86 row.set_visit_count(3);
87 data_.SetData(row);
88 data_.MarkAsBookmark(bookmark);
89 EXPECT_TRUE(data_.Valid());
90 EXPECT_EQ(18, data_.Score());
93 TEST_F(DeltaFileEntryWithDataTest, NoBookmarkEmptyTitle) {
94 history::URLRow row(GURL("http://www.host.org/path?query=param"));
95 row.set_title(base::UTF8ToUTF16(""));
96 row.set_hidden(false);
97 data_.SetData(row);
98 EXPECT_TRUE(data_.Valid());
99 EXPECT_EQ(base::UTF8ToUTF16("www.host.org"), data_.Title());
102 TEST_F(DeltaFileEntryWithDataTest, NoBookmarkNonEmptyTitle) {
103 history::URLRow row(GURL("http://host.org/path?query=param"));
104 row.set_title(base::UTF8ToUTF16("title"));
105 row.set_hidden(false);
106 data_.SetData(row);
107 EXPECT_TRUE(data_.Valid());
108 EXPECT_EQ(base::UTF8ToUTF16("title"), data_.Title());
111 TEST_F(DeltaFileEntryWithDataTest, BookmarkTitle) {
112 BookmarkModel::URLAndTitle bookmark;
113 bookmark.title = base::UTF8ToUTF16("bookmark_title");
114 history::URLRow row(GURL("http://host.org/path?query=param"));
115 row.set_title(base::UTF8ToUTF16("title"));
116 row.set_hidden(false);
117 data_.SetData(row);
118 data_.MarkAsBookmark(bookmark);
119 EXPECT_TRUE(data_.Valid());
120 EXPECT_EQ(base::UTF8ToUTF16("bookmark_title"), data_.Title());
123 TEST_F(DeltaFileEntryWithDataTest, TrimWWWPrefix) {
124 history::URLRow row(GURL("http://www.host.org/path?query=param"));
125 row.set_hidden(false);
126 data_.SetData(row);
127 EXPECT_TRUE(data_.Valid());
128 EXPECT_EQ("host", data_.IndexedUrl());
131 TEST_F(DeltaFileEntryWithDataTest, TrimWW2Prefix) {
132 history::URLRow row(GURL("http://ww2.host.org/path?query=param"));
133 row.set_hidden(false);
134 data_.SetData(row);
135 EXPECT_TRUE(data_.Valid());
136 EXPECT_EQ("host", data_.IndexedUrl());
139 TEST_F(DeltaFileEntryWithDataTest, TrimComSuffix) {
140 history::URLRow row(GURL("http://host.com/path?query=param"));
141 row.set_hidden(false);
142 data_.SetData(row);
143 EXPECT_TRUE(data_.Valid());
144 EXPECT_EQ("host", data_.IndexedUrl());
147 TEST_F(DeltaFileEntryWithDataTest, TrimCoUKSuffix) {
148 history::URLRow row(GURL("http://host.co.uk/path?query=param"));
149 row.set_hidden(false);
150 data_.SetData(row);
151 EXPECT_TRUE(data_.Valid());
152 EXPECT_EQ("host", data_.IndexedUrl());
155 TEST_F(DeltaFileEntryWithDataTest, TrimOrgKSuffix) {
156 history::URLRow row(GURL("http://host.org/path?query=param"));
157 row.set_hidden(false);
158 data_.SetData(row);
159 EXPECT_TRUE(data_.Valid());
160 EXPECT_EQ("host", data_.IndexedUrl());
163 TEST_F(DeltaFileEntryWithDataTest, TrimRegionalSuffix) {
164 history::URLRow row(GURL("http://host.waw.pl/path?query=param"));
165 row.set_hidden(false);
166 data_.SetData(row);
167 EXPECT_TRUE(data_.Valid());
168 EXPECT_EQ("host", data_.IndexedUrl());
171 TEST_F(DeltaFileEntryWithDataTest, TrimPrivateDomainSuffix) {
172 history::URLRow row(GURL("http://host.appspot.com/path?query=param"));
173 row.set_hidden(false);
174 data_.SetData(row);
175 EXPECT_TRUE(data_.Valid());
176 EXPECT_EQ("host.appspot", data_.IndexedUrl());
179 TEST_F(DeltaFileEntryWithDataTest, IdForShortUrl) {
180 std::string short_url("http://this.is.a.short.url.dot.com");
182 EXPECT_TRUE(DeltaFileEntryWithData::IsValidId(short_url));
184 DeltaFileEntry entry;
185 entry.set_url(short_url);
186 DeltaFileEntryWithData data(entry);
188 EXPECT_EQ(short_url, data.Id());
191 TEST_F(DeltaFileEntryWithDataTest, IdForLongUrl) {
193 std::stringstream url("http://domain.com/");
195 while (DeltaFileEntryWithData::IsValidId(url.str())) {
196 url << "a";
199 EXPECT_FALSE(DeltaFileEntryWithData::IsValidId(url.str()));
201 DeltaFileEntry entry;
202 entry.set_url(url.str());
203 DeltaFileEntryWithData data(entry);
205 EXPECT_NE(url.str(), data.Id());
206 EXPECT_TRUE(DeltaFileEntryWithData::IsValidId(data.Id()))
207 << data.Id() << " is not a valid ID";
209 std::stringstream expected_length_stream;
210 expected_length_stream << std::setfill('0') << std::setw(8)
211 << base::Uint64ToString(static_cast<uint64>(url.str().size()));
212 std::string length = data.Id().substr(0, 8);
213 EXPECT_EQ(expected_length_stream.str(), length);
215 std::string prefix = data.Id().substr(72);
216 std::string expected_prefix(url.str().substr(0, prefix.size()));
217 EXPECT_EQ(expected_prefix, prefix);
220 } // namespace history_report