summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 00:38:56 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 00:38:56 +0000
commit79b15b23db23e5c7722258d0b227959be7ac387c (patch)
tree412e984c99342c6e6bedf4a5d4ac0766fe8210df /webkit
parent26d8e64e28eacee2118834aad825c3752d239c5d (diff)
downloadchromium_src-79b15b23db23e5c7722258d0b227959be7ac387c.zip
chromium_src-79b15b23db23e5c7722258d0b227959be7ac387c.tar.gz
chromium_src-79b15b23db23e5c7722258d0b227959be7ac387c.tar.bz2
AppCache*Test: do not use ScopedRunnableMethodFactory from multiple threads.
The event_ signaling should already prevent the testcase from being deleted before the test is done, so we can just post the tasks directly. BUG=24715 TEST=tools/valgrind/chrome_tests.sh --tool=tsan -t test_shell --gtest_filter='AppCache*' Review URL: http://codereview.chromium.org/2121005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/appcache/appcache_request_handler_unittest.cc28
-rw-r--r--webkit/appcache/appcache_response_unittest.cc151
-rw-r--r--webkit/appcache/appcache_storage_impl_unittest.cc68
-rw-r--r--webkit/appcache/appcache_update_job_unittest.cc53
-rw-r--r--webkit/appcache/appcache_url_request_job_unittest.cc59
5 files changed, 183 insertions, 176 deletions
diff --git a/webkit/appcache/appcache_request_handler_unittest.cc b/webkit/appcache/appcache_request_handler_unittest.cc
index 26091d9..83a0236 100644
--- a/webkit/appcache/appcache_request_handler_unittest.cc
+++ b/webkit/appcache/appcache_request_handler_unittest.cc
@@ -103,8 +103,7 @@ class AppCacheRequestHandlerTest : public testing::Test {
// Test harness --------------------------------------------------
AppCacheRequestHandlerTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- orig_http_factory_(NULL) {
+ : orig_http_factory_(NULL) {
}
template <class Method>
@@ -142,9 +141,8 @@ class AppCacheRequestHandlerTest : public testing::Test {
// We unwind the stack prior to finishing up to let stack
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread_->message_loop());
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &AppCacheRequestHandlerTest::TestFinishedUnwound));
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &AppCacheRequestHandlerTest::TestFinishedUnwound));
}
void TestFinishedUnwound() {
@@ -169,8 +167,8 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_Miss --------------------------------------------------
void MainResource_Miss() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheRequestHandlerTest::Verify_MainResource_Miss));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheRequestHandlerTest::Verify_MainResource_Miss));
request_.reset(new MockURLRequest(GURL("http://blah/")));
handler_.reset(host_->CreateRequestHandler(request_.get(), true));
@@ -207,8 +205,8 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_Hit --------------------------------------------------
void MainResource_Hit() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheRequestHandlerTest::Verify_MainResource_Hit));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheRequestHandlerTest::Verify_MainResource_Hit));
request_.reset(new MockURLRequest(GURL("http://blah/")));
handler_.reset(host_->CreateRequestHandler(request_.get(), true));
@@ -246,8 +244,8 @@ class AppCacheRequestHandlerTest : public testing::Test {
// MainResource_Fallback --------------------------------------------------
void MainResource_Fallback() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheRequestHandlerTest::Verify_MainResource_Fallback));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheRequestHandlerTest::Verify_MainResource_Fallback));
request_.reset(new MockURLRequest(GURL("http://blah/")));
handler_.reset(host_->CreateRequestHandler(request_.get(), true));
@@ -573,7 +571,6 @@ class AppCacheRequestHandlerTest : public testing::Test {
// Data members --------------------------------------------------
- ScopedRunnableMethodFactory<AppCacheRequestHandlerTest> method_factory_;
scoped_ptr<base::WaitableEvent> test_finished_event_;
std::stack<Task*> task_stack_;
scoped_ptr<MockAppCacheService> mock_service_;
@@ -655,3 +652,10 @@ TEST_F(AppCacheRequestHandlerTest, CanceledRequest) {
} // namespace appcache
+// AppCacheRequestHandlerTest is expected to always live longer than the
+// runnable methods. This lets us call NewRunnableMethod on its instances.
+template<>
+struct RunnableMethodTraits<appcache::AppCacheRequestHandlerTest> {
+ void RetainCallee(appcache::AppCacheRequestHandlerTest* obj) { }
+ void ReleaseCallee(appcache::AppCacheRequestHandlerTest* obj) { }
+};
diff --git a/webkit/appcache/appcache_response_unittest.cc b/webkit/appcache/appcache_response_unittest.cc
index d96d2e4..c0a4eb5 100644
--- a/webkit/appcache/appcache_response_unittest.cc
+++ b/webkit/appcache/appcache_response_unittest.cc
@@ -75,8 +75,7 @@ class AppCacheResponseTest : public testing::Test {
}
AppCacheResponseTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
+ : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
this, &AppCacheResponseTest::OnReadComplete)),
ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
this, &AppCacheResponseTest::OnReadInfoComplete)),
@@ -131,8 +130,7 @@ class AppCacheResponseTest : public testing::Test {
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread_->message_loop());
MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::TestFinishedUnwound));
+ NewRunnableMethod(this, &AppCacheResponseTest::TestFinishedUnwound));
}
void TestFinishedUnwound() {
@@ -180,8 +178,8 @@ class AppCacheResponseTest : public testing::Test {
IOBuffer* body, int body_len) {
DCHECK(body);
scoped_refptr<IOBuffer> body_ref(body);
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteResponseBody,
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteResponseBody,
body_ref, body_len));
WriteResponseHead(head);
}
@@ -306,10 +304,10 @@ class AppCacheResponseTest : public testing::Test {
GURL(), kNoSuchResponseId));
// Push tasks in reverse order
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadNonExistentData));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadNonExistentInfo));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadNonExistentData));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadNonExistentInfo));
ScheduleNextTask();
}
@@ -331,8 +329,8 @@ class AppCacheResponseTest : public testing::Test {
// LoadResponseInfo_Miss ----------------------------------------------------
void LoadResponseInfo_Miss() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::LoadResponseInfo_Miss_Verify));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::LoadResponseInfo_Miss_Verify));
service_->storage()->LoadResponseInfo(GURL(), kNoSuchResponseId,
storage_delegate_.get());
}
@@ -350,8 +348,8 @@ class AppCacheResponseTest : public testing::Test {
// a. headers
// b. body
// 2. Use LoadResponseInfo to read the response headers back out
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::LoadResponseInfo_Hit_Step2));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::LoadResponseInfo_Hit_Step2));
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
WriteBasicResponse();
@@ -359,8 +357,8 @@ class AppCacheResponseTest : public testing::Test {
void LoadResponseInfo_Hit_Step2() {
writer_.reset();
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::LoadResponseInfo_Hit_Verify));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::LoadResponseInfo_Hit_Verify));
service_->storage()->LoadResponseInfo(GURL(), written_response_id_,
storage_delegate_.get());
}
@@ -387,14 +385,15 @@ class AppCacheResponseTest : public testing::Test {
GetHttpResponseInfoSize(head) + kNumBlocks * kBlockSize;
// Push tasks in reverse order.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::Verify_AmountWritten, expected_amount_written));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::Verify_AmountWritten,
+ expected_amount_written));
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
}
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteResponseHead, head));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteResponseHead, head));
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
@@ -420,22 +419,22 @@ class AppCacheResponseTest : public testing::Test {
// 6. Attempt to read beyond EOF of a range.
// Push tasks in reverse order
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadRangeFullyBeyondEOF));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadRangePartiallyBeyondEOF));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadPastEOF));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadRange));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadPastEOF));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadAllAtOnce));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadInBlocks));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteOutBlocks));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadRangeFullyBeyondEOF));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadRangePartiallyBeyondEOF));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadPastEOF));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadRange));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadPastEOF));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadAllAtOnce));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadInBlocks));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteOutBlocks));
// Get them going.
ScheduleNextTask();
@@ -445,8 +444,8 @@ class AppCacheResponseTest : public testing::Test {
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
}
ScheduleNextTask();
}
@@ -463,15 +462,15 @@ class AppCacheResponseTest : public testing::Test {
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), written_response_id_));
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadOneBlock, kNumBlocks - i));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadOneBlock, kNumBlocks - i));
}
ScheduleNextTask();
}
void ReadOneBlock(int block_number) {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::VerifyOneBlock, block_number));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::VerifyOneBlock, block_number));
ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize);
}
@@ -481,8 +480,8 @@ class AppCacheResponseTest : public testing::Test {
}
void ReadAllAtOnce() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::VerifyAllAtOnce));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::VerifyAllAtOnce));
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), written_response_id_));
int big_size = kNumBlocks * kBlockSize;
@@ -505,8 +504,8 @@ class AppCacheResponseTest : public testing::Test {
}
void ReadRange() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::VerifyRange));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::VerifyRange));
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), written_response_id_));
reader_->SetReadRange(kBlockSize, kBlockSize);
@@ -519,8 +518,8 @@ class AppCacheResponseTest : public testing::Test {
}
void ReadRangePartiallyBeyondEOF() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::VerifyRangeBeyondEOF));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::VerifyRangeBeyondEOF));
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), written_response_id_));
reader_->SetReadRange(kBlockSize, kNumBlocks * kBlockSize);
@@ -549,10 +548,10 @@ class AppCacheResponseTest : public testing::Test {
// 2. Read and verify several blocks in similarly chaining reads.
// Push tasks in reverse order
- PushNextTaskAsImmediate(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadInBlocksImmediately));
- PushNextTaskAsImmediate(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteOutBlocksImmediately));
+ PushNextTaskAsImmediate(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadInBlocksImmediately));
+ PushNextTaskAsImmediate(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteOutBlocksImmediately));
// Get them going.
ScheduleNextTask();
@@ -562,8 +561,8 @@ class AppCacheResponseTest : public testing::Test {
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTaskAsImmediate(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
+ PushNextTaskAsImmediate(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteOneBlock, kNumBlocks - i));
}
ScheduleNextTask();
}
@@ -573,15 +572,16 @@ class AppCacheResponseTest : public testing::Test {
reader_.reset(service_->storage()->CreateResponseReader(
GURL(), written_response_id_));
for (int i = 0; i < kNumBlocks; ++i) {
- PushNextTaskAsImmediate(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadOneBlockImmediately, kNumBlocks - i));
+ PushNextTaskAsImmediate(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadOneBlockImmediately,
+ kNumBlocks - i));
}
ScheduleNextTask();
}
void ReadOneBlockImmediately(int block_number) {
- PushNextTaskAsImmediate(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::VerifyOneBlock, block_number));
+ PushNextTaskAsImmediate(NewRunnableMethod(
+ this, &AppCacheResponseTest::VerifyOneBlock, block_number));
ReadResponseBody(new IOBuffer(kBlockSize), kBlockSize);
}
@@ -597,10 +597,10 @@ class AppCacheResponseTest : public testing::Test {
should_delete_writer_in_completion_callback_ = true;
writer_deletion_count_down_ = kNumBlocks;
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadInBlocks));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteOutBlocks));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadInBlocks));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteOutBlocks));
ScheduleNextTask();
}
@@ -609,12 +609,12 @@ class AppCacheResponseTest : public testing::Test {
// 1. Write a few blocks normally.
// 2. Start a write, delete with it pending.
// 3. Start a read, delete with it pending.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::ReadThenDelete));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteThenDelete));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::WriteOutBlocks));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::ReadThenDelete));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteThenDelete));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheResponseTest::WriteOutBlocks));
ScheduleNextTask();
}
@@ -636,8 +636,7 @@ class AppCacheResponseTest : public testing::Test {
// Wait a moment to verify no callbacks.
MessageLoop::current()->PostDelayedTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &AppCacheResponseTest::VerifyNoCallbacks),
+ NewRunnableMethod(this, &AppCacheResponseTest::VerifyNoCallbacks),
10);
}
@@ -649,7 +648,6 @@ class AppCacheResponseTest : public testing::Test {
// Data members
- ScopedRunnableMethodFactory<AppCacheResponseTest> method_factory_;
scoped_ptr<base::WaitableEvent> test_finished_event_;
scoped_ptr<MockStorageDelegate> storage_delegate_;
scoped_ptr<MockAppCacheService> service_;
@@ -716,3 +714,10 @@ TEST_F(AppCacheResponseTest, DeleteWithIOPending) {
} // namespace appcache
+// AppCacheResponseTest is expected to always live longer than the
+// runnable methods. This lets us call NewRunnableMethod on its instances.
+template<>
+struct RunnableMethodTraits<appcache::AppCacheResponseTest> {
+ void RetainCallee(appcache::AppCacheResponseTest* obj) { }
+ void ReleaseCallee(appcache::AppCacheResponseTest* obj) { }
+};
diff --git a/webkit/appcache/appcache_storage_impl_unittest.cc b/webkit/appcache/appcache_storage_impl_unittest.cc
index 182c3d8..00342df 100644
--- a/webkit/appcache/appcache_storage_impl_unittest.cc
+++ b/webkit/appcache/appcache_storage_impl_unittest.cc
@@ -213,8 +213,7 @@ class AppCacheStorageImplTest : public testing::Test {
// Test harness --------------------------------------------------
AppCacheStorageImplTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- ALLOW_THIS_IN_INITIALIZER_LIST(policy_(this)) {
+ : ALLOW_THIS_IN_INITIALIZER_LIST(policy_(this)) {
}
template <class Method>
@@ -248,8 +247,7 @@ class AppCacheStorageImplTest : public testing::Test {
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread->message_loop());
MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::TestFinishedUnwound));
+ NewRunnableMethod(this, &AppCacheStorageImplTest::TestFinishedUnwound));
}
void TestFinishedUnwound() {
@@ -289,8 +287,8 @@ class AppCacheStorageImplTest : public testing::Test {
void LoadCache_Miss() {
// Attempt to load a cache that doesn't exist. Should
// complete asyncly.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_LoadCache_Miss));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_LoadCache_Miss));
storage()->LoadCache(111, delegate());
EXPECT_NE(111, delegate()->loaded_cache_id_);
@@ -336,8 +334,8 @@ class AppCacheStorageImplTest : public testing::Test {
void CreateGroupInPopulatedOrigin() {
// Attempt to load a group that doesn't exist, one should
// be created for us, but not stored.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_CreateGroup));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_CreateGroup));
// Since the origin has groups, storage class will have to
// consult the database and completion will be async.
@@ -367,8 +365,8 @@ class AppCacheStorageImplTest : public testing::Test {
// Attempt to load a cache that is not currently in use
// and does require loading from disk. This
// load should complete asyncly.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_LoadCache_Far_Hit));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_LoadCache_Far_Hit));
// Setup some preconditions. Create a group and newest cache that
// appear to be "stored" and "not currently in use".
@@ -395,8 +393,8 @@ class AppCacheStorageImplTest : public testing::Test {
EXPECT_FALSE(delegate()->loaded_group_);
// Conduct the group load test, also complete asyncly.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit));
storage()->LoadOrCreateGroup(kManifestUrl, delegate());
}
@@ -414,8 +412,8 @@ class AppCacheStorageImplTest : public testing::Test {
void StoreNewGroup() {
// Store a group and its newest cache. Should complete asyncly.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_StoreNewGroup));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_StoreNewGroup));
// Setup some preconditions. Create a group and newest cache that
// appear to be "unstored".
@@ -448,8 +446,8 @@ class AppCacheStorageImplTest : public testing::Test {
void StoreExistingGroup() {
// Store a group and its newest cache. Should complete asyncly.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_StoreExistingGroup));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_StoreExistingGroup));
// Setup some preconditions. Create a group and old complete cache
// that appear to be "stored"
@@ -496,8 +494,8 @@ class AppCacheStorageImplTest : public testing::Test {
cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 100));
cache_->set_update_time(now);
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache,
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache,
now));
// Conduct the test.
@@ -535,8 +533,8 @@ class AppCacheStorageImplTest : public testing::Test {
void MakeGroupObsolete() {
// Make a group obsolete, should complete asyncly.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_MakeGroupObsolete));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete));
// Setup some preconditions. Create a group and newest cache that
// appears to be "stored" and "currently in use".
@@ -630,7 +628,7 @@ class AppCacheStorageImplTest : public testing::Test {
// MarkEntryAsForeignWithLoadInProgress -------------------------------
void MarkEntryAsForeignWithLoadInProgress() {
- PushNextTask(method_factory_.NewRunnableMethod(
+ PushNextTask(NewRunnableMethod(this,
&AppCacheStorageImplTest::Verify_MarkEntryAsForeignWithLoadInProgress));
// Setup some preconditions. Create a cache with an entry
@@ -674,8 +672,8 @@ class AppCacheStorageImplTest : public testing::Test {
// FindNoMainResponse -------------------------------
void FindNoMainResponse() {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_FindNoMainResponse));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_FindNoMainResponse));
// Conduct the test.
storage()->FindResponseForMainRequest(kEntryUrl, delegate());
@@ -709,8 +707,8 @@ class AppCacheStorageImplTest : public testing::Test {
void BasicFindMainResponse(bool drop_from_working_set,
bool block_with_policy_check) {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_BasicFindMainResponse));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_BasicFindMainResponse));
policy_.can_load_return_value_ = !block_with_policy_check;
service()->set_appcache_policy(&policy_);
@@ -765,8 +763,8 @@ class AppCacheStorageImplTest : public testing::Test {
}
void BasicFindMainFallbackResponse(bool drop_from_working_set) {
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse));
// Setup some preconditions. Create a complete cache with a
// fallback namespace and entry.
@@ -812,7 +810,7 @@ class AppCacheStorageImplTest : public testing::Test {
// FindMainResponseWithMultipleHits -------------------------------
void FindMainResponseWithMultipleHits() {
- PushNextTask(method_factory_.NewRunnableMethod(
+ PushNextTask(NewRunnableMethod(this,
&AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits));
// Setup some preconditions. Create 2 complete caches with an entry
@@ -888,8 +886,8 @@ class AppCacheStorageImplTest : public testing::Test {
}
// We should not find anything for the foreign entry.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheStorageImplTest::Verify_NotFound, kEntryUrl, false));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheStorageImplTest::Verify_NotFound, kEntryUrl, false));
storage()->FindResponseForMainRequest(kEntryUrl, delegate());
}
@@ -904,7 +902,7 @@ class AppCacheStorageImplTest : public testing::Test {
if (!test_finished) {
// We should not find anything for the online namespace.
- PushNextTask(method_factory_.NewRunnableMethod(
+ PushNextTask(NewRunnableMethod(this,
&AppCacheStorageImplTest::Verify_NotFound, kOnlineNamespace, true));
storage()->FindResponseForMainRequest(kOnlineNamespace, delegate());
return;
@@ -956,7 +954,6 @@ class AppCacheStorageImplTest : public testing::Test {
// Data members --------------------------------------------------
- ScopedRunnableMethodFactory<AppCacheStorageImplTest> method_factory_;
scoped_ptr<base::WaitableEvent> test_finished_event_;
std::stack<Task*> task_stack_;
MockAppCachePolicy policy_;
@@ -1062,3 +1059,10 @@ TEST_F(AppCacheStorageImplTest, FindMainResponseExclusionsInWorkingSet) {
} // namespace appcache
+// AppCacheStorageImplTest is expected to always live longer than the
+// runnable methods. This lets us call NewRunnableMethod on its instances.
+template<>
+struct RunnableMethodTraits<appcache::AppCacheStorageImplTest> {
+ void RetainCallee(appcache::AppCacheStorageImplTest* obj) { }
+ void ReleaseCallee(appcache::AppCacheStorageImplTest* obj) { }
+};
diff --git a/webkit/appcache/appcache_update_job_unittest.cc b/webkit/appcache/appcache_update_job_unittest.cc
index 18b9375..df63042 100644
--- a/webkit/appcache/appcache_update_job_unittest.cc
+++ b/webkit/appcache/appcache_update_job_unittest.cc
@@ -81,25 +81,6 @@ class MockFrontend : public AppCacheFrontend {
std::vector<AppCacheHost*> update_hosts_;
};
-// Helper class to let us call methods of AppCacheUpdateJobTest on a
-// thread of our choice.
-template <class Method>
-class WrapperTask : public Task {
- public:
- WrapperTask(AppCacheUpdateJobTest* test, Method method)
- : test_(test),
- method_(method) {
- }
-
- virtual void Run() {
- (test_->*method_)( );
- }
-
- private:
- AppCacheUpdateJobTest* test_;
- Method method_;
-};
-
// Helper factories to simulate redirected URL responses for tests.
static URLRequestJob* RedirectFactory(URLRequest* request,
const std::string& scheme) {
@@ -278,8 +259,7 @@ class AppCacheUpdateJobTest : public testing::Test,
class MockAppCachePolicy : public AppCachePolicy {
public:
MockAppCachePolicy()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- can_create_return_value_(net::OK), return_immediately_(true),
+ : can_create_return_value_(net::OK), return_immediately_(true),
callback_(NULL) {
}
@@ -294,9 +274,8 @@ class AppCacheUpdateJobTest : public testing::Test,
if (return_immediately_)
return can_create_return_value_;
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &MockAppCachePolicy::CompleteCanCreateAppCache));
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &MockAppCachePolicy::CompleteCanCreateAppCache));
return net::ERR_IO_PENDING;
}
@@ -304,7 +283,6 @@ class AppCacheUpdateJobTest : public testing::Test,
callback_->Run(can_create_return_value_);
}
- ScopedRunnableMethodFactory<MockAppCachePolicy> method_factory_;
int can_create_return_value_;
bool return_immediately_;
GURL requested_manifest_url_;
@@ -313,8 +291,7 @@ class AppCacheUpdateJobTest : public testing::Test,
AppCacheUpdateJobTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- do_checks_after_update_finished_(false),
+ : do_checks_after_update_finished_(false),
expect_group_obsolete_(false),
expect_group_has_cache_(false),
expect_old_cache_(NULL),
@@ -364,7 +341,7 @@ class AppCacheUpdateJobTest : public testing::Test,
void RunTestOnIOThread(Method method) {
event_.reset(new base::WaitableEvent(false, false));
io_thread_->message_loop()->PostTask(
- FROM_HERE, new WrapperTask<Method>(this, method));
+ FROM_HERE, NewRunnableMethod(this, method));
// Wait until task is done before exiting the test.
event_->Wait();
@@ -2562,9 +2539,8 @@ class AppCacheUpdateJobTest : public testing::Test,
void UpdateFinished() {
// We unwind the stack prior to finishing up to let stack-based objects
// get deleted.
- MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &AppCacheUpdateJobTest::UpdateFinishedUnwound));
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &AppCacheUpdateJobTest::UpdateFinishedUnwound));
}
void UpdateFinishedUnwound() {
@@ -2876,7 +2852,6 @@ class AppCacheUpdateJobTest : public testing::Test,
static HTTPTestServer* http_server_;
static TestURLRequestContext* request_context_;
- ScopedRunnableMethodFactory<AppCacheUpdateJobTest> method_factory_;
scoped_ptr<MockAppCacheService> service_;
scoped_refptr<AppCacheGroup> group_;
scoped_refptr<AppCache> protect_newest_cache_;
@@ -3182,3 +3157,17 @@ TEST_F(AppCacheUpdateJobTest, MultipleHeadersRefetch) {
}
} // namespace appcache
+
+// AppCacheUpdateJobTest is expected to always live longer than the
+// runnable methods. This lets us call NewRunnableMethod on its instances.
+template<>
+struct RunnableMethodTraits<appcache::AppCacheUpdateJobTest> {
+ void RetainCallee(appcache::AppCacheUpdateJobTest* obj) { }
+ void ReleaseCallee(appcache::AppCacheUpdateJobTest* obj) { }
+};
+template<>
+struct RunnableMethodTraits<appcache::AppCacheUpdateJobTest::MockAppCachePolicy>
+{
+ void RetainCallee(appcache::AppCacheUpdateJobTest::MockAppCachePolicy* o) { }
+ void ReleaseCallee(appcache::AppCacheUpdateJobTest::MockAppCachePolicy* o) { }
+};
diff --git a/webkit/appcache/appcache_url_request_job_unittest.cc b/webkit/appcache/appcache_url_request_job_unittest.cc
index cc4b853..330784d 100644
--- a/webkit/appcache/appcache_url_request_job_unittest.cc
+++ b/webkit/appcache/appcache_url_request_job_unittest.cc
@@ -161,8 +161,7 @@ class AppCacheURLRequestJobTest : public testing::Test {
}
AppCacheURLRequestJobTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
- ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
+ : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
this, &AppCacheURLRequestJobTest::OnReadComplete)),
ALLOW_THIS_IN_INITIALIZER_LIST(read_info_callback_(
this, &AppCacheURLRequestJobTest::OnReadInfoComplete)),
@@ -226,8 +225,8 @@ class AppCacheURLRequestJobTest : public testing::Test {
// based objects get deleted.
DCHECK(MessageLoop::current() == io_thread_->message_loop());
MessageLoop::current()->PostTask(FROM_HERE,
- method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::TestFinishedUnwound));
+ NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::TestFinishedUnwound));
}
void TestFinishedUnwound() {
@@ -271,8 +270,8 @@ class AppCacheURLRequestJobTest : public testing::Test {
IOBuffer* body, int body_len) {
DCHECK(body);
scoped_refptr<IOBuffer> body_ref(body);
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::WriteResponseBody,
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::WriteResponseBody,
body_ref, body_len));
WriteResponseHead(head);
}
@@ -448,8 +447,8 @@ class AppCacheURLRequestJobTest : public testing::Test {
void DeliverNetworkResponse() {
// This test has async steps.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse));
AppCacheStorage* storage = service_->storage();
request_.reset(
@@ -480,8 +479,8 @@ class AppCacheURLRequestJobTest : public testing::Test {
void DeliverErrorResponse() {
// This test has async steps.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::VerifyDeliverErrorResponse));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::VerifyDeliverErrorResponse));
AppCacheStorage* storage = service_->storage();
request_.reset(
@@ -517,10 +516,10 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use URLRequest to retrieve it.
// 3. Verify we received what we expected to receive.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::RequestAppCachedResource, false));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::RequestAppCachedResource, false));
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
@@ -583,10 +582,10 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use URLRequest to retrieve it.
// 3. Verify we received what we expected to receive.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
@@ -626,10 +625,10 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use URLRequest to retrieve it.
// 3. Cancel the request after data starts coming in.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::VerifyCancel));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::VerifyCancel));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
@@ -654,10 +653,10 @@ class AppCacheURLRequestJobTest : public testing::Test {
// 2. Use URLRequest to retrieve it.
// 3. Cancel the request after data starts coming in.
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::VerifyCancel));
- PushNextTask(method_factory_.NewRunnableMethod(
- &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::VerifyCancel));
+ PushNextTask(NewRunnableMethod(
+ this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
writer_.reset(service_->storage()->CreateResponseWriter(GURL()));
written_response_id_ = writer_->response_id();
@@ -671,7 +670,6 @@ class AppCacheURLRequestJobTest : public testing::Test {
// Data members --------------------------------------------------------
- ScopedRunnableMethodFactory<AppCacheURLRequestJobTest> method_factory_;
scoped_ptr<base::WaitableEvent> test_finished_event_;
scoped_ptr<MockStorageDelegate> storage_delegate_;
scoped_ptr<MockAppCacheService> service_;
@@ -744,3 +742,10 @@ TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
} // namespace appcache
+// AppCacheURLRequestJobTest is expected to always live longer than the
+// runnable methods. This lets us call NewRunnableMethod on its instances.
+template<>
+struct RunnableMethodTraits<appcache::AppCacheURLRequestJobTest> {
+ void RetainCallee(appcache::AppCacheURLRequestJobTest* obj) { }
+ void ReleaseCallee(appcache::AppCacheURLRequestJobTest* obj) { }
+};