Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 kDummyProtobufPermission = | |
| 27 PermissionReport::GEOLOCATION; | |
| 28 static const PermissionReport::Action kDummyProtobufAction = | |
| 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_))) {} | |
|
raymes
2016/06/09 06:03:47
What I mean is, can we replace mock_report_sender_
stefanocs
2016/06/09 06:41:29
I was trying to do this earlier but I figured the
raymes
2016/06/09 06:43:41
Oh sorry, I understand now. This seems ok to me. S
stefanocs
2016/06/09 07:50:45
Acknowledged.
| |
| 61 | |
|
raymes
2016/06/09 06:43:41
Add a comment about the ownership of this:
// Owne
stefanocs
2016/06/09 07:50:45
Done.
| |
| 62 MockReportSender* mock_report_sender_; | |
| 63 | |
| 64 std::unique_ptr<PermissionReporter> permission_reporter_; | |
| 65 }; | |
| 66 | |
| 67 // Test that PermissionReporter::SendReport sends a serialized report string to | |
| 68 // SafeBrowsing CSD servers. | |
| 69 TEST_F(PermissionReporterTest, SendReport) { | |
| 70 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission, | |
| 71 kDummyAction); | |
| 72 | |
| 73 PermissionReport permission_report; | |
| 74 ASSERT_TRUE( | |
| 75 permission_report.ParseFromString(mock_report_sender_->latest_report())); | |
| 76 EXPECT_EQ(kDummyProtobufPermission, permission_report.permission()); | |
| 77 EXPECT_EQ(kDummyProtobufAction, permission_report.action()); | |
| 78 EXPECT_EQ(kDummyOrigin, permission_report.origin()); | |
| 79 | |
| 80 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl), | |
| 81 mock_report_sender_->latest_report_uri()); | |
| 82 } | |
| 83 | |
| 84 } // namespace safe_browsing | |
| OLD | NEW |