| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 7 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 8 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 9 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 10 #include "content/browser/appcache/appcache_group.h" | 13 #include "content/browser/appcache/appcache_group.h" |
| 11 #include "content/browser/appcache/appcache_host.h" | 14 #include "content/browser/appcache/appcache_host.h" |
| 12 #include "content/browser/appcache/appcache_response.h" | 15 #include "content/browser/appcache/appcache_response.h" |
| 13 #include "content/browser/appcache/appcache_update_job.h" | 16 #include "content/browser/appcache/appcache_update_job.h" |
| 14 #include "content/browser/appcache/mock_appcache_service.h" | 17 #include "content/browser/appcache/mock_appcache_service.h" |
| 15 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 16 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| 17 #include "net/url_request/url_request_error_job.h" | 20 #include "net/url_request/url_request_error_job.h" |
| 18 #include "net/url_request/url_request_job_factory_impl.h" | 21 #include "net/url_request/url_request_job_factory_impl.h" |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread")); | 599 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread")); |
| 597 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 600 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 598 io_thread_->StartWithOptions(options); | 601 io_thread_->StartWithOptions(options); |
| 599 } | 602 } |
| 600 | 603 |
| 601 // Use a separate IO thread to run a test. Thread will be destroyed | 604 // Use a separate IO thread to run a test. Thread will be destroyed |
| 602 // when it goes out of scope. | 605 // when it goes out of scope. |
| 603 template <class Method> | 606 template <class Method> |
| 604 void RunTestOnIOThread(Method method) { | 607 void RunTestOnIOThread(Method method) { |
| 605 event_.reset(new base::WaitableEvent(false, false)); | 608 event_.reset(new base::WaitableEvent(false, false)); |
| 606 io_thread_->message_loop()->PostTask( | 609 io_thread_->task_runner()->PostTask( |
| 607 FROM_HERE, base::Bind(method, base::Unretained(this))); | 610 FROM_HERE, base::Bind(method, base::Unretained(this))); |
| 608 | 611 |
| 609 // Wait until task is done before exiting the test. | 612 // Wait until task is done before exiting the test. |
| 610 event_->Wait(); | 613 event_->Wait(); |
| 611 } | 614 } |
| 612 | 615 |
| 613 void StartCacheAttemptTest() { | 616 void StartCacheAttemptTest() { |
| 614 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); | 617 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
| 615 | 618 |
| 616 MakeService(); | 619 MakeService(); |
| (...skipping 2359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2976 | 2979 |
| 2977 void OnUpdateComplete(AppCacheGroup* group) override { | 2980 void OnUpdateComplete(AppCacheGroup* group) override { |
| 2978 ASSERT_EQ(group_.get(), group); | 2981 ASSERT_EQ(group_.get(), group); |
| 2979 protect_newest_cache_ = group->newest_complete_cache(); | 2982 protect_newest_cache_ = group->newest_complete_cache(); |
| 2980 UpdateFinished(); | 2983 UpdateFinished(); |
| 2981 } | 2984 } |
| 2982 | 2985 |
| 2983 void UpdateFinished() { | 2986 void UpdateFinished() { |
| 2984 // We unwind the stack prior to finishing up to let stack-based objects | 2987 // We unwind the stack prior to finishing up to let stack-based objects |
| 2985 // get deleted. | 2988 // get deleted. |
| 2986 base::MessageLoop::current()->PostTask( | 2989 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2987 FROM_HERE, | 2990 FROM_HERE, base::Bind(&AppCacheUpdateJobTest::UpdateFinishedUnwound, |
| 2988 base::Bind(&AppCacheUpdateJobTest::UpdateFinishedUnwound, | 2991 base::Unretained(this))); |
| 2989 base::Unretained(this))); | |
| 2990 } | 2992 } |
| 2991 | 2993 |
| 2992 void UpdateFinishedUnwound() { | 2994 void UpdateFinishedUnwound() { |
| 2993 EXPECT_EQ(AppCacheGroup::IDLE, group_->update_status()); | 2995 EXPECT_EQ(AppCacheGroup::IDLE, group_->update_status()); |
| 2994 EXPECT_TRUE(group_->update_job() == NULL); | 2996 EXPECT_TRUE(group_->update_job() == NULL); |
| 2995 if (do_checks_after_update_finished_) | 2997 if (do_checks_after_update_finished_) |
| 2996 VerifyExpectations(); | 2998 VerifyExpectations(); |
| 2997 | 2999 |
| 2998 // Clean up everything that was created on the IO thread. | 3000 // Clean up everything that was created on the IO thread. |
| 2999 protect_newest_cache_ = NULL; | 3001 protect_newest_cache_ = NULL; |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3644 | 3646 |
| 3645 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3647 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
| 3646 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3648 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
| 3647 } | 3649 } |
| 3648 | 3650 |
| 3649 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3651 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
| 3650 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3652 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
| 3651 } | 3653 } |
| 3652 | 3654 |
| 3653 } // namespace content | 3655 } // namespace content |
| OLD | NEW |