OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" |
| 8 #include "base/bind_helpers.h" |
7 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
8 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
9 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
10 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
11 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
12 #include "net/url_request/url_request_error_job.h" | 14 #include "net/url_request/url_request_error_job.h" |
13 #include "net/url_request/url_request_job_factory.h" | 15 #include "net/url_request/url_request_job_factory.h" |
14 #include "net/url_request/url_request_test_job.h" | 16 #include "net/url_request/url_request_test_job.h" |
15 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
16 #include "webkit/appcache/appcache_group.h" | 18 #include "webkit/appcache/appcache_group.h" |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 563 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
562 io_thread_->StartWithOptions(options); | 564 io_thread_->StartWithOptions(options); |
563 } | 565 } |
564 | 566 |
565 // Use a separate IO thread to run a test. Thread will be destroyed | 567 // Use a separate IO thread to run a test. Thread will be destroyed |
566 // when it goes out of scope. | 568 // when it goes out of scope. |
567 template <class Method> | 569 template <class Method> |
568 void RunTestOnIOThread(Method method) { | 570 void RunTestOnIOThread(Method method) { |
569 event_.reset(new base::WaitableEvent(false, false)); | 571 event_.reset(new base::WaitableEvent(false, false)); |
570 io_thread_->message_loop()->PostTask( | 572 io_thread_->message_loop()->PostTask( |
571 FROM_HERE, NewRunnableMethod(this, method)); | 573 FROM_HERE, base::Bind(method, base::Unretained(this))); |
572 | 574 |
573 // Wait until task is done before exiting the test. | 575 // Wait until task is done before exiting the test. |
574 event_->Wait(); | 576 event_->Wait(); |
575 } | 577 } |
576 | 578 |
577 void StartCacheAttemptTest() { | 579 void StartCacheAttemptTest() { |
578 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 580 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
579 | 581 |
580 MakeService(); | 582 MakeService(); |
581 group_ = new AppCacheGroup(service_.get(), GURL("http://failme"), | 583 group_ = new AppCacheGroup(service_.get(), GURL("http://failme"), |
(...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2812 | 2814 |
2813 void OnUpdateComplete(AppCacheGroup* group) { | 2815 void OnUpdateComplete(AppCacheGroup* group) { |
2814 ASSERT_EQ(group_, group); | 2816 ASSERT_EQ(group_, group); |
2815 protect_newest_cache_ = group->newest_complete_cache(); | 2817 protect_newest_cache_ = group->newest_complete_cache(); |
2816 UpdateFinished(); | 2818 UpdateFinished(); |
2817 } | 2819 } |
2818 | 2820 |
2819 void UpdateFinished() { | 2821 void UpdateFinished() { |
2820 // We unwind the stack prior to finishing up to let stack-based objects | 2822 // We unwind the stack prior to finishing up to let stack-based objects |
2821 // get deleted. | 2823 // get deleted. |
2822 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 2824 MessageLoop::current()->PostTask( |
2823 this, &AppCacheUpdateJobTest::UpdateFinishedUnwound)); | 2825 FROM_HERE, base::Bind(&AppCacheUpdateJobTest::UpdateFinishedUnwound, |
| 2826 base::Unretained(this))); |
2824 } | 2827 } |
2825 | 2828 |
2826 void UpdateFinishedUnwound() { | 2829 void UpdateFinishedUnwound() { |
2827 EXPECT_EQ(AppCacheGroup::IDLE, group_->update_status()); | 2830 EXPECT_EQ(AppCacheGroup::IDLE, group_->update_status()); |
2828 EXPECT_TRUE(group_->update_job() == NULL); | 2831 EXPECT_TRUE(group_->update_job() == NULL); |
2829 if (do_checks_after_update_finished_) | 2832 if (do_checks_after_update_finished_) |
2830 VerifyExpectations(); | 2833 VerifyExpectations(); |
2831 | 2834 |
2832 // Clean up everything that was created on the IO thread. | 2835 // Clean up everything that was created on the IO thread. |
2833 protect_newest_cache_ = NULL; | 2836 protect_newest_cache_ = NULL; |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3444 | 3447 |
3445 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3448 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
3446 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3449 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
3447 } | 3450 } |
3448 | 3451 |
3449 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3452 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
3450 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3453 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
3451 } | 3454 } |
3452 | 3455 |
3453 } // namespace appcache | 3456 } // namespace appcache |
3454 | |
3455 // AppCacheUpdateJobTest is expected to always live longer than the | |
3456 // runnable methods. This lets us call NewRunnableMethod on its instances. | |
3457 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheUpdateJobTest); | |
OLD | NEW |