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

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: rebase and design change. 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
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 void UpdateDataSavings(const std::string& host,
28 int64_t data_used,
29 int64_t original_size) override {
30 last_host_ = host;
31 data_used_ += data_used;
32 original_size_ += original_size;
33 }
34 bool ShouldRecordDataSavings() const override { return data_saver_enabled_; }
35
36 void set_data_saver_enabled(bool data_saver_enabled) {
37 data_saver_enabled_ = data_saver_enabled;
38 }
39
40 std::string last_host() const { return last_host_; }
41
42 int64_t data_used() const { return data_used_; }
43
44 int64_t original_size() const { return original_size_; }
45
46 private:
47 bool data_saver_enabled_;
48 std::string last_host_;
49 int64_t data_used_;
50 int64_t original_size_;
51 };
52
53 } // namespace
54
55 class PreviewsDataSavingsTest : public testing::Test {
56 public:
57 PreviewsDataSavingsTest()
58 : test_data_savings_recorder_(new TestDataSavingsRecorder()),
59 data_savings_(
60 new PreviewsDataSavings(test_data_savings_recorder_.get())) {}
61 ~PreviewsDataSavingsTest() override {}
62
63 PreviewsDataSavings* data_savings() const { return data_savings_.get(); }
64
65 TestDataSavingsRecorder* test_data_savings_recorder() const {
66 return test_data_savings_recorder_.get();
67 }
68
69 private:
70 std::unique_ptr<TestDataSavingsRecorder> test_data_savings_recorder_;
71 std::unique_ptr<PreviewsDataSavings> data_savings_;
72 };
73
74 TEST_F(PreviewsDataSavingsTest, RecordDataSavings) {
75 int64_t original_size = 200;
76 int64_t data_used = 100;
77 std::string host = "host";
78
79 EXPECT_EQ(0, test_data_savings_recorder()->data_used());
80 EXPECT_EQ(0, test_data_savings_recorder()->original_size());
81 test_data_savings_recorder()->set_data_saver_enabled(false);
82
83 data_savings()->RecordDataSavings(host, data_used, original_size);
84
85 EXPECT_EQ(0, test_data_savings_recorder()->data_used());
86 EXPECT_EQ(0, test_data_savings_recorder()->original_size());
87 EXPECT_EQ(std::string(), test_data_savings_recorder()->last_host());
88 test_data_savings_recorder()->set_data_saver_enabled(true);
89
90 data_savings()->RecordDataSavings(host, data_used, original_size);
91
92 EXPECT_EQ(data_used, test_data_savings_recorder()->data_used());
93 EXPECT_EQ(original_size, test_data_savings_recorder()->original_size());
94 EXPECT_EQ(host, test_data_savings_recorder()->last_host());
95 }
96
97 } // namespace previews
OLDNEW
« components/previews/previews_data_savings.cc ('K') | « components/previews/previews_data_savings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698