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/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 ServiceWorkerRegistrationInfo info; | 889 ServiceWorkerRegistrationInfo info; |
890 }; | 890 }; |
891 | 891 |
892 struct StateChangeLogEntry { | 892 struct StateChangeLogEntry { |
893 int64 version_id; | 893 int64 version_id; |
894 ServiceWorkerVersion::Status status; | 894 ServiceWorkerVersion::Status status; |
895 }; | 895 }; |
896 | 896 |
897 UpdateJobTestHelper(int mock_render_process_id) | 897 UpdateJobTestHelper(int mock_render_process_id) |
898 : EmbeddedWorkerTestHelper(mock_render_process_id) {} | 898 : EmbeddedWorkerTestHelper(mock_render_process_id) {} |
| 899 virtual ~UpdateJobTestHelper() { |
| 900 if (registration_) |
| 901 registration_->RemoveListener(this); |
| 902 } |
899 | 903 |
900 ServiceWorkerStorage* storage() { return context()->storage(); } | 904 ServiceWorkerStorage* storage() { return context()->storage(); } |
901 ServiceWorkerJobCoordinator* job_coordinator() { | 905 ServiceWorkerJobCoordinator* job_coordinator() { |
902 return context()->job_coordinator(); | 906 return context()->job_coordinator(); |
903 } | 907 } |
904 | 908 |
905 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration( | 909 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration( |
906 const GURL& test_origin) { | 910 const GURL& test_origin) { |
907 scoped_refptr<ServiceWorkerRegistration> registration; | 911 scoped_refptr<ServiceWorkerRegistration> registration; |
908 bool called = false; | 912 bool called = false; |
909 job_coordinator()->Register( | 913 job_coordinator()->Register( |
910 test_origin.Resolve(kScope), | 914 test_origin.Resolve(kScope), |
911 test_origin.Resolve(kScript), | 915 test_origin.Resolve(kScript), |
912 mock_render_process_id(), | 916 mock_render_process_id(), |
913 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 917 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
914 base::RunLoop().RunUntilIdle(); | 918 base::RunLoop().RunUntilIdle(); |
915 EXPECT_TRUE(called); | 919 EXPECT_TRUE(called); |
916 EXPECT_TRUE(registration); | 920 EXPECT_TRUE(registration); |
917 EXPECT_TRUE(registration->active_version()); | 921 EXPECT_TRUE(registration->active_version()); |
918 EXPECT_FALSE(registration->installing_version()); | 922 EXPECT_FALSE(registration->installing_version()); |
919 EXPECT_FALSE(registration->waiting_version()); | 923 EXPECT_FALSE(registration->waiting_version()); |
| 924 registration_ = registration; |
920 return registration; | 925 return registration; |
921 } | 926 } |
922 | 927 |
923 // EmbeddedWorkerTestHelper overrides | 928 // EmbeddedWorkerTestHelper overrides |
924 virtual void OnStartWorker(int embedded_worker_id, | 929 virtual void OnStartWorker(int embedded_worker_id, |
925 int64 version_id, | 930 int64 version_id, |
926 const GURL& scope, | 931 const GURL& scope, |
927 const GURL& script, | 932 const GURL& script, |
928 bool pause_after_download) OVERRIDE { | 933 bool pause_after_download) OVERRIDE { |
929 const std::string kMockScriptBody = "mock_script"; | 934 const std::string kMockScriptBody = "mock_script"; |
(...skipping 26 matching lines...) Expand all Loading... |
956 ServiceWorkerRegistration* registration, | 961 ServiceWorkerRegistration* registration, |
957 ChangedVersionAttributesMask changed_mask, | 962 ChangedVersionAttributesMask changed_mask, |
958 const ServiceWorkerRegistrationInfo& info) OVERRIDE { | 963 const ServiceWorkerRegistrationInfo& info) OVERRIDE { |
959 AttributeChangeLogEntry entry; | 964 AttributeChangeLogEntry entry; |
960 entry.registration_id = registration->id(); | 965 entry.registration_id = registration->id(); |
961 entry.mask = changed_mask; | 966 entry.mask = changed_mask; |
962 entry.info = info; | 967 entry.info = info; |
963 attribute_change_log_.push_back(entry); | 968 attribute_change_log_.push_back(entry); |
964 } | 969 } |
965 | 970 |
| 971 virtual void OnRegistrationFailed( |
| 972 ServiceWorkerRegistration* registration) OVERRIDE { |
| 973 NOTREACHED(); |
| 974 } |
| 975 |
966 // ServiceWorkerVersion::Listener overrides | 976 // ServiceWorkerVersion::Listener overrides |
967 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) OVERRIDE { | 977 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) OVERRIDE { |
968 StateChangeLogEntry entry; | 978 StateChangeLogEntry entry; |
969 entry.version_id = version->version_id(); | 979 entry.version_id = version->version_id(); |
970 entry.status = version->status(); | 980 entry.status = version->status(); |
971 state_change_log_.push_back(entry); | 981 state_change_log_.push_back(entry); |
972 } | 982 } |
973 | 983 |
| 984 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 985 |
974 std::vector<AttributeChangeLogEntry> attribute_change_log_; | 986 std::vector<AttributeChangeLogEntry> attribute_change_log_; |
975 std::vector<StateChangeLogEntry> state_change_log_; | 987 std::vector<StateChangeLogEntry> state_change_log_; |
976 }; | 988 }; |
977 | 989 |
978 } // namespace | 990 } // namespace |
979 | 991 |
980 TEST_F(ServiceWorkerJobTest, Update_NoChange) { | 992 TEST_F(ServiceWorkerJobTest, Update_NoChange) { |
981 UpdateJobTestHelper* update_helper = | 993 UpdateJobTestHelper* update_helper = |
982 new UpdateJobTestHelper(render_process_id_); | 994 new UpdateJobTestHelper(render_process_id_); |
983 helper_.reset(update_helper); | 995 helper_.reset(update_helper); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, | 1101 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, |
1090 update_helper->state_change_log_[3].status); | 1102 update_helper->state_change_log_[3].status); |
1091 | 1103 |
1092 EXPECT_EQ(registration->active_version()->version_id(), | 1104 EXPECT_EQ(registration->active_version()->version_id(), |
1093 update_helper->state_change_log_[4].version_id); | 1105 update_helper->state_change_log_[4].version_id); |
1094 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 1106 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, |
1095 update_helper->state_change_log_[4].status); | 1107 update_helper->state_change_log_[4].status); |
1096 } | 1108 } |
1097 | 1109 |
1098 } // namespace content | 1110 } // namespace content |
OLD | NEW |