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

Side by Side Diff: components/previews/previews_data_savings_unittest.cc

Issue 2257533003: Adding a previews object, PreviewsDataSavings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bengr comment Created 4 years, 3 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 | « components/previews/previews_data_savings.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 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 "components/previews/previews_data_savings.h"
6
7 #include <stdint.h>
8
9 #include <memory>
10 #include <string>
11
12 #include "components/data_reduction_proxy/core/common/data_savings_recorder.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace previews {
16
17 namespace {
18
19 class TestDataSavingsRecorder
20 : public data_reduction_proxy::DataSavingsRecorder {
21 public:
22 TestDataSavingsRecorder()
23 : data_saver_enabled_(false), data_used_(0), original_size_(0) {}
24 ~TestDataSavingsRecorder() {}
25
26 // data_reduction_proxy::DataSavingsRecorder implementation:
27 bool UpdateDataSavings(const std::string& host,
28 int64_t data_used,
29 int64_t original_size) override {
30 if (!data_saver_enabled_) {
31 return false;
32 }
33 last_host_ = host;
34 data_used_ += data_used;
35 original_size_ += original_size;
36 return true;
37 }
38
39 void set_data_saver_enabled(bool data_saver_enabled) {
40 data_saver_enabled_ = data_saver_enabled;
41 }
42
43 std::string last_host() const { return last_host_; }
44
45 int64_t data_used() const { return data_used_; }
46
47 int64_t original_size() const { return original_size_; }
48
49 private:
50 bool data_saver_enabled_;
51 std::string last_host_;
52 int64_t data_used_;
53 int64_t original_size_;
54 };
55
56 } // namespace
57
58 class PreviewsDataSavingsTest : public testing::Test {
59 public:
60 PreviewsDataSavingsTest()
61 : test_data_savings_recorder_(new TestDataSavingsRecorder()),
62 data_savings_(
63 new PreviewsDataSavings(test_data_savings_recorder_.get())) {}
64 ~PreviewsDataSavingsTest() override {}
65
66 PreviewsDataSavings* data_savings() const { return data_savings_.get(); }
67
68 TestDataSavingsRecorder* test_data_savings_recorder() const {
69 return test_data_savings_recorder_.get();
70 }
71
72 private:
73 std::unique_ptr<TestDataSavingsRecorder> test_data_savings_recorder_;
74 std::unique_ptr<PreviewsDataSavings> data_savings_;
75 };
76
77 TEST_F(PreviewsDataSavingsTest, RecordDataSavings) {
78 int64_t original_size = 200;
79 int64_t data_used = 100;
80 std::string host = "host";
81
82 EXPECT_EQ(0, test_data_savings_recorder()->data_used());
83 EXPECT_EQ(0, test_data_savings_recorder()->original_size());
84 test_data_savings_recorder()->set_data_saver_enabled(false);
85
86 data_savings()->RecordDataSavings(host, data_used, original_size);
87
88 EXPECT_EQ(0, test_data_savings_recorder()->data_used());
89 EXPECT_EQ(0, test_data_savings_recorder()->original_size());
90 EXPECT_EQ(std::string(), test_data_savings_recorder()->last_host());
91 test_data_savings_recorder()->set_data_saver_enabled(true);
92
93 data_savings()->RecordDataSavings(host, data_used, original_size);
94
95 EXPECT_EQ(data_used, test_data_savings_recorder()->data_used());
96 EXPECT_EQ(original_size, test_data_savings_recorder()->original_size());
97 EXPECT_EQ(host, test_data_savings_recorder()->last_host());
98 }
99
100 } // namespace previews
OLDNEW
« no previous file with comments | « components/previews/previews_data_savings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698