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

Unified Diff: chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc

Issue 291483005: drive: Discard stream reader canceller as soon as the required data is obtained. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_stream_reader.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc
diff --git a/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc b/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc
index dbfb1991ae9945f5ff162a76dddfac3ac68d806d..eaac7d85b46949c1c38a5f3cadcf5575b12d78a5 100644
--- a/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc
+++ b/chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc
@@ -110,7 +110,7 @@ class NetworkReaderProxyTest : public ::testing::Test {
};
TEST_F(NetworkReaderProxyTest, EmptyFile) {
- NetworkReaderProxy proxy(0, 0, base::Bind(&base::DoNothing));
+ NetworkReaderProxy proxy(0, 0, 0, base::Bind(&base::DoNothing));
net::TestCompletionCallback callback;
const int kBufferSize = 10;
@@ -122,52 +122,60 @@ TEST_F(NetworkReaderProxyTest, EmptyFile) {
}
TEST_F(NetworkReaderProxyTest, Read) {
- NetworkReaderProxy proxy(0, 10, base::Bind(&base::DoNothing));
-
- net::TestCompletionCallback callback;
- const int kBufferSize = 3;
- scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize));
-
- // If no data is available yet, ERR_IO_PENDING should be returned.
- int result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
- EXPECT_EQ(net::ERR_IO_PENDING, result);
-
- // And when the data is supplied, the callback will be called.
- scoped_ptr<std::string> data(new std::string("abcde"));
- proxy.OnGetContent(data.Pass());
-
- // The returned data should be fit to the buffer size.
- result = callback.GetResult(result);
- EXPECT_EQ(3, result);
- EXPECT_EQ("abc", std::string(buffer->data(), result));
-
- // The next Read should return immediately because there is pending data
- result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
- EXPECT_EQ(2, result);
- EXPECT_EQ("de", std::string(buffer->data(), result));
-
- // Supply the data before calling Read operation.
- data.reset(new std::string("fg"));
- proxy.OnGetContent(data.Pass());
- data.reset(new std::string("hij"));
- proxy.OnGetContent(data.Pass()); // Now 10 bytes are supplied.
-
- // The data should be concatenated if possible.
- result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
- EXPECT_EQ(3, result);
- EXPECT_EQ("fgh", std::string(buffer->data(), result));
-
- result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
- EXPECT_EQ(2, result);
- EXPECT_EQ("ij", std::string(buffer->data(), result));
+ int cancel_called = 0;
+ {
+ NetworkReaderProxy proxy(0, 10, 10,
+ base::Bind(&IncrementCallback, &cancel_called));
+
+ net::TestCompletionCallback callback;
+ const int kBufferSize = 3;
+ scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize));
+
+ // If no data is available yet, ERR_IO_PENDING should be returned.
+ int result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
+ EXPECT_EQ(net::ERR_IO_PENDING, result);
+
+ // And when the data is supplied, the callback will be called.
+ scoped_ptr<std::string> data(new std::string("abcde"));
+ proxy.OnGetContent(data.Pass());
+
+ // The returned data should be fit to the buffer size.
+ result = callback.GetResult(result);
+ EXPECT_EQ(3, result);
+ EXPECT_EQ("abc", std::string(buffer->data(), result));
+
+ // The next Read should return immediately because there is pending data
+ result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
+ EXPECT_EQ(2, result);
+ EXPECT_EQ("de", std::string(buffer->data(), result));
+
+ // Supply the data before calling Read operation.
+ data.reset(new std::string("fg"));
+ proxy.OnGetContent(data.Pass());
+ data.reset(new std::string("hij"));
+ proxy.OnGetContent(data.Pass()); // Now 10 bytes are supplied.
+
+ // The data should be concatenated if possible.
+ result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
+ EXPECT_EQ(3, result);
+ EXPECT_EQ("fgh", std::string(buffer->data(), result));
+
+ result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
+ EXPECT_EQ(2, result);
+ EXPECT_EQ("ij", std::string(buffer->data(), result));
+
+ // The whole data is read, so Read() should return 0 immediately by then.
+ result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
+ EXPECT_EQ(0, result);
+ }
- // The whole data is read, so Read() should return 0 immediately by then.
- result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
- EXPECT_EQ(0, result);
+ // Proxy is deleted without any called to OnCompleted(). Even in the case,
+ // cancel callback should not be invoked.
+ EXPECT_EQ(0, cancel_called);
}
TEST_F(NetworkReaderProxyTest, ReadWithLimit) {
- NetworkReaderProxy proxy(10, 10, base::Bind(&base::DoNothing));
+ NetworkReaderProxy proxy(10, 10, 10, base::Bind(&base::DoNothing));
net::TestCompletionCallback callback;
const int kBufferSize = 3;
@@ -216,7 +224,7 @@ TEST_F(NetworkReaderProxyTest, ReadWithLimit) {
}
TEST_F(NetworkReaderProxyTest, ErrorWithPendingCallback) {
- NetworkReaderProxy proxy(0, 10, base::Bind(&base::DoNothing));
+ NetworkReaderProxy proxy(0, 10, 10, base::Bind(&base::DoNothing));
net::TestCompletionCallback callback;
const int kBufferSize = 3;
@@ -237,7 +245,7 @@ TEST_F(NetworkReaderProxyTest, ErrorWithPendingCallback) {
}
TEST_F(NetworkReaderProxyTest, ErrorWithPendingData) {
- NetworkReaderProxy proxy(0, 10, base::Bind(&base::DoNothing));
+ NetworkReaderProxy proxy(0, 10, 10, base::Bind(&base::DoNothing));
net::TestCompletionCallback callback;
const int kBufferSize = 3;
@@ -260,7 +268,7 @@ TEST_F(NetworkReaderProxyTest, CancelJob) {
int num_called = 0;
{
NetworkReaderProxy proxy(
- 0, 0, base::Bind(&IncrementCallback, &num_called));
+ 0, 0, 0, base::Bind(&IncrementCallback, &num_called));
proxy.OnCompleted(FILE_ERROR_OK);
// Destroy the instance after the network operation is completed.
// The cancelling callback shouldn't be called.
@@ -270,7 +278,7 @@ TEST_F(NetworkReaderProxyTest, CancelJob) {
num_called = 0;
{
NetworkReaderProxy proxy(
- 0, 0, base::Bind(&IncrementCallback, &num_called));
+ 0, 0, 0, base::Bind(&IncrementCallback, &num_called));
// Destroy the instance before the network operation is completed.
// The cancelling callback should be called.
}
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_stream_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698