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 "content/browser/service_worker/service_worker_cache.h" | 5 #include "content/browser/service_worker/service_worker_cache.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 delayable_backend->OpenEntryContinue(); | 901 delayable_backend->OpenEntryContinue(); |
902 | 902 |
903 close_loop->Run(); | 903 close_loop->Run(); |
904 // Put failed because the backend was closed while it was running. | 904 // Put failed because the backend was closed while it was running. |
905 EXPECT_EQ(ServiceWorkerCache::ErrorTypeStorage, callback_error_); | 905 EXPECT_EQ(ServiceWorkerCache::ErrorTypeStorage, callback_error_); |
906 EXPECT_TRUE(callback_closed_); | 906 EXPECT_TRUE(callback_closed_); |
907 | 907 |
908 VerifyAllOpsFail(); | 908 VerifyAllOpsFail(); |
909 } | 909 } |
910 | 910 |
| 911 TEST_P(ServiceWorkerCacheTestP, VerifySerialScheduling) { |
| 912 // Start two operations, the first one is delayed but the second isn't. The |
| 913 // second should wait for the first. |
| 914 EXPECT_TRUE(Keys()); // Opens the backend. |
| 915 DelayableBackend* delayable_backend = cache_->UseDelayableBackend(); |
| 916 delayable_backend->set_delay_open(true); |
| 917 |
| 918 scoped_ptr<ServiceWorkerResponse> response1 = |
| 919 CopyFetchResponse(body_response_); |
| 920 response1->status_code = 1; |
| 921 |
| 922 scoped_ptr<base::RunLoop> close_loop1(new base::RunLoop()); |
| 923 cache_->Put(CopyFetchRequest(body_request_), response1.Pass(), |
| 924 base::Bind(&ServiceWorkerCacheTest::ResponseAndErrorCallback, |
| 925 base::Unretained(this), close_loop1.get())); |
| 926 |
| 927 // Blocks on opening the cache entry. |
| 928 base::RunLoop().RunUntilIdle(); |
| 929 |
| 930 delayable_backend->set_delay_open(false); |
| 931 scoped_ptr<ServiceWorkerResponse> response2 = |
| 932 CopyFetchResponse(body_response_); |
| 933 response2->status_code = 2; |
| 934 scoped_ptr<base::RunLoop> close_loop2(new base::RunLoop()); |
| 935 cache_->Put(CopyFetchRequest(body_request_), response2.Pass(), |
| 936 base::Bind(&ServiceWorkerCacheTest::ResponseAndErrorCallback, |
| 937 base::Unretained(this), close_loop2.get())); |
| 938 |
| 939 // The second put operation should wait for the first to complete. |
| 940 base::RunLoop().RunUntilIdle(); |
| 941 EXPECT_FALSE(callback_response_); |
| 942 |
| 943 delayable_backend->OpenEntryContinue(); |
| 944 close_loop1->Run(); |
| 945 EXPECT_EQ(1, callback_response_->status_code); |
| 946 close_loop2->Run(); |
| 947 EXPECT_EQ(2, callback_response_->status_code); |
| 948 } |
| 949 |
911 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, | 950 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, |
912 ServiceWorkerCacheTestP, | 951 ServiceWorkerCacheTestP, |
913 ::testing::Values(false, true)); | 952 ::testing::Values(false, true)); |
914 | 953 |
915 } // namespace content | 954 } // namespace content |
OLD | NEW |