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

Unified Diff: net/base/test_completion_callback_unittest.cc

Issue 693943003: Update from https://crrev.com/302630 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/test_completion_callback.cc ('k') | net/disk_cache/simple/simple_index_file.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/test_completion_callback_unittest.cc
diff --git a/net/base/test_completion_callback_unittest.cc b/net/base/test_completion_callback_unittest.cc
index 704273ebc7f41f583711363617579d71b1893262..b0c8565b112b7c4cd096f0c750f485f31aca276f 100644
--- a/net/base/test_completion_callback_unittest.cc
+++ b/net/base/test_completion_callback_unittest.cc
@@ -13,10 +13,18 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-typedef PlatformTest TestCompletionCallbackTest;
+namespace {
const int kMagicResult = 8888;
+void CallClosureAfterCheckingResult(const base::Closure& closure,
+ bool* did_check_result,
+ int result) {
+ DCHECK_EQ(result, kMagicResult);
+ *did_check_result = true;
+ closure.Run();
+}
+
// ExampleEmployer is a toy version of HostResolver
// TODO: restore damage done in extracting example from real code
// (e.g. bring back real destructor, bring back comments)
@@ -111,13 +119,32 @@ bool ExampleEmployer::DoSomething(const net::CompletionCallback& callback) {
return true;
}
+} // namespace
+
+typedef PlatformTest TestCompletionCallbackTest;
+
TEST_F(TestCompletionCallbackTest, Simple) {
ExampleEmployer boss;
net::TestCompletionCallback callback;
bool queued = boss.DoSomething(callback.callback());
- EXPECT_EQ(queued, true);
+ EXPECT_TRUE(queued);
int result = callback.WaitForResult();
EXPECT_EQ(result, kMagicResult);
}
+TEST_F(TestCompletionCallbackTest, Closure) {
+ ExampleEmployer boss;
+ net::TestClosure closure;
+ bool did_check_result = false;
+ net::CompletionCallback completion_callback =
+ base::Bind(&CallClosureAfterCheckingResult,
+ closure.closure(), base::Unretained(&did_check_result));
+ bool queued = boss.DoSomething(completion_callback);
+ EXPECT_TRUE(queued);
+
+ EXPECT_FALSE(did_check_result);
+ closure.WaitForResult();
+ EXPECT_TRUE(did_check_result);
+}
+
// TODO: test deleting ExampleEmployer while work outstanding
« no previous file with comments | « net/base/test_completion_callback.cc ('k') | net/disk_cache/simple/simple_index_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698