Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / safe_browsing / ping_manager_unittest.cc
blob95a8686dd7309784f17c1dec4f74da739cc51781
1 // Copyright (c) 2012 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 //
6 #include "base/logging.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/safe_browsing/ping_manager.h"
10 #include "google_apis/google_api_keys.h"
11 #include "net/base/escape.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using base::Time;
15 using base::TimeDelta;
17 static const char kUrlPrefix[] = "https://prefix.com/foo";
18 static const char kClient[] = "unittest";
19 static const char kAppVer[] = "1.0";
21 class SafeBrowsingPingManagerTest : public testing::Test {
22 protected:
23 std::string key_param_;
25 void SetUp() override {
26 std::string key = google_apis::GetAPIKey();
27 if (!key.empty()) {
28 key_param_ = base::StringPrintf(
29 "&key=%s",
30 net::EscapeQueryParamValue(key, true).c_str());
35 TEST_F(SafeBrowsingPingManagerTest, TestSafeBrowsingHitUrl) {
36 SafeBrowsingProtocolConfig config;
37 config.client_name = kClient;
38 config.url_prefix = kUrlPrefix;
39 SafeBrowsingPingManager pm(NULL, config);
41 pm.version_ = kAppVer;
43 GURL malicious_url("http://malicious.url.com");
44 GURL page_url("http://page.url.com");
45 GURL referrer_url("http://referrer.url.com");
46 EXPECT_EQ(
47 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
48 "pver=3.0" +
49 key_param_ +
50 "&ext=1&evts=malblhit&evtd=http%3A%2F%2Fmalicious.url.com%2F&"
51 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
52 "url.com%2F&evtb=1",
53 pm.SafeBrowsingHitUrl(malicious_url, page_url, referrer_url, true,
54 SB_THREAT_TYPE_URL_MALWARE, true).spec());
56 EXPECT_EQ(
57 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
58 "pver=3.0" +
59 key_param_ +
60 "&ext=1&evts=phishblhit&"
61 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
62 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
63 "url.com%2F&evtb=0",
64 pm.SafeBrowsingHitUrl(malicious_url, page_url, referrer_url, false,
65 SB_THREAT_TYPE_URL_PHISHING, true).spec());
67 EXPECT_EQ(
68 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
69 "pver=3.0" +
70 key_param_ +
71 "&ext=0&evts=binurlhit&"
72 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
73 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
74 "url.com%2F&evtb=0",
75 pm.SafeBrowsingHitUrl(malicious_url, page_url, referrer_url, false,
76 SB_THREAT_TYPE_BINARY_MALWARE_URL, false).spec());
78 EXPECT_EQ(
79 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
80 "pver=3.0" +
81 key_param_ +
82 "&ext=0&evts=phishcsdhit&"
83 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
84 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
85 "url.com%2F&evtb=0",
86 pm.SafeBrowsingHitUrl(malicious_url, page_url, referrer_url, false,
87 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
88 false).spec());
90 EXPECT_EQ(
91 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
92 "pver=3.0" +
93 key_param_ +
94 "&ext=0&evts=malcsdhit&"
95 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
96 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
97 "url.com%2F&evtb=1",
98 pm.SafeBrowsingHitUrl(malicious_url, page_url, referrer_url, true,
99 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL,
100 false).spec());
103 TEST_F(SafeBrowsingPingManagerTest, TestMalwareDetailsUrl) {
104 SafeBrowsingProtocolConfig config;
105 config.client_name = kClient;
106 config.url_prefix = kUrlPrefix;
107 SafeBrowsingPingManager pm(NULL, config);
109 pm.version_ = kAppVer;
110 EXPECT_EQ("https://prefix.com/foo/clientreport/malware?"
111 "client=unittest&appver=1.0&pver=1.0" + key_param_,
112 pm.MalwareDetailsUrl().spec());