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

Unified Diff: components/reporting/core/browser/reporting_cache_unittest.cc

Issue 2249213002: [OBSOLETE] Reporting: Initial implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ProfileImplIOData Created 4 years, 2 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
Index: components/reporting/core/browser/reporting_cache_unittest.cc
diff --git a/components/reporting/core/browser/reporting_cache_unittest.cc b/components/reporting/core/browser/reporting_cache_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5868fe9520e67dc8ac5149159e2d46832a412482
--- /dev/null
+++ b/components/reporting/core/browser/reporting_cache_unittest.cc
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/reporting/core/browser/reporting_cache.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/time/time.h"
+#include "components/reporting/core/browser/reporting_endpoint.h"
+#include "components/reporting/core/browser/reporting_report.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace reporting {
+namespace {
+
+class ReportingCacheTest : public ::testing::Test {
+ protected:
+ std::unique_ptr<ReportingEndpoint> MakeEndpoint(const GURL& url) {
+ return base::MakeUnique<ReportingEndpoint>(url, backoff_policy_,
+ base::TimeTicks::Now());
+ }
+
+ std::unique_ptr<ReportingReport> MakeReport(const std::string& type) {
+ auto report = base::MakeUnique<ReportingReport>();
+ report->type = type;
+ return report;
+ }
+
+ net::BackoffEntry::Policy backoff_policy_;
+ ReportingCache cache_;
+};
+
+TEST_F(ReportingCacheTest, Endpoints) {
+ GURL url("https://example.com/");
+
+ EXPECT_TRUE(cache_.GetEndpoints().empty());
+
+ cache_.InsertEndpoint(MakeEndpoint(url));
+
+ const std::unique_ptr<ReportingEndpoint>* endpoint = cache_.GetEndpoint(url);
+ EXPECT_TRUE(endpoint != nullptr);
+ EXPECT_TRUE(*endpoint != nullptr);
+ EXPECT_EQ((*endpoint)->url, url);
+
+ auto& endpoint_map = cache_.GetEndpoints();
+ EXPECT_EQ(1u, endpoint_map.size());
+ EXPECT_EQ(1u, endpoint_map.count(url));
+ auto endpoint_it = endpoint_map.find(url);
+ EXPECT_TRUE(endpoint_it != endpoint_map.end());
+ EXPECT_TRUE(endpoint_it->second == *endpoint);
+
+ cache_.RemoveEndpoint(*endpoint);
+
+ EXPECT_TRUE(cache_.GetEndpoint(url) == nullptr);
+
+ EXPECT_TRUE(cache_.GetEndpoints().empty());
+ EXPECT_EQ(0u, cache_.GetEndpoints().count(url));
+}
+
+TEST_F(ReportingCacheTest, Reports) {
+ EXPECT_TRUE(cache_.GetReports().empty());
+
+ cache_.EnqueueReport(MakeReport("test"));
+ auto& report_set = cache_.GetReports();
+ EXPECT_EQ(1u, report_set.size());
+ auto report_it = report_set.begin();
+ EXPECT_TRUE(report_it != report_set.end());
+ EXPECT_TRUE(*report_it);
+ EXPECT_EQ("test", (*report_it)->type);
+
+ cache_.DequeueReport(*report_it);
+ EXPECT_TRUE(cache_.GetReports().empty());
+}
+
+TEST_F(ReportingCacheTest, Clear) {
+ GURL url("https://example.com/");
+
+ cache_.InsertEndpoint(MakeEndpoint(url));
+ cache_.EnqueueReport(MakeReport("test"));
+
+ cache_.Clear();
+ EXPECT_TRUE(cache_.GetEndpoints().empty());
+ EXPECT_TRUE(cache_.GetReports().empty());
+}
+
+} // namespace
+} // namespace reporting

Powered by Google App Engine
This is Rietveld 408576698