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

Side by Side Diff: chrome/browser/ui/webui/browsing_history_handler_unittest.cc

Issue 2485253002: Remove unnecessary calls to GURL() (Closed)
Patch Set: Assert that StringPiece must always be canonicalized. Fix some constants. Created 4 years, 1 month 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/ui/webui/browsing_history_handler.h" 5 #include "chrome/browser/ui/webui/browsing_history_handler.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 // Returns true if |result| matches the test data given by |correct_result|, 67 // Returns true if |result| matches the test data given by |correct_result|,
68 // otherwise returns false. 68 // otherwise returns false.
69 bool ResultEquals( 69 bool ResultEquals(
70 const BrowsingHistoryHandler::HistoryEntry& result, 70 const BrowsingHistoryHandler::HistoryEntry& result,
71 const TestResult& correct_result) { 71 const TestResult& correct_result) {
72 base::Time correct_time = 72 base::Time correct_time =
73 baseline_time + base::TimeDelta::FromHours(correct_result.hour_offset); 73 baseline_time + base::TimeDelta::FromHours(correct_result.hour_offset);
74 74
75 return result.time == correct_time && result.url == GURL(correct_result.url); 75 return result.time == correct_time && result.url == correct_result.url;
76 } 76 }
77 77
78 void IgnoreBoolAndDoNothing(bool ignored_argument) {} 78 void IgnoreBoolAndDoNothing(bool ignored_argument) {}
79 79
80 class TestSyncService : public browser_sync::TestProfileSyncService { 80 class TestSyncService : public browser_sync::TestProfileSyncService {
81 public: 81 public:
82 explicit TestSyncService(Profile* profile) 82 explicit TestSyncService(Profile* profile)
83 : browser_sync::TestProfileSyncService( 83 : browser_sync::TestProfileSyncService(
84 CreateProfileSyncServiceParamsForTest(profile)), 84 CreateProfileSyncServiceParamsForTest(profile)),
85 sync_active_(true) {} 85 sync_active_(true) {}
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Fails on Android. http://crbug.com/2345 182 // Fails on Android. http://crbug.com/2345
183 #if defined(OS_ANDROID) 183 #if defined(OS_ANDROID)
184 #define MAYBE_MergeDuplicateResults DISABLED_MergeDuplicateResults 184 #define MAYBE_MergeDuplicateResults DISABLED_MergeDuplicateResults
185 #else 185 #else
186 #define MAYBE_MergeDuplicateResults MergeDuplicateResults 186 #define MAYBE_MergeDuplicateResults MergeDuplicateResults
187 #endif 187 #endif
188 TEST_F(BrowsingHistoryHandlerTest, MAYBE_MergeDuplicateResults) { 188 TEST_F(BrowsingHistoryHandlerTest, MAYBE_MergeDuplicateResults) {
189 { 189 {
190 // Basic test that duplicates on the same day are removed. 190 // Basic test that duplicates on the same day are removed.
191 TestResult test_data[] = { 191 TestResult test_data[] = {
192 { "http://google.com", 0 }, 192 { "http://google.com/", 0 },
193 { "http://google.de", 1 }, 193 { "http://google.de/", 1 },
194 { "http://google.com", 2 }, 194 { "http://google.com/", 2 },
195 { "http://google.com", 3 } // Most recent. 195 { "http://google.com/", 3 } // Most recent.
196 }; 196 };
197 std::vector<BrowsingHistoryHandler::HistoryEntry> results; 197 std::vector<BrowsingHistoryHandler::HistoryEntry> results;
198 AddQueryResults(test_data, arraysize(test_data), &results); 198 AddQueryResults(test_data, arraysize(test_data), &results);
199 BrowsingHistoryHandler::MergeDuplicateResults(&results); 199 BrowsingHistoryHandler::MergeDuplicateResults(&results);
200 200
201 ASSERT_EQ(2U, results.size()); 201 ASSERT_EQ(2U, results.size());
202 EXPECT_TRUE(ResultEquals(results[0], test_data[3])); 202 EXPECT_TRUE(ResultEquals(results[0], test_data[3]));
203 EXPECT_TRUE(ResultEquals(results[1], test_data[1])); 203 EXPECT_TRUE(ResultEquals(results[1], test_data[1]));
204 } 204 }
205 205
206 { 206 {
207 // Test that a duplicate URL on the next day is not removed. 207 // Test that a duplicate URL on the next day is not removed.
208 TestResult test_data[] = { 208 TestResult test_data[] = {
209 { "http://google.com", 0 }, 209 { "http://google.com/", 0 },
210 { "http://google.com", 23 }, 210 { "http://google.com/", 23 },
211 { "http://google.com", 24 }, // Most recent. 211 { "http://google.com/", 24 }, // Most recent.
212 }; 212 };
213 std::vector<BrowsingHistoryHandler::HistoryEntry> results; 213 std::vector<BrowsingHistoryHandler::HistoryEntry> results;
214 AddQueryResults(test_data, arraysize(test_data), &results); 214 AddQueryResults(test_data, arraysize(test_data), &results);
215 BrowsingHistoryHandler::MergeDuplicateResults(&results); 215 BrowsingHistoryHandler::MergeDuplicateResults(&results);
216 216
217 ASSERT_EQ(2U, results.size()); 217 ASSERT_EQ(2U, results.size());
218 EXPECT_TRUE(ResultEquals(results[0], test_data[2])); 218 EXPECT_TRUE(ResultEquals(results[0], test_data[2]));
219 EXPECT_TRUE(ResultEquals(results[1], test_data[1])); 219 EXPECT_TRUE(ResultEquals(results[1], test_data[1]));
220 } 220 }
221 221
222 { 222 {
223 // Test multiple duplicates across multiple days. 223 // Test multiple duplicates across multiple days.
224 TestResult test_data[] = { 224 TestResult test_data[] = {
225 // First day. 225 // First day.
226 { "http://google.de", 0 }, 226 { "http://google.de/", 0 },
227 { "http://google.com", 1 }, 227 { "http://google.com/", 1 },
228 { "http://google.de", 2 }, 228 { "http://google.de/", 2 },
229 { "http://google.com", 3 }, 229 { "http://google.com/", 3 },
230 230
231 // Second day. 231 // Second day.
232 { "http://google.de", 24 }, 232 { "http://google.de/", 24 },
233 { "http://google.com", 25 }, 233 { "http://google.com/", 25 },
234 { "http://google.de", 26 }, 234 { "http://google.de/", 26 },
235 { "http://google.com", 27 }, // Most recent. 235 { "http://google.com/", 27 }, // Most recent.
236 }; 236 };
237 std::vector<BrowsingHistoryHandler::HistoryEntry> results; 237 std::vector<BrowsingHistoryHandler::HistoryEntry> results;
238 AddQueryResults(test_data, arraysize(test_data), &results); 238 AddQueryResults(test_data, arraysize(test_data), &results);
239 BrowsingHistoryHandler::MergeDuplicateResults(&results); 239 BrowsingHistoryHandler::MergeDuplicateResults(&results);
240 240
241 ASSERT_EQ(4U, results.size()); 241 ASSERT_EQ(4U, results.size());
242 EXPECT_TRUE(ResultEquals(results[0], test_data[7])); 242 EXPECT_TRUE(ResultEquals(results[0], test_data[7]));
243 EXPECT_TRUE(ResultEquals(results[1], test_data[6])); 243 EXPECT_TRUE(ResultEquals(results[1], test_data[6]));
244 EXPECT_TRUE(ResultEquals(results[2], test_data[3])); 244 EXPECT_TRUE(ResultEquals(results[2], test_data[3]));
245 EXPECT_TRUE(ResultEquals(results[3], test_data[2])); 245 EXPECT_TRUE(ResultEquals(results[3], test_data[2]));
246 } 246 }
247 247
248 { 248 {
249 // Test that timestamps for duplicates are properly saved. 249 // Test that timestamps for duplicates are properly saved.
250 TestResult test_data[] = { 250 TestResult test_data[] = {
251 { "http://google.com", 0 }, 251 { "http://google.com/", 0 },
252 { "http://google.de", 1 }, 252 { "http://google.de/", 1 },
253 { "http://google.com", 2 }, 253 { "http://google.com/", 2 },
254 { "http://google.com", 3 } // Most recent. 254 { "http://google.com/", 3 } // Most recent.
255 }; 255 };
256 std::vector<BrowsingHistoryHandler::HistoryEntry> results; 256 std::vector<BrowsingHistoryHandler::HistoryEntry> results;
257 AddQueryResults(test_data, arraysize(test_data), &results); 257 AddQueryResults(test_data, arraysize(test_data), &results);
258 BrowsingHistoryHandler::MergeDuplicateResults(&results); 258 BrowsingHistoryHandler::MergeDuplicateResults(&results);
259 259
260 ASSERT_EQ(2U, results.size()); 260 ASSERT_EQ(2U, results.size());
261 EXPECT_TRUE(ResultEquals(results[0], test_data[3])); 261 EXPECT_TRUE(ResultEquals(results[0], test_data[3]));
262 EXPECT_TRUE(ResultEquals(results[1], test_data[1])); 262 EXPECT_TRUE(ResultEquals(results[1], test_data[1]));
263 EXPECT_EQ(3u, results[0].all_timestamps.size()); 263 EXPECT_EQ(3u, results[0].all_timestamps.size());
264 EXPECT_EQ(1u, results[1].all_timestamps.size()); 264 EXPECT_EQ(1u, results[1].all_timestamps.size());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 const base::DictionaryValue* first_entry; 361 const base::DictionaryValue* first_entry;
362 ASSERT_TRUE(arg2->GetDictionary(0, &first_entry)); 362 ASSERT_TRUE(arg2->GetDictionary(0, &first_entry));
363 363
364 base::string16 title; 364 base::string16 title;
365 ASSERT_TRUE(first_entry->GetString("title", &title)); 365 ASSERT_TRUE(first_entry->GetString("title", &title));
366 366
367 ASSERT_EQ(0u, title.find(base::ASCIIToUTF16("http://loooo"))); 367 ASSERT_EQ(0u, title.find(base::ASCIIToUTF16("http://loooo")));
368 EXPECT_EQ(300u, title.size()); 368 EXPECT_EQ(300u, title.size());
369 } 369 }
370 #endif 370 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | components/bookmarks/managed/managed_bookmarks_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698