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

Side by Side Diff: net/reporting/reporting_service_unittest.cc

Issue 2770443002: Reporting: Wrap context in service. (Closed)
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « net/reporting/reporting_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "net/reporting/reporting_service.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/memory/ptr_util.h"
11 #include "base/time/tick_clock.h"
12 #include "base/values.h"
13 #include "net/reporting/reporting_cache.h"
14 #include "net/reporting/reporting_context.h"
15 #include "net/reporting/reporting_delegate.h"
16 #include "net/reporting/reporting_policy.h"
17 #include "net/reporting/reporting_report.h"
18 #include "net/reporting/reporting_service.h"
19 #include "net/reporting/reporting_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace net {
23 namespace {
24
25 class ReportingServiceTest : public ::testing::Test {
26 protected:
27 const GURL kUrl_ = GURL("https://origin/path");
28 const url::Origin kOrigin_ = url::Origin(kUrl_);
29 const GURL kEndpoint_ = GURL("https://endpoint/");
30 const std::string kGroup_ = "group";
31 const std::string kType_ = "type";
32
33 ReportingServiceTest()
34 : context_(new TestReportingContext(ReportingPolicy())),
35 service_(
36 ReportingService::CreateForTesting(base::WrapUnique(context_))) {}
37
38 TestReportingContext* context() { return context_; }
39 ReportingService* service() { return service_.get(); }
40
41 private:
42 TestReportingContext* context_;
43 std::unique_ptr<ReportingService> service_;
44 };
45
46 TEST_F(ReportingServiceTest, QueueReport) {
47 service()->QueueReport(kUrl_, kGroup_, kType_,
48 base::MakeUnique<base::DictionaryValue>());
49
50 std::vector<const ReportingReport*> reports;
51 context()->cache()->GetReports(&reports);
52 ASSERT_EQ(1u, reports.size());
53 EXPECT_EQ(kUrl_, reports[0]->url);
54 EXPECT_EQ(kGroup_, reports[0]->group);
55 EXPECT_EQ(kType_, reports[0]->type);
56 }
57
58 TEST_F(ReportingServiceTest, ProcessHeader) {
59 service()->ProcessHeader(kUrl_, "{\"url\":\"" + kEndpoint_.spec() +
60 "\","
61 "\"group\":\"" +
62 kGroup_ +
63 "\","
64 "\"max-age\":86400}");
65
66 const ReportingClient* client =
67 FindClientInCache(context()->cache(), kOrigin_, kEndpoint_);
68 ASSERT_TRUE(client != nullptr);
69 EXPECT_EQ(kOrigin_, client->origin);
70 EXPECT_EQ(kEndpoint_, client->endpoint);
71 EXPECT_EQ(ReportingClient::Subdomains::EXCLUDE, client->subdomains);
72 EXPECT_EQ(kGroup_, client->group);
73 EXPECT_EQ(context()->tick_clock()->NowTicks() + base::TimeDelta::FromDays(1),
74 client->expires);
75 }
76
77 } // namespace
78 } // namespace net
OLDNEW
« no previous file with comments | « net/reporting/reporting_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698