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

Unified Diff: chrome/browser/history/browsing_history_service_unittest.cc

Issue 2704283002: Speculatively deflake BrowsingHistoryHandler::MergeDuplicateResults on Android. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/browsing_history_handler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/browsing_history_service_unittest.cc
diff --git a/chrome/browser/history/browsing_history_service_unittest.cc b/chrome/browser/history/browsing_history_service_unittest.cc
index 8473fd40b2ec42dc8deeccd4b15264f1c253c295..c4025860c24c9bbbd07d5406d9a01b2064ab12ec 100644
--- a/chrome/browser/history/browsing_history_service_unittest.cc
+++ b/chrome/browser/history/browsing_history_service_unittest.cc
@@ -19,20 +19,17 @@ struct TestResult {
int64_t hour_offset; // Visit time in hours past the baseline time.
};
-// Duplicates on the same day in the local timezone are removed, so set a
-// baseline time in local time.
-const base::Time baseline_time = base::Time::UnixEpoch().LocalMidnight();
-
// For each item in |results|, create a new Value representing the visit, and
// insert it into |list_value|.
void AddQueryResults(
+ const base::Time baseline_time,
TestResult* test_results,
int test_results_size,
std::vector<BrowsingHistoryService::HistoryEntry>* results) {
for (int i = 0; i < test_results_size; ++i) {
BrowsingHistoryService::HistoryEntry entry;
- entry.time = baseline_time +
- base::TimeDelta::FromHours(test_results[i].hour_offset);
+ entry.time =
+ baseline_time + base::TimeDelta::FromHours(test_results[i].hour_offset);
entry.url = GURL(test_results[i].url);
entry.all_timestamps.insert(entry.time.ToInternalValue());
results->push_back(entry);
@@ -41,9 +38,9 @@ void AddQueryResults(
// Returns true if |result| matches the test data given by |correct_result|,
// otherwise returns false.
-bool ResultEquals(
- const BrowsingHistoryService::HistoryEntry& result,
- const TestResult& correct_result) {
+bool ResultEquals(const base::Time baseline_time,
+ const BrowsingHistoryService::HistoryEntry& result,
+ const TestResult& correct_result) {
base::Time correct_time =
baseline_time + base::TimeDelta::FromHours(correct_result.hour_offset);
@@ -54,93 +51,93 @@ bool ResultEquals(
class BrowsingHistoryServiceTest : public ::testing::Test {
public:
- BrowsingHistoryServiceTest() {}
+ BrowsingHistoryServiceTest()
+ : baseline_time_(base::Time::UnixEpoch().LocalMidnight()) {}
~BrowsingHistoryServiceTest() override {}
+
+ protected:
+ // Duplicates on the same day in the local timezone are removed, so set a
+ // baseline time in local time.
+ base::Time baseline_time_;
};
// Tests that the MergeDuplicateResults method correctly removes duplicate
// visits to the same URL on the same day.
-// Fails on Android. http://crbug.com/2345
-#if defined(OS_ANDROID)
-#define MAYBE_MergeDuplicateResults DISABLED_MergeDuplicateResults
-#else
-#define MAYBE_MergeDuplicateResults MergeDuplicateResults
-#endif
-TEST_F(BrowsingHistoryServiceTest, MAYBE_MergeDuplicateResults) {
+TEST_F(BrowsingHistoryServiceTest, MergeDuplicateResults) {
{
// Basic test that duplicates on the same day are removed.
TestResult test_data[] = {
- { "http://google.com", 0 },
- { "http://google.de", 1 },
- { "http://google.com", 2 },
- { "http://google.com", 3 } // Most recent.
+ {"http://google.com", 0},
+ {"http://google.de", 1},
+ {"http://google.com", 2},
+ {"http://google.com", 3} // Most recent.
};
std::vector<BrowsingHistoryService::HistoryEntry> results;
- AddQueryResults(test_data, arraysize(test_data), &results);
+ AddQueryResults(baseline_time_, test_data, arraysize(test_data), &results);
BrowsingHistoryService::MergeDuplicateResults(&results);
ASSERT_EQ(2U, results.size());
- EXPECT_TRUE(ResultEquals(results[0], test_data[3]));
- EXPECT_TRUE(ResultEquals(results[1], test_data[1]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[0], test_data[3]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[1], test_data[1]));
}
{
// Test that a duplicate URL on the next day is not removed.
TestResult test_data[] = {
- { "http://google.com", 0 },
- { "http://google.com", 23 },
- { "http://google.com", 24 }, // Most recent.
+ {"http://google.com", 0},
+ {"http://google.com", 23},
+ {"http://google.com", 24}, // Most recent.
};
std::vector<BrowsingHistoryService::HistoryEntry> results;
- AddQueryResults(test_data, arraysize(test_data), &results);
+ AddQueryResults(baseline_time_, test_data, arraysize(test_data), &results);
BrowsingHistoryService::MergeDuplicateResults(&results);
ASSERT_EQ(2U, results.size());
- EXPECT_TRUE(ResultEquals(results[0], test_data[2]));
- EXPECT_TRUE(ResultEquals(results[1], test_data[1]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[0], test_data[2]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[1], test_data[1]));
}
{
// Test multiple duplicates across multiple days.
TestResult test_data[] = {
- // First day.
- { "http://google.de", 0 },
- { "http://google.com", 1 },
- { "http://google.de", 2 },
- { "http://google.com", 3 },
-
- // Second day.
- { "http://google.de", 24 },
- { "http://google.com", 25 },
- { "http://google.de", 26 },
- { "http://google.com", 27 }, // Most recent.
+ // First day.
+ {"http://google.de", 0},
+ {"http://google.com", 1},
+ {"http://google.de", 2},
+ {"http://google.com", 3},
+
+ // Second day.
+ {"http://google.de", 24},
+ {"http://google.com", 25},
+ {"http://google.de", 26},
+ {"http://google.com", 27}, // Most recent.
};
std::vector<BrowsingHistoryService::HistoryEntry> results;
- AddQueryResults(test_data, arraysize(test_data), &results);
+ AddQueryResults(baseline_time_, test_data, arraysize(test_data), &results);
BrowsingHistoryService::MergeDuplicateResults(&results);
ASSERT_EQ(4U, results.size());
- EXPECT_TRUE(ResultEquals(results[0], test_data[7]));
- EXPECT_TRUE(ResultEquals(results[1], test_data[6]));
- EXPECT_TRUE(ResultEquals(results[2], test_data[3]));
- EXPECT_TRUE(ResultEquals(results[3], test_data[2]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[0], test_data[7]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[1], test_data[6]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[2], test_data[3]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[3], test_data[2]));
}
{
// Test that timestamps for duplicates are properly saved.
TestResult test_data[] = {
- { "http://google.com", 0 },
- { "http://google.de", 1 },
- { "http://google.com", 2 },
- { "http://google.com", 3 } // Most recent.
+ {"http://google.com", 0},
+ {"http://google.de", 1},
+ {"http://google.com", 2},
+ {"http://google.com", 3} // Most recent.
};
std::vector<BrowsingHistoryService::HistoryEntry> results;
- AddQueryResults(test_data, arraysize(test_data), &results);
+ AddQueryResults(baseline_time_, test_data, arraysize(test_data), &results);
BrowsingHistoryService::MergeDuplicateResults(&results);
ASSERT_EQ(2U, results.size());
- EXPECT_TRUE(ResultEquals(results[0], test_data[3]));
- EXPECT_TRUE(ResultEquals(results[1], test_data[1]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[0], test_data[3]));
+ EXPECT_TRUE(ResultEquals(baseline_time_, results[1], test_data[1]));
EXPECT_EQ(3u, results[0].all_timestamps.size());
EXPECT_EQ(1u, results[1].all_timestamps.size());
}
« no previous file with comments | « no previous file | chrome/browser/ui/webui/browsing_history_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698