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

Unified Diff: net/spdy/spdy_buffer_unittest.cc

Issue 14311002: [SPDY] Avoid leaking bytes from the session flow control receive window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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 | « net/spdy/spdy_buffer.cc ('k') | net/spdy/spdy_http_stream.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_buffer_unittest.cc
diff --git a/net/spdy/spdy_buffer_unittest.cc b/net/spdy/spdy_buffer_unittest.cc
index fbd770527cb06df47deb265afb0bdb93cb51921b..bcf25d20fd88f39a9e61c39e51920a095b9a7c86 100644
--- a/net/spdy/spdy_buffer_unittest.cc
+++ b/net/spdy/spdy_buffer_unittest.cc
@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/io_buffer.h"
@@ -53,18 +54,45 @@ TEST_F(SpdyBufferTest, DataConstructor) {
EXPECT_EQ(std::string(kData, kDataSize), BufferToString(buffer));
}
+void IncrementBy(size_t* x, size_t delta) {
+ *x += delta;
+}
+
// Construct a SpdyBuffer and call Consume() on it, which should
-// update the remaining data pointer and size appropriately.
+// update the remaining data pointer and size appropriately, as well
+// as calling the consume callbacks.
TEST_F(SpdyBufferTest, Consume) {
SpdyBuffer buffer(kData, kDataSize);
+ size_t x1 = 0;
+ size_t x2 = 0;
+ buffer.AddConsumeCallback(base::Bind(&IncrementBy, &x1));
+ buffer.AddConsumeCallback(base::Bind(&IncrementBy, &x2));
+
EXPECT_EQ(std::string(kData, kDataSize), BufferToString(buffer));
buffer.Consume(5);
EXPECT_EQ(std::string(kData + 5, kDataSize - 5), BufferToString(buffer));
+ EXPECT_EQ(5u, x1);
+ EXPECT_EQ(5u, x2);
buffer.Consume(kDataSize - 5);
EXPECT_EQ(0u, buffer.GetRemainingSize());
+ EXPECT_EQ(kDataSize, x1);
+ EXPECT_EQ(kDataSize, x2);
+}
+
+// Construct a SpdyBuffer and attach a ConsumeCallback to it. The
+// callback should be called when the SpdyBuffer is destroyed.
+TEST_F(SpdyBufferTest, ConsumeOnDestruction) {
+ size_t x = 0;
+
+ {
+ SpdyBuffer buffer(kData, kDataSize);
+ buffer.AddConsumeCallback(base::Bind(&IncrementBy, &x));
+ }
+
+ EXPECT_EQ(kDataSize, x);
}
// Make sure the IOBuffer returned by GetIOBufferForRemainingData()
« no previous file with comments | « net/spdy/spdy_buffer.cc ('k') | net/spdy/spdy_http_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698