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

Side by Side Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 2378173002: Precache per-resource cap should be applied on network bytes used (Closed)
Patch Set: Created 4 years, 2 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/url_request/url_fetcher_delegate.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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/url_request/url_fetcher_impl.h" 5 #include "net/url_request/url_fetcher_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 void OnURLFetchComplete(const URLFetcher* source) override { 120 void OnURLFetchComplete(const URLFetcher* source) override {
121 EXPECT_FALSE(did_complete_); 121 EXPECT_FALSE(did_complete_);
122 EXPECT_TRUE(fetcher_); 122 EXPECT_TRUE(fetcher_);
123 EXPECT_EQ(fetcher_.get(), source); 123 EXPECT_EQ(fetcher_.get(), source);
124 did_complete_ = true; 124 did_complete_ = true;
125 run_loop_.Quit(); 125 run_loop_.Quit();
126 } 126 }
127 127
128 void OnURLFetchDownloadProgress(const URLFetcher* source, 128 void OnURLFetchDownloadProgress(const URLFetcher* source,
129 int64_t current, 129 int64_t current,
130 int64_t total) override { 130 int64_t total,
131 int64_t current_network_bytes) override {
131 // Note that the current progress may be greater than the previous progress, 132 // Note that the current progress may be greater than the previous progress,
132 // in the case of retrying the request. 133 // in the case of retrying the request.
133 EXPECT_FALSE(did_complete_); 134 EXPECT_FALSE(did_complete_);
134 EXPECT_TRUE(fetcher_); 135 EXPECT_TRUE(fetcher_);
135 EXPECT_EQ(source, fetcher_.get()); 136 EXPECT_EQ(source, fetcher_.get());
136 137
137 EXPECT_LE(0, current); 138 EXPECT_LE(0, current);
138 // If file size is not known, |total| is -1. 139 // If file size is not known, |total| is -1.
139 if (total >= 0) 140 if (total >= 0)
140 EXPECT_LE(current, total); 141 EXPECT_LE(current, total);
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 // Checks that download progress never decreases, never exceeds file size, and 918 // Checks that download progress never decreases, never exceeds file size, and
918 // that file size is correctly reported. 919 // that file size is correctly reported.
919 class CheckDownloadProgressDelegate : public WaitingURLFetcherDelegate { 920 class CheckDownloadProgressDelegate : public WaitingURLFetcherDelegate {
920 public: 921 public:
921 CheckDownloadProgressDelegate(int64_t file_size) 922 CheckDownloadProgressDelegate(int64_t file_size)
922 : file_size_(file_size), last_seen_progress_(0) {} 923 : file_size_(file_size), last_seen_progress_(0) {}
923 ~CheckDownloadProgressDelegate() override {} 924 ~CheckDownloadProgressDelegate() override {}
924 925
925 void OnURLFetchDownloadProgress(const URLFetcher* source, 926 void OnURLFetchDownloadProgress(const URLFetcher* source,
926 int64_t current, 927 int64_t current,
927 int64_t total) override { 928 int64_t total,
929 int64_t current_network_bytes) override {
928 // Run default checks. 930 // Run default checks.
929 WaitingURLFetcherDelegate::OnURLFetchDownloadProgress(source, current, 931 WaitingURLFetcherDelegate::OnURLFetchDownloadProgress(
930 total); 932 source, current, total, current_network_bytes);
931 933
932 EXPECT_LE(last_seen_progress_, current); 934 EXPECT_LE(last_seen_progress_, current);
933 EXPECT_EQ(file_size_, total); 935 EXPECT_EQ(file_size_, total);
934 last_seen_progress_ = current; 936 last_seen_progress_ = current;
935 } 937 }
936 938
937 private: 939 private:
938 int64_t file_size_; 940 int64_t file_size_;
939 int64_t last_seen_progress_; 941 int64_t last_seen_progress_;
940 942
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 EXPECT_FALSE(delegate.fetcher()); 1006 EXPECT_FALSE(delegate.fetcher());
1005 } 1007 }
1006 1008
1007 class CancelOnDownloadProgressDelegate : public WaitingURLFetcherDelegate { 1009 class CancelOnDownloadProgressDelegate : public WaitingURLFetcherDelegate {
1008 public: 1010 public:
1009 CancelOnDownloadProgressDelegate() {} 1011 CancelOnDownloadProgressDelegate() {}
1010 ~CancelOnDownloadProgressDelegate() override {} 1012 ~CancelOnDownloadProgressDelegate() override {}
1011 1013
1012 void OnURLFetchDownloadProgress(const URLFetcher* source, 1014 void OnURLFetchDownloadProgress(const URLFetcher* source,
1013 int64_t current, 1015 int64_t current,
1014 int64_t total) override { 1016 int64_t total,
1017 int64_t current_network_bytes) override {
1015 CancelFetch(); 1018 CancelFetch();
1016 } 1019 }
1017 1020
1018 private: 1021 private:
1019 DISALLOW_COPY_AND_ASSIGN(CancelOnDownloadProgressDelegate); 1022 DISALLOW_COPY_AND_ASSIGN(CancelOnDownloadProgressDelegate);
1020 }; 1023 };
1021 1024
1022 // Check that a fetch can be safely cancelled/deleted during a download progress 1025 // Check that a fetch can be safely cancelled/deleted during a download progress
1023 // callback. 1026 // callback.
1024 TEST_F(URLFetcherTest, CancelInDownloadProgressCallback) { 1027 TEST_F(URLFetcherTest, CancelInDownloadProgressCallback) {
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 EXPECT_EQ(-1, delegate.fetcher()->GetResponseCode()); 1539 EXPECT_EQ(-1, delegate.fetcher()->GetResponseCode());
1537 EXPECT_FALSE(delegate.fetcher()->GetResponseHeaders()); 1540 EXPECT_FALSE(delegate.fetcher()->GetResponseHeaders());
1538 std::string data; 1541 std::string data;
1539 EXPECT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); 1542 EXPECT_TRUE(delegate.fetcher()->GetResponseAsString(&data));
1540 EXPECT_TRUE(data.empty()); 1543 EXPECT_TRUE(data.empty());
1541 } 1544 }
1542 1545
1543 } // namespace 1546 } // namespace
1544 1547
1545 } // namespace net 1548 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_fetcher_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698