| OLD | NEW |
| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class StreamTest : public testing::Test { | 15 class StreamTest : public testing::Test { |
| 16 public: | 16 public: |
| 17 StreamTest() : producing_seed_key_(0) {} | 17 StreamTest() : producing_seed_key_(0) {} |
| 18 | 18 |
| 19 virtual void SetUp() override { | 19 void SetUp() override { registry_.reset(new StreamRegistry()); } |
| 20 registry_.reset(new StreamRegistry()); | |
| 21 } | |
| 22 | 20 |
| 23 // Create a new IO buffer of the given |buffer_size| and fill it with random | 21 // Create a new IO buffer of the given |buffer_size| and fill it with random |
| 24 // data. | 22 // data. |
| 25 scoped_refptr<net::IOBuffer> NewIOBuffer(size_t buffer_size) { | 23 scoped_refptr<net::IOBuffer> NewIOBuffer(size_t buffer_size) { |
| 26 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(buffer_size)); | 24 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(buffer_size)); |
| 27 char *bufferp = buffer->data(); | 25 char *bufferp = buffer->data(); |
| 28 for (size_t i = 0; i < buffer_size; i++) | 26 for (size_t i = 0; i < buffer_size; i++) |
| 29 bufferp[i] = (i + producing_seed_key_) % (1 << sizeof(char)); | 27 bufferp[i] = (i + producing_seed_key_) % (1 << sizeof(char)); |
| 30 ++producing_seed_key_; | 28 ++producing_seed_key_; |
| 31 return buffer; | 29 return buffer; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 296 |
| 299 // Run loop to make |reader| consume the data. | 297 // Run loop to make |reader| consume the data. |
| 300 base::MessageLoop::current()->RunUntilIdle(); | 298 base::MessageLoop::current()->RunUntilIdle(); |
| 301 | 299 |
| 302 writer.Write(stream.get(), buffer, kBufferSize); | 300 writer.Write(stream.get(), buffer, kBufferSize); |
| 303 | 301 |
| 304 EXPECT_EQ(stream.get(), registry_->GetStream(url).get()); | 302 EXPECT_EQ(stream.get(), registry_->GetStream(url).get()); |
| 305 } | 303 } |
| 306 | 304 |
| 307 } // namespace content | 305 } // namespace content |
| OLD | NEW |