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

Side by Side 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: Change functions signature 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #include "chrome/browser/safe_browsing/permission_reporter.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "chrome/common/safe_browsing/permission_report.pb.h"
9 #include "content/public/browser/permission_type.h"
10 #include "net/url_request/report_sender.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using content::PermissionType;
14
15 namespace safe_browsing {
16
17 namespace {
18 // URL to upload permission action reports.
19 static const char kPermissionActionReportingUploadUrl[] =
20 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/"
21 "permission-action";
22
23 static const char kDummyOrigin[] = "http://example.test/";
24 static const PermissionType kDummyPermission = PermissionType::GEOLOCATION;
25 static const PermissionAction kDummyAction = GRANTED;
26 static const PermissionReport::PermissionType kDummyPermissionReportPermission =
27 PermissionReport::GEOLOCATION;
28 static const PermissionReport::Action kDummyPermissionReportAction =
29 PermissionReport::GRANTED;
30
31 // A mock ReportSender that keeps track of the last report sent.
32 class MockReportSender : public net::ReportSender {
33 public:
34 MockReportSender() : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {}
35 ~MockReportSender() override {}
36
37 void Send(const GURL& report_uri, const std::string& report) override {
38 latest_report_uri_ = report_uri;
39 latest_report_ = report;
40 }
41
42 const GURL& latest_report_uri() { return latest_report_uri_; }
43
44 const std::string& latest_report() { return latest_report_; }
45
46 private:
47 GURL latest_report_uri_;
48 std::string latest_report_;
49
50 DISALLOW_COPY_AND_ASSIGN(MockReportSender);
51 };
52
53 } // namespace
54
55 class PermissionReporterTest : public ::testing::Test {
56 protected:
57 PermissionReporterTest()
58 : mock_report_sender_(new MockReportSender()),
59 permission_reporter_(
60 new PermissionReporter(base::WrapUnique(mock_report_sender_))) {}
61
62 // Owned by |permission_reporter_|.
63 MockReportSender* mock_report_sender_;
64
65 std::unique_ptr<PermissionReporter> permission_reporter_;
66 };
67
68 // Test that PermissionReporter::SendReport sends a serialized report string to
69 // SafeBrowsing CSD servers.
70 TEST_F(PermissionReporterTest, SendReport) {
71 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission,
72 kDummyAction);
73
74 PermissionReport permission_report;
75 ASSERT_TRUE(
76 permission_report.ParseFromString(mock_report_sender_->latest_report()));
77 EXPECT_EQ(kDummyPermissionReportPermission, permission_report.permission());
kcarattini 2016/06/14 21:17:27 I think you should test the BuildReport functional
raymes 2016/06/14 23:07:28 I said the opposite and asked Stefano to remove th
kcarattini 2016/06/14 23:51:08 I do not feel strongly :). Comments withdrawn.
78 EXPECT_EQ(kDummyPermissionReportAction, permission_report.action());
79 EXPECT_EQ(kDummyOrigin, permission_report.origin());
80
81 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl),
82 mock_report_sender_->latest_report_uri());
83 }
84
85 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698