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

Side by Side Diff: chrome/browser/devtools/devtools_network_controller_unittest.cc

Issue 1411183009: [DevTools] Narrow down DevToolsNetworkInterceptor::Throttable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | « no previous file | chrome/browser/devtools/devtools_network_interceptor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 int Start() { 77 int Start() {
78 return transaction_->Start( 78 return transaction_->Start(
79 GetRequest(), completion_callback_, net::BoundNetLog()); 79 GetRequest(), completion_callback_, net::BoundNetLog());
80 } 80 }
81 81
82 int Read() { 82 int Read() {
83 return transaction_->Read(buffer_.get(), 64, completion_callback_); 83 return transaction_->Read(buffer_.get(), 64, completion_callback_);
84 } 84 }
85 85
86 bool ShouldFail() { 86 bool ShouldFail() {
87 return transaction_->interceptor_->ShouldFail(); 87 if (transaction_->interceptor_)
88 return transaction_->interceptor_->ShouldFail();
89 base::WeakPtr<DevToolsNetworkInterceptor> interceptor =
90 controller_.GetInterceptor(kClientId);
91 EXPECT_TRUE(!!interceptor);
92 return interceptor->ShouldFail();
93 }
94
95 bool HasStarted() {
96 return !!transaction_->request_;
97 }
98
99 bool HasFailed() {
100 return transaction_->failed_;
88 } 101 }
89 102
90 ~DevToolsNetworkControllerHelper() { 103 ~DevToolsNetworkControllerHelper() {
91 RemoveMockTransaction(&mock_transaction_); 104 RemoveMockTransaction(&mock_transaction_);
92 } 105 }
93 106
94 TestCallback* callback() { return &callback_; } 107 TestCallback* callback() { return &callback_; }
95 MockTransaction* mock_transaction() { return &mock_transaction_; } 108 MockTransaction* mock_transaction() { return &mock_transaction_; }
96 DevToolsNetworkController* controller() { return &controller_; } 109 DevToolsNetworkController* controller() { return &controller_; }
97 DevToolsNetworkTransaction* transaction() { return transaction_.get(); } 110 DevToolsNetworkTransaction* transaction() { return transaction_.get(); }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 helper.SetNetworkState(kClientId, true); 190 helper.SetNetworkState(kClientId, true);
178 EXPECT_EQ(callback->run_count(), 1); 191 EXPECT_EQ(callback->run_count(), 1);
179 } 192 }
180 193
181 TEST(DevToolsNetworkControllerTest, ReadAfterFail) { 194 TEST(DevToolsNetworkControllerTest, ReadAfterFail) {
182 DevToolsNetworkControllerHelper helper; 195 DevToolsNetworkControllerHelper helper;
183 helper.SetNetworkState(kClientId, false); 196 helper.SetNetworkState(kClientId, false);
184 197
185 int rv = helper.Start(); 198 int rv = helper.Start();
186 EXPECT_EQ(rv, net::OK); 199 EXPECT_EQ(rv, net::OK);
187 EXPECT_TRUE(helper.transaction()->HasStarted()); 200 EXPECT_TRUE(helper.HasStarted());
188 201
189 helper.SetNetworkState(kClientId, true); 202 helper.SetNetworkState(kClientId, true);
190 EXPECT_TRUE(helper.transaction()->HasFailed()); 203 EXPECT_TRUE(helper.HasFailed());
191 204
192 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(64)); 205 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(64));
193 rv = helper.Read(); 206 rv = helper.Read();
194 EXPECT_EQ(rv, net::ERR_INTERNET_DISCONNECTED); 207 EXPECT_EQ(rv, net::ERR_INTERNET_DISCONNECTED);
195 208
196 // Check that callback is never invoked. 209 // Check that callback is never invoked.
197 base::RunLoop().RunUntilIdle(); 210 base::RunLoop().RunUntilIdle();
198 EXPECT_EQ(helper.callback()->run_count(), 0); 211 EXPECT_EQ(helper.callback()->run_count(), 0);
199 } 212 }
200 213
201 } // namespace test 214 } // namespace test
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/devtools/devtools_network_interceptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698