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

Side by Side Diff: chrome/browser/safe_browsing/permission_reporter_unittest.cc

Issue 2075523002: Add SourceUI field to permission report (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/permission_reporter.h" 5 #include "chrome/browser/safe_browsing/permission_reporter.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "chrome/common/safe_browsing/permission_report.pb.h" 8 #include "chrome/common/safe_browsing/permission_report.pb.h"
9 #include "content/public/browser/permission_type.h" 9 #include "content/public/browser/permission_type.h"
10 #include "net/url_request/report_sender.h" 10 #include "net/url_request/report_sender.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 using content::PermissionType; 13 using content::PermissionType;
14 14
15 namespace safe_browsing { 15 namespace safe_browsing {
16 16
17 namespace { 17 namespace {
18 // URL to upload permission action reports. 18 // URL to upload permission action reports.
19 static const char kPermissionActionReportingUploadUrl[] = 19 static const char kPermissionActionReportingUploadUrl[] =
20 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" 20 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/"
21 "permission-action"; 21 "permission-action";
22 22
23 static const char kDummyOrigin[] = "http://example.test/"; 23 static const char kDummyOrigin[] = "http://example.test/";
24 static const PermissionType kDummyPermission = PermissionType::GEOLOCATION; 24 static const PermissionType kDummyPermission = PermissionType::GEOLOCATION;
25 static const PermissionAction kDummyAction = GRANTED; 25 static const PermissionAction kDummyAction = GRANTED;
26 static const SourceUI kDummySourceUI = PROMPT;
26 static const PermissionReport::PermissionType kDummyPermissionReportPermission = 27 static const PermissionReport::PermissionType kDummyPermissionReportPermission =
27 PermissionReport::GEOLOCATION; 28 PermissionReport::GEOLOCATION;
28 static const PermissionReport::Action kDummyPermissionReportAction = 29 static const PermissionReport::Action kDummyPermissionReportAction =
29 PermissionReport::GRANTED; 30 PermissionReport::GRANTED;
31 static const PermissionReport::SourceUI kDummyPermissionReportSourceUI =
32 PermissionReport::PROMPT;
30 33
31 // A mock ReportSender that keeps track of the last report sent. 34 // A mock ReportSender that keeps track of the last report sent.
32 class MockReportSender : public net::ReportSender { 35 class MockReportSender : public net::ReportSender {
33 public: 36 public:
34 MockReportSender() : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {} 37 MockReportSender() : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {}
35 ~MockReportSender() override {} 38 ~MockReportSender() override {}
36 39
37 void Send(const GURL& report_uri, const std::string& report) override { 40 void Send(const GURL& report_uri, const std::string& report) override {
38 latest_report_uri_ = report_uri; 41 latest_report_uri_ = report_uri;
39 latest_report_ = report; 42 latest_report_ = report;
(...skipping 22 matching lines...) Expand all
62 // Owned by |permission_reporter_|. 65 // Owned by |permission_reporter_|.
63 MockReportSender* mock_report_sender_; 66 MockReportSender* mock_report_sender_;
64 67
65 std::unique_ptr<PermissionReporter> permission_reporter_; 68 std::unique_ptr<PermissionReporter> permission_reporter_;
66 }; 69 };
67 70
68 // Test that PermissionReporter::SendReport sends a serialized report string to 71 // Test that PermissionReporter::SendReport sends a serialized report string to
69 // SafeBrowsing CSD servers. 72 // SafeBrowsing CSD servers.
70 TEST_F(PermissionReporterTest, SendReport) { 73 TEST_F(PermissionReporterTest, SendReport) {
71 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission, 74 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission,
72 kDummyAction); 75 kDummyAction, kDummySourceUI);
73 76
74 PermissionReport permission_report; 77 PermissionReport permission_report;
75 ASSERT_TRUE( 78 ASSERT_TRUE(
76 permission_report.ParseFromString(mock_report_sender_->latest_report())); 79 permission_report.ParseFromString(mock_report_sender_->latest_report()));
77 EXPECT_EQ(kDummyPermissionReportPermission, permission_report.permission()); 80 EXPECT_EQ(kDummyPermissionReportPermission, permission_report.permission());
78 EXPECT_EQ(kDummyPermissionReportAction, permission_report.action()); 81 EXPECT_EQ(kDummyPermissionReportAction, permission_report.action());
82 EXPECT_EQ(kDummyPermissionReportSourceUI, permission_report.source_ui());
79 EXPECT_EQ(kDummyOrigin, permission_report.origin()); 83 EXPECT_EQ(kDummyOrigin, permission_report.origin());
80 84
81 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl), 85 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl),
82 mock_report_sender_->latest_report_uri()); 86 mock_report_sender_->latest_report_uri());
83 } 87 }
84 88
85 } // namespace safe_browsing 89 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698