cros: Remove default pinned apps trial.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / ping_manager_unittest.cc
blobc40fca38e3468fbc3789cb4376e16a6276e3919d
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 virtual void SetUp() {
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("https://prefix.com/foo/report?client=unittest&appver=1.0&"
47 "pver=2.2" + key_param_ +
48 "&evts=malblhit&evtd=http%3A%2F%2Fmalicious.url.com%2F&"
49 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
50 "url.com%2F&evtb=1",
51 pm.SafeBrowsingHitUrl(
52 malicious_url, page_url, referrer_url,
53 true, SB_THREAT_TYPE_URL_MALWARE).spec());
55 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
56 "pver=2.2" + key_param_ + "&evts=phishblhit&"
57 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
58 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
59 "url.com%2F&evtb=0",
60 pm.SafeBrowsingHitUrl(
61 malicious_url, page_url, referrer_url,
62 false, SB_THREAT_TYPE_URL_PHISHING).spec());
64 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
65 "pver=2.2" + key_param_ + "&evts=binurlhit&"
66 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
67 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
68 "url.com%2F&evtb=0",
69 pm.SafeBrowsingHitUrl(
70 malicious_url, page_url, referrer_url,
71 false, SB_THREAT_TYPE_BINARY_MALWARE_URL).spec());
73 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
74 "pver=2.2" + key_param_ + "&evts=binhashhit&"
75 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
76 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
77 "url.com%2F&evtb=0",
78 pm.SafeBrowsingHitUrl(
79 malicious_url, page_url, referrer_url,
80 false, SB_THREAT_TYPE_BINARY_MALWARE_HASH).spec());
82 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
83 "pver=2.2" + key_param_ + "&evts=phishcsdhit&"
84 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
85 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
86 "url.com%2F&evtb=0",
87 pm.SafeBrowsingHitUrl(
88 malicious_url, page_url, referrer_url,
89 false, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL).spec());
91 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
92 "pver=2.2" + key_param_ + "&evts=malcsdhit&"
93 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
94 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
95 "url.com%2F&evtb=1",
96 pm.SafeBrowsingHitUrl(
97 malicious_url, page_url, referrer_url,
98 true, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL).spec());
101 TEST_F(SafeBrowsingPingManagerTest, TestMalwareDetailsUrl) {
102 SafeBrowsingProtocolConfig config;
103 config.client_name = kClient;
104 config.url_prefix = kUrlPrefix;
105 SafeBrowsingPingManager pm(NULL, config);
107 pm.version_ = kAppVer;
108 EXPECT_EQ("https://prefix.com/foo/clientreport/malware?"
109 "client=unittest&appver=1.0&pver=1.0" + key_param_,
110 pm.MalwareDetailsUrl().spec());