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

Side by Side Diff: content/browser/appcache/appcache_response_unittest.cc

Issue 2940023002: TaskScheduler: migrate appcache database over to use it. (Closed)
Patch Set: comments + rebase Created 3 years, 5 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
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include <stack> 8 #include <stack>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/message_loop/message_loop.h"
19 #include "base/pickle.h" 18 #include "base/pickle.h"
20 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
21 #include "base/synchronization/waitable_event.h" 20 #include "base/synchronization/waitable_event.h"
21 #include "base/test/scoped_task_environment.h"
22 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
23 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
24 #include "content/browser/appcache/appcache_response.h" 24 #include "content/browser/appcache/appcache_response.h"
25 #include "content/browser/appcache/mock_appcache_service.h" 25 #include "content/browser/appcache/mock_appcache_service.h"
26 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
27 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
28 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 using net::IOBuffer; 31 using net::IOBuffer;
(...skipping 30 matching lines...) Expand all
62 62
63 // Helper callback to run a test on our io_thread. The io_thread is spun up 63 // Helper callback to run a test on our io_thread. The io_thread is spun up
64 // once and reused for all tests. 64 // once and reused for all tests.
65 template <class Method> 65 template <class Method>
66 void MethodWrapper(Method method) { 66 void MethodWrapper(Method method) {
67 SetUpTest(); 67 SetUpTest();
68 (this->*method)(); 68 (this->*method)();
69 } 69 }
70 70
71 static void SetUpTestCase() { 71 static void SetUpTestCase() {
72 scoped_task_environment_.reset(new base::test::ScopedTaskEnvironment);
72 io_thread_.reset(new base::Thread("AppCacheResponseTest Thread")); 73 io_thread_.reset(new base::Thread("AppCacheResponseTest Thread"));
73 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); 74 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
74 io_thread_->StartWithOptions(options); 75 io_thread_->StartWithOptions(options);
75 } 76 }
76 77
77 static void TearDownTestCase() { 78 static void TearDownTestCase() {
78 io_thread_.reset(NULL); 79 io_thread_.reset();
80 scoped_task_environment_.reset();
79 } 81 }
80 82
81 AppCacheResponseTest() {} 83 AppCacheResponseTest() {}
82 84
83 template <class Method> 85 template <class Method>
84 void RunTestOnIOThread(Method method) { 86 void RunTestOnIOThread(Method method) {
85 test_finished_event_.reset(new base::WaitableEvent( 87 test_finished_event_.reset(new base::WaitableEvent(
86 base::WaitableEvent::ResetPolicy::AUTOMATIC, 88 base::WaitableEvent::ResetPolicy::AUTOMATIC,
87 base::WaitableEvent::InitialState::NOT_SIGNALED)); 89 base::WaitableEvent::InitialState::NOT_SIGNALED));
88 io_thread_->task_runner()->PostTask( 90 io_thread_->task_runner()->PostTask(
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 std::unique_ptr<AppCacheResponseWriter> writer_; 779 std::unique_ptr<AppCacheResponseWriter> writer_;
778 std::unique_ptr<AppCacheResponseMetadataWriter> metadata_writer_; 780 std::unique_ptr<AppCacheResponseMetadataWriter> metadata_writer_;
779 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_; 781 scoped_refptr<HttpResponseInfoIOBuffer> write_info_buffer_;
780 scoped_refptr<IOBuffer> write_buffer_; 782 scoped_refptr<IOBuffer> write_buffer_;
781 int expected_write_result_; 783 int expected_write_result_;
782 bool should_delete_writer_in_completion_callback_; 784 bool should_delete_writer_in_completion_callback_;
783 int writer_deletion_count_down_; 785 int writer_deletion_count_down_;
784 bool write_callback_was_called_; 786 bool write_callback_was_called_;
785 787
786 static std::unique_ptr<base::Thread> io_thread_; 788 static std::unique_ptr<base::Thread> io_thread_;
789 static std::unique_ptr<base::test::ScopedTaskEnvironment>
790 scoped_task_environment_;
787 }; 791 };
788 792
789 // static 793 // static
790 std::unique_ptr<base::Thread> AppCacheResponseTest::io_thread_; 794 std::unique_ptr<base::Thread> AppCacheResponseTest::io_thread_;
795 std::unique_ptr<base::test::ScopedTaskEnvironment>
796 AppCacheResponseTest::scoped_task_environment_;
791 797
792 TEST_F(AppCacheResponseTest, ReadNonExistentResponse) { 798 TEST_F(AppCacheResponseTest, ReadNonExistentResponse) {
793 RunTestOnIOThread(&AppCacheResponseTest::ReadNonExistentResponse); 799 RunTestOnIOThread(&AppCacheResponseTest::ReadNonExistentResponse);
794 } 800 }
795 801
796 TEST_F(AppCacheResponseTest, LoadResponseInfo_Miss) { 802 TEST_F(AppCacheResponseTest, LoadResponseInfo_Miss) {
797 RunTestOnIOThread(&AppCacheResponseTest::LoadResponseInfo_Miss); 803 RunTestOnIOThread(&AppCacheResponseTest::LoadResponseInfo_Miss);
798 } 804 }
799 805
800 TEST_F(AppCacheResponseTest, LoadResponseInfo_Hit) { 806 TEST_F(AppCacheResponseTest, LoadResponseInfo_Hit) {
(...skipping 18 matching lines...) Expand all
819 825
820 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) { 826 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) {
821 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks); 827 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks);
822 } 828 }
823 829
824 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { 830 TEST_F(AppCacheResponseTest, DeleteWithIOPending) {
825 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); 831 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending);
826 } 832 }
827 833
828 } // namespace content 834 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_request_handler_unittest.cc ('k') | content/browser/appcache/appcache_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698