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

Side by Side Diff: content/browser/streams/stream_unittest.cc

Issue 22908008: Limit the total memory usage for Stream instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: creis's comments Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/streams/stream_registry.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/test/test_simple_task_runner.h" 6 #include "base/test/test_simple_task_runner.h"
7 #include "content/browser/streams/stream.h" 7 #include "content/browser/streams/stream.h"
8 #include "content/browser/streams/stream_read_observer.h" 8 #include "content/browser/streams/stream_read_observer.h"
9 #include "content/browser/streams/stream_registry.h" 9 #include "content/browser/streams/stream_registry.h"
10 #include "content/browser/streams/stream_write_observer.h" 10 #include "content/browser/streams/stream_write_observer.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 GURL url("blob://stream"); 244 GURL url("blob://stream");
245 scoped_refptr<Stream> stream1( 245 scoped_refptr<Stream> stream1(
246 new Stream(registry_.get(), &writer, url)); 246 new Stream(registry_.get(), &writer, url));
247 247
248 registry_->UnregisterStream(url); 248 registry_->UnregisterStream(url);
249 scoped_refptr<Stream> stream2 = registry_->GetStream(url); 249 scoped_refptr<Stream> stream2 = registry_->GetStream(url);
250 ASSERT_FALSE(stream2.get()); 250 ASSERT_FALSE(stream2.get());
251 } 251 }
252 252
253 TEST_F(StreamTest, MemoryExceedMemoryUsageLimit) {
254 TestStreamWriter writer1;
255 TestStreamWriter writer2;
256
257 GURL url1("blob://stream");
258 scoped_refptr<Stream> stream1(
259 new Stream(registry_.get(), &writer1, url1));
260
261 GURL url2("blob://stream2");
262 scoped_refptr<Stream> stream2(
263 new Stream(registry_.get(), &writer2, url2));
264
265 const int kMaxMemoryUsage = 1500000;
266 registry_->set_max_memory_usage_for_testing(kMaxMemoryUsage);
267
268 const int kBufferSize = 1000000;
269 scoped_refptr<net::IOBuffer> buffer(NewIOBuffer(kBufferSize));
270 writer1.Write(stream1.get(), buffer, kBufferSize);
271 // Make transfer happen.
272 base::MessageLoop::current()->RunUntilIdle();
273
274 writer2.Write(stream2.get(), buffer, kBufferSize);
275
276 // Written data (1000000 * 2) exceeded limit (1500000). |stream2| should be
277 // unregistered with |registry_|.
278 EXPECT_EQ(NULL, registry_->GetStream(url2).get());
279
280 writer1.Write(stream1.get(), buffer, kMaxMemoryUsage - kBufferSize);
281 // Should be accepted since stream2 is unregistered and the new data is not
282 // so big to exceed the limit.
283 EXPECT_FALSE(registry_->GetStream(url1).get() == NULL);
284 }
285
286 TEST_F(StreamTest, UnderMemoryUsageLimit) {
287 TestStreamWriter writer;
288 TestStreamReader reader;
289
290 GURL url("blob://stream");
291 scoped_refptr<Stream> stream(new Stream(registry_.get(), &writer, url));
292 EXPECT_TRUE(stream->SetReadObserver(&reader));
293
294 registry_->set_max_memory_usage_for_testing(1500000);
295
296 const int kBufferSize = 1000000;
297 scoped_refptr<net::IOBuffer> buffer(NewIOBuffer(kBufferSize));
298 writer.Write(stream.get(), buffer, kBufferSize);
299
300 // Run loop to make |reader| consume the data.
301 base::MessageLoop::current()->RunUntilIdle();
302
303 writer.Write(stream.get(), buffer, kBufferSize);
304
305 EXPECT_EQ(stream.get(), registry_->GetStream(url).get());
306 }
307
253 } // namespace content 308 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/streams/stream_registry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698