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

Side by Side Diff: webkit/appcache/appcache_update_job_unittest.cc

Issue 2501002: Quick fix to avoid crashing in unit tests when HTTPTestServer::CreateServer r... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/stl_util-inl.h" 7 #include "base/stl_util-inl.h"
8 #include "base/thread.h" 8 #include "base/thread.h"
9 #include "base/waitable_event.h" 9 #include "base/waitable_event.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 kDocRoot, io_thread_->message_loop()).release(); 366 kDocRoot, io_thread_->message_loop()).release();
367 ASSERT_TRUE(http_server_); 367 ASSERT_TRUE(http_server_);
368 request_context_ = new TestURLRequestContext(); 368 request_context_ = new TestURLRequestContext();
369 request_context_->AddRef(); 369 request_context_->AddRef();
370 } 370 }
371 371
372 static base::WaitableEvent* io_thread_shutdown_event_; 372 static base::WaitableEvent* io_thread_shutdown_event_;
373 373
374 // Cleanup function; must be called on the IO Thread. 374 // Cleanup function; must be called on the IO Thread.
375 static void CleanupIOThread() { 375 static void CleanupIOThread() {
376 http_server_->Release(); 376 if (http_server_) {
377 http_server_ = NULL; 377 http_server_->Release();
378 request_context_->Release(); 378 http_server_ = NULL;
379 request_context_ = NULL; 379 }
380 if (request_context_) {
381 request_context_->Release();
382 request_context_ = NULL;
383 }
380 io_thread_shutdown_event_->Signal(); 384 io_thread_shutdown_event_->Signal();
381 } 385 }
382 386
383 static void TearDownTestCase() { 387 static void TearDownTestCase() {
384 io_thread_shutdown_event_ = new base::WaitableEvent(false, false); 388 io_thread_shutdown_event_ = new base::WaitableEvent(false, false);
385 io_thread_->message_loop()->PostTask(FROM_HERE, 389 io_thread_->message_loop()->PostTask(FROM_HERE,
386 NewRunnableFunction(CleanupIOThread)); 390 NewRunnableFunction(CleanupIOThread));
387 io_thread_shutdown_event_->Wait(); 391 io_thread_shutdown_event_->Wait();
388 delete io_thread_shutdown_event_; 392 delete io_thread_shutdown_event_;
389 delete io_thread_; 393 delete io_thread_;
390 io_thread_ = NULL; 394 io_thread_ = NULL;
391 } 395 }
392 396
393 // Use a separate IO thread to run a test. Thread will be destroyed 397 // Use a separate IO thread to run a test. Thread will be destroyed
394 // when it goes out of scope. 398 // when it goes out of scope.
395 template <class Method> 399 template <class Method>
396 void RunTestOnIOThread(Method method) { 400 void RunTestOnIOThread(Method method) {
401 EXPECT_TRUE(http_server_);
402 if (!http_server_)
403 return; // Don't even try to run any of these tests w/o the server.
404
397 event_.reset(new base::WaitableEvent(false, false)); 405 event_.reset(new base::WaitableEvent(false, false));
398 io_thread_->message_loop()->PostTask( 406 io_thread_->message_loop()->PostTask(
399 FROM_HERE, NewRunnableMethod(this, method)); 407 FROM_HERE, NewRunnableMethod(this, method));
400 408
401 // Wait until task is done before exiting the test. 409 // Wait until task is done before exiting the test.
402 event_->Wait(); 410 event_->Wait();
403 } 411 }
404 412
405 void StartCacheAttemptTest() { 413 void StartCacheAttemptTest() {
406 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); 414 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
(...skipping 2624 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 } 3039 }
3032 3040
3033 TEST_F(AppCacheUpdateJobTest, UpgradeFetchManifestFail) { 3041 TEST_F(AppCacheUpdateJobTest, UpgradeFetchManifestFail) {
3034 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFetchManifestFailTest); 3042 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFetchManifestFailTest);
3035 } 3043 }
3036 3044
3037 TEST_F(AppCacheUpdateJobTest, ManifestRedirect) { 3045 TEST_F(AppCacheUpdateJobTest, ManifestRedirect) {
3038 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest); 3046 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest);
3039 } 3047 }
3040 3048
3041 #if defined(OS_MACOSX) 3049 TEST_F(AppCacheUpdateJobTest, ManifestWrongMimeType) {
3042 // Crashing on mac webkit bots. http://crbug.com/45664
3043 #define MAYBE_ManifestWrongMimeType DISABLED_ManifestWrongMimeType
3044 #else
3045 #define MAYBE_ManifestWrongMimeType ManifestWrongMimeType
3046 #endif
3047
3048 TEST_F(AppCacheUpdateJobTest, MAYBE_ManifestWrongMimeType) {
3049 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestWrongMimeTypeTest); 3050 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestWrongMimeTypeTest);
3050 } 3051 }
3051 3052
3052 TEST_F(AppCacheUpdateJobTest, ManifestNotFound) { 3053 TEST_F(AppCacheUpdateJobTest, ManifestNotFound) {
3053 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestNotFoundTest); 3054 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestNotFoundTest);
3054 } 3055 }
3055 3056
3056 TEST_F(AppCacheUpdateJobTest, ManifestGone) { 3057 TEST_F(AppCacheUpdateJobTest, ManifestGone) {
3057 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestGoneTest); 3058 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestGoneTest);
3058 } 3059 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
3230 struct RunnableMethodTraits<appcache::AppCacheUpdateJobTest> { 3231 struct RunnableMethodTraits<appcache::AppCacheUpdateJobTest> {
3231 void RetainCallee(appcache::AppCacheUpdateJobTest* obj) { } 3232 void RetainCallee(appcache::AppCacheUpdateJobTest* obj) { }
3232 void ReleaseCallee(appcache::AppCacheUpdateJobTest* obj) { } 3233 void ReleaseCallee(appcache::AppCacheUpdateJobTest* obj) { }
3233 }; 3234 };
3234 template<> 3235 template<>
3235 struct RunnableMethodTraits<appcache::AppCacheUpdateJobTest::MockAppCachePolicy> 3236 struct RunnableMethodTraits<appcache::AppCacheUpdateJobTest::MockAppCachePolicy>
3236 { 3237 {
3237 void RetainCallee(appcache::AppCacheUpdateJobTest::MockAppCachePolicy* o) { } 3238 void RetainCallee(appcache::AppCacheUpdateJobTest::MockAppCachePolicy* o) { }
3238 void ReleaseCallee(appcache::AppCacheUpdateJobTest::MockAppCachePolicy* o) { } 3239 void ReleaseCallee(appcache::AppCacheUpdateJobTest::MockAppCachePolicy* o) { }
3239 }; 3240 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698