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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/previews/previews_data_savings_unittest.cc
diff --git a/components/previews/previews_data_savings_unittest.cc b/components/previews/previews_data_savings_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eddf01824d3fd265a11228b75adcb69d3bdd01e6
--- /dev/null
+++ b/components/previews/previews_data_savings_unittest.cc
@@ -0,0 +1,97 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/previews/previews_data_savings.h"
+
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+
+#include "components/data_reduction_proxy/core/common/data_savings_recorder.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace previews {
+
+namespace {
+
+class TestDataSavingsRecorder
+ : public data_reduction_proxy::DataSavingsRecorder {
+ public:
+ TestDataSavingsRecorder()
+ : data_saver_enabled_(false), data_used_(0), original_size_(0) {}
+ ~TestDataSavingsRecorder() {}
+
+ // data_reduction_proxy::DataSavingsRecorder implementation:
+ void UpdateDataSavings(const std::string& host,
+ int64_t data_used,
+ int64_t original_size) override {
+ last_host_ = host;
+ data_used_ += data_used;
+ original_size_ += original_size;
+ }
+ bool ShouldRecordDataSavings() const override { return data_saver_enabled_; }
+
+ void set_data_saver_enabled(bool data_saver_enabled) {
+ data_saver_enabled_ = data_saver_enabled;
+ }
+
+ std::string last_host() const { return last_host_; }
+
+ int64_t data_used() const { return data_used_; }
+
+ int64_t original_size() const { return original_size_; }
+
+ private:
+ bool data_saver_enabled_;
+ std::string last_host_;
+ int64_t data_used_;
+ int64_t original_size_;
+};
+
+} // namespace
+
+class PreviewsDataSavingsTest : public testing::Test {
+ public:
+ PreviewsDataSavingsTest()
+ : test_data_savings_recorder_(new TestDataSavingsRecorder()),
+ data_savings_(
+ new PreviewsDataSavings(test_data_savings_recorder_.get())) {}
+ ~PreviewsDataSavingsTest() override {}
+
+ PreviewsDataSavings* data_savings() const { return data_savings_.get(); }
+
+ TestDataSavingsRecorder* test_data_savings_recorder() const {
+ return test_data_savings_recorder_.get();
+ }
+
+ private:
+ std::unique_ptr<TestDataSavingsRecorder> test_data_savings_recorder_;
+ std::unique_ptr<PreviewsDataSavings> data_savings_;
+};
+
+TEST_F(PreviewsDataSavingsTest, RecordDataSavings) {
+ int64_t original_size = 200;
+ int64_t data_used = 100;
+ std::string host = "host";
+
+ EXPECT_EQ(0, test_data_savings_recorder()->data_used());
+ EXPECT_EQ(0, test_data_savings_recorder()->original_size());
+ test_data_savings_recorder()->set_data_saver_enabled(false);
+
+ data_savings()->RecordDataSavings(host, data_used, original_size);
+
+ EXPECT_EQ(0, test_data_savings_recorder()->data_used());
+ EXPECT_EQ(0, test_data_savings_recorder()->original_size());
+ EXPECT_EQ(std::string(), test_data_savings_recorder()->last_host());
+ test_data_savings_recorder()->set_data_saver_enabled(true);
+
+ data_savings()->RecordDataSavings(host, data_used, original_size);
+
+ EXPECT_EQ(data_used, test_data_savings_recorder()->data_used());
+ EXPECT_EQ(original_size, test_data_savings_recorder()->original_size());
+ EXPECT_EQ(host, test_data_savings_recorder()->last_host());
+}
+
+} // namespace previews
« 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