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

Unified Diff: chrome/browser/safe_browsing/permission_reporter_unittest.cc

Issue 2035753004: Add implementation of PermissionReporter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-certificate-report-sender
Patch Set: Remove static marker in anon namespace Created 4 years, 6 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 | « chrome/browser/safe_browsing/permission_reporter.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/permission_reporter_unittest.cc
diff --git a/chrome/browser/safe_browsing/permission_reporter_unittest.cc b/chrome/browser/safe_browsing/permission_reporter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5c96a5fc37e37c9c5b44c8c97fb6f7727f8997f9
--- /dev/null
+++ b/chrome/browser/safe_browsing/permission_reporter_unittest.cc
@@ -0,0 +1,85 @@
+// 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 "chrome/browser/safe_browsing/permission_reporter.h"
+
+#include "base/memory/ptr_util.h"
+#include "chrome/common/safe_browsing/permission_report.pb.h"
+#include "content/public/browser/permission_type.h"
+#include "net/url_request/report_sender.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using content::PermissionType;
+
+namespace safe_browsing {
+
+namespace {
+// URL to upload permission action reports.
+const char kPermissionActionReportingUploadUrl[] =
+ "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/"
+ "permission-action";
+
+const char kDummyOrigin[] = "http://example.test/";
+const PermissionType kDummyPermission = PermissionType::GEOLOCATION;
+const PermissionAction kDummyAction = GRANTED;
+const PermissionReport::PermissionType kDummyPermissionReportPermission =
+ PermissionReport::GEOLOCATION;
+const PermissionReport::Action kDummyPermissionReportAction =
+ PermissionReport::GRANTED;
+
+// A mock ReportSender that keeps track of the last report sent.
+class MockReportSender : public net::ReportSender {
+ public:
+ MockReportSender() : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {}
+ ~MockReportSender() override {}
+
+ void Send(const GURL& report_uri, const std::string& report) override {
+ latest_report_uri_ = report_uri;
+ latest_report_ = report;
+ }
+
+ const GURL& latest_report_uri() { return latest_report_uri_; }
+
+ const std::string& latest_report() { return latest_report_; }
+
+ private:
+ GURL latest_report_uri_;
+ std::string latest_report_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockReportSender);
+};
+
+} // namespace
+
+class PermissionReporterTest : public ::testing::Test {
+ protected:
+ PermissionReporterTest()
+ : mock_report_sender_(new MockReportSender()),
+ permission_reporter_(
+ new PermissionReporter(base::WrapUnique(mock_report_sender_))) {}
+
+ // Owned by |permission_reporter_|.
+ MockReportSender* mock_report_sender_;
+
+ std::unique_ptr<PermissionReporter> permission_reporter_;
+};
+
+// Test that PermissionReporter::SendReport sends a serialized report string to
+// SafeBrowsing CSD servers.
+TEST_F(PermissionReporterTest, SendReport) {
+ permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission,
+ kDummyAction);
+
+ PermissionReport permission_report;
+ ASSERT_TRUE(
+ permission_report.ParseFromString(mock_report_sender_->latest_report()));
+ EXPECT_EQ(kDummyPermissionReportPermission, permission_report.permission());
+ EXPECT_EQ(kDummyPermissionReportAction, permission_report.action());
+ EXPECT_EQ(kDummyOrigin, permission_report.origin());
+
+ EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl),
+ mock_report_sender_->latest_report_uri());
+}
+
+} // namespace safe_browsing
« no previous file with comments | « chrome/browser/safe_browsing/permission_reporter.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698