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 <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> |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 test_finished_event_.reset(new base::WaitableEvent( | 84 test_finished_event_.reset(new base::WaitableEvent( |
85 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 85 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
86 base::WaitableEvent::InitialState::NOT_SIGNALED)); | 86 base::WaitableEvent::InitialState::NOT_SIGNALED)); |
87 io_thread_->task_runner()->PostTask( | 87 io_thread_->task_runner()->PostTask( |
88 FROM_HERE, base::Bind(&AppCacheResponseTest::MethodWrapper<Method>, | 88 FROM_HERE, base::Bind(&AppCacheResponseTest::MethodWrapper<Method>, |
89 base::Unretained(this), method)); | 89 base::Unretained(this), method)); |
90 test_finished_event_->Wait(); | 90 test_finished_event_->Wait(); |
91 } | 91 } |
92 | 92 |
93 void SetUpTest() { | 93 void SetUpTest() { |
94 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 94 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
95 DCHECK(task_stack_.empty()); | 95 DCHECK(task_stack_.empty()); |
96 storage_delegate_.reset(new MockStorageDelegate(this)); | 96 storage_delegate_.reset(new MockStorageDelegate(this)); |
97 service_.reset(new MockAppCacheService()); | 97 service_.reset(new MockAppCacheService()); |
98 expected_read_result_ = 0; | 98 expected_read_result_ = 0; |
99 expected_write_result_ = 0; | 99 expected_write_result_ = 0; |
100 written_response_id_ = 0; | 100 written_response_id_ = 0; |
101 should_delete_reader_in_completion_callback_ = false; | 101 should_delete_reader_in_completion_callback_ = false; |
102 should_delete_writer_in_completion_callback_ = false; | 102 should_delete_writer_in_completion_callback_ = false; |
103 reader_deletion_count_down_ = 0; | 103 reader_deletion_count_down_ = 0; |
104 writer_deletion_count_down_ = 0; | 104 writer_deletion_count_down_ = 0; |
105 read_callback_was_called_ = false; | 105 read_callback_was_called_ = false; |
106 write_callback_was_called_ = false; | 106 write_callback_was_called_ = false; |
107 } | 107 } |
108 | 108 |
109 void TearDownTest() { | 109 void TearDownTest() { |
110 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 110 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
111 while (!task_stack_.empty()) | 111 while (!task_stack_.empty()) |
112 task_stack_.pop(); | 112 task_stack_.pop(); |
113 | 113 |
114 reader_.reset(); | 114 reader_.reset(); |
115 read_buffer_ = NULL; | 115 read_buffer_ = NULL; |
116 read_info_buffer_ = NULL; | 116 read_info_buffer_ = NULL; |
117 writer_.reset(); | 117 writer_.reset(); |
118 write_buffer_ = NULL; | 118 write_buffer_ = NULL; |
119 write_info_buffer_ = NULL; | 119 write_info_buffer_ = NULL; |
120 storage_delegate_.reset(); | 120 storage_delegate_.reset(); |
121 service_.reset(); | 121 service_.reset(); |
122 } | 122 } |
123 | 123 |
124 void TestFinished() { | 124 void TestFinished() { |
125 // We unwind the stack prior to finishing up to let stack | 125 // We unwind the stack prior to finishing up to let stack |
126 // based objects get deleted. | 126 // based objects get deleted. |
127 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 127 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
128 base::ThreadTaskRunnerHandle::Get()->PostTask( | 128 base::ThreadTaskRunnerHandle::Get()->PostTask( |
129 FROM_HERE, base::Bind(&AppCacheResponseTest::TestFinishedUnwound, | 129 FROM_HERE, base::Bind(&AppCacheResponseTest::TestFinishedUnwound, |
130 base::Unretained(this))); | 130 base::Unretained(this))); |
131 } | 131 } |
132 | 132 |
133 void TestFinishedUnwound() { | 133 void TestFinishedUnwound() { |
134 TearDownTest(); | 134 TearDownTest(); |
135 test_finished_event_->Signal(); | 135 test_finished_event_->Signal(); |
136 } | 136 } |
137 | 137 |
138 void PushNextTask(const base::Closure& task) { | 138 void PushNextTask(const base::Closure& task) { |
139 task_stack_.push(std::pair<base::Closure, bool>(task, false)); | 139 task_stack_.push(std::pair<base::Closure, bool>(task, false)); |
140 } | 140 } |
141 | 141 |
142 void PushNextTaskAsImmediate(const base::Closure& task) { | 142 void PushNextTaskAsImmediate(const base::Closure& task) { |
143 task_stack_.push(std::pair<base::Closure, bool>(task, true)); | 143 task_stack_.push(std::pair<base::Closure, bool>(task, true)); |
144 } | 144 } |
145 | 145 |
146 void ScheduleNextTask() { | 146 void ScheduleNextTask() { |
147 DCHECK(base::MessageLoop::current() == io_thread_->message_loop()); | 147 DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); |
148 if (task_stack_.empty()) { | 148 if (task_stack_.empty()) { |
149 TestFinished(); | 149 TestFinished(); |
150 return; | 150 return; |
151 } | 151 } |
152 base::Closure task = task_stack_.top().first; | 152 base::Closure task = task_stack_.top().first; |
153 bool immediate = task_stack_.top().second; | 153 bool immediate = task_stack_.top().second; |
154 task_stack_.pop(); | 154 task_stack_.pop(); |
155 if (immediate) | 155 if (immediate) |
156 task.Run(); | 156 task.Run(); |
157 else | 157 else |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 | 818 |
819 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) { | 819 TEST_F(AppCacheResponseTest, DeleteWithinCallbacks) { |
820 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks); | 820 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithinCallbacks); |
821 } | 821 } |
822 | 822 |
823 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { | 823 TEST_F(AppCacheResponseTest, DeleteWithIOPending) { |
824 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); | 824 RunTestOnIOThread(&AppCacheResponseTest::DeleteWithIOPending); |
825 } | 825 } |
826 | 826 |
827 } // namespace content | 827 } // namespace content |
OLD | NEW |