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 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "content/browser/message_port_service.h" | 9 #include "content/browser/message_port_service.h" |
10 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 }; | 73 }; |
74 | 74 |
75 class MockBackgroundSyncServiceClient : public BackgroundSyncServiceClient { | 75 class MockBackgroundSyncServiceClient : public BackgroundSyncServiceClient { |
76 public: | 76 public: |
77 MockBackgroundSyncServiceClient( | 77 MockBackgroundSyncServiceClient( |
78 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) | 78 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) |
79 : binding_(this, std::move(request)) {} | 79 : binding_(this, std::move(request)) {} |
80 | 80 |
81 void RunCallback() { | 81 void RunCallback() { |
82 EXPECT_FALSE(callback_.is_null()); | 82 EXPECT_FALSE(callback_.is_null()); |
83 callback_.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED); | 83 callback_.Run(ServiceWorkerEventStatus::ABORTED); |
84 } | 84 } |
85 | 85 |
86 private: | 86 private: |
87 // BackgroundSyncServiceClient overrides | 87 // BackgroundSyncServiceClient overrides |
88 void Sync(int64_t handle_id, | 88 void Sync(int64_t handle_id, |
89 content::BackgroundSyncEventLastChance last_chance, | 89 content::BackgroundSyncEventLastChance last_chance, |
90 const SyncCallback& callback) override { | 90 const SyncCallback& callback) override { |
91 EXPECT_TRUE(callback_.is_null()); | 91 EXPECT_TRUE(callback_.is_null()); |
92 callback_ = callback; | 92 callback_ = callback; |
93 } | 93 } |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); | 805 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); |
806 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); | 806 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); |
807 } | 807 } |
808 | 808 |
809 TEST_F(ServiceWorkerVersionTest, RequestCustomizedTimeout) { | 809 TEST_F(ServiceWorkerVersionTest, RequestCustomizedTimeout) { |
810 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value | 810 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NETWORK; // dummy value |
811 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 811 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
812 | 812 |
813 // Create a sync request that should expire Now(). | 813 // Create a sync request that should expire Now(). |
814 version_->DispatchSyncEvent(0 /* sync handle id */, | 814 version_->DispatchSyncEvent(0 /* sync handle id */, |
815 BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_LAST_CHANCE, | 815 BackgroundSyncEventLastChance::IS_LAST_CHANCE, |
816 base::TimeDelta(), /* max duration */ | 816 base::TimeDelta(), /* max duration */ |
817 base::Bind(&ReceiveSyncStatus, &status)); | 817 base::Bind(&ReceiveSyncStatus, &status)); |
818 base::RunLoop().RunUntilIdle(); | 818 base::RunLoop().RunUntilIdle(); |
819 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); | 819 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); |
820 version_->timeout_timer_.user_task().Run(); | 820 version_->timeout_timer_.user_task().Run(); |
821 base::RunLoop().RunUntilIdle(); | 821 base::RunLoop().RunUntilIdle(); |
822 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); | 822 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); |
823 } | 823 } |
824 | 824 |
825 // crbug.com/571271 tracks flakiness in MixedRequestTimeouts. | 825 // crbug.com/571271 tracks flakiness in MixedRequestTimeouts. |
826 TEST_F(ServiceWorkerWaitForeverInFetchTest, DISABLED_MixedRequestTimeouts) { | 826 TEST_F(ServiceWorkerWaitForeverInFetchTest, DISABLED_MixedRequestTimeouts) { |
827 ServiceWorkerStatusCode sync_status = | 827 ServiceWorkerStatusCode sync_status = |
828 SERVICE_WORKER_ERROR_NETWORK; // dummy value | 828 SERVICE_WORKER_ERROR_NETWORK; // dummy value |
829 ServiceWorkerStatusCode fetch_status = | 829 ServiceWorkerStatusCode fetch_status = |
830 SERVICE_WORKER_ERROR_NETWORK; // dummy value | 830 SERVICE_WORKER_ERROR_NETWORK; // dummy value |
831 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 831 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
832 | 832 |
833 // Create a fetch request that should expire sometime later. | 833 // Create a fetch request that should expire sometime later. |
834 version_->DispatchFetchEvent(ServiceWorkerFetchRequest(), | 834 version_->DispatchFetchEvent(ServiceWorkerFetchRequest(), |
835 base::Bind(&base::DoNothing), | 835 base::Bind(&base::DoNothing), |
836 base::Bind(&ReceiveFetchResult, &fetch_status)); | 836 base::Bind(&ReceiveFetchResult, &fetch_status)); |
837 // Create a sync request that should expire Now(). | 837 // Create a sync request that should expire Now(). |
838 version_->DispatchSyncEvent(0 /* sync handle id */, | 838 version_->DispatchSyncEvent(0 /* sync handle id */, |
839 BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_LAST_CHANCE, | 839 BackgroundSyncEventLastChance::IS_LAST_CHANCE, |
840 base::TimeDelta(), /* max duration */ | 840 base::TimeDelta(), /* max duration */ |
841 base::Bind(&ReceiveSyncStatus, &sync_status)); | 841 base::Bind(&ReceiveSyncStatus, &sync_status)); |
842 base::RunLoop().RunUntilIdle(); | 842 base::RunLoop().RunUntilIdle(); |
843 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, sync_status); | 843 EXPECT_EQ(SERVICE_WORKER_ERROR_NETWORK, sync_status); |
844 | 844 |
845 // Verify the sync has timed out but not the fetch. | 845 // Verify the sync has timed out but not the fetch. |
846 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); | 846 EXPECT_TRUE(version_->timeout_timer_.IsRunning()); |
847 version_->timeout_timer_.user_task().Run(); | 847 version_->timeout_timer_.user_task().Run(); |
848 base::RunLoop().RunUntilIdle(); | 848 base::RunLoop().RunUntilIdle(); |
849 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, sync_status); | 849 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, sync_status); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 GURL valid_scope_2("http://www.example.com/test/subscope"); | 1035 GURL valid_scope_2("http://www.example.com/test/subscope"); |
1036 version_->OnRegisterForeignFetchScopes(std::vector<GURL>(1, valid_scope_2)); | 1036 version_->OnRegisterForeignFetchScopes(std::vector<GURL>(1, valid_scope_2)); |
1037 base::RunLoop().RunUntilIdle(); | 1037 base::RunLoop().RunUntilIdle(); |
1038 EXPECT_EQ(3, helper_->mock_render_process_host()->bad_msg_count()); | 1038 EXPECT_EQ(3, helper_->mock_render_process_host()->bad_msg_count()); |
1039 EXPECT_EQ(2u, version_->foreign_fetch_scopes_.size()); | 1039 EXPECT_EQ(2u, version_->foreign_fetch_scopes_.size()); |
1040 EXPECT_EQ(valid_scope_1, version_->foreign_fetch_scopes_[0]); | 1040 EXPECT_EQ(valid_scope_1, version_->foreign_fetch_scopes_[0]); |
1041 EXPECT_EQ(valid_scope_2, version_->foreign_fetch_scopes_[1]); | 1041 EXPECT_EQ(valid_scope_2, version_->foreign_fetch_scopes_[1]); |
1042 } | 1042 } |
1043 | 1043 |
1044 } // namespace content | 1044 } // namespace content |
OLD | NEW |