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 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 ChangedVersionAttributesMask mask; | 887 ChangedVersionAttributesMask mask; |
888 ServiceWorkerRegistrationInfo info; | 888 ServiceWorkerRegistrationInfo info; |
889 }; | 889 }; |
890 | 890 |
891 struct StateChangeLogEntry { | 891 struct StateChangeLogEntry { |
892 int64 version_id; | 892 int64 version_id; |
893 ServiceWorkerVersion::Status status; | 893 ServiceWorkerVersion::Status status; |
894 }; | 894 }; |
895 | 895 |
896 UpdateJobTestHelper(int mock_render_process_id) | 896 UpdateJobTestHelper(int mock_render_process_id) |
897 : EmbeddedWorkerTestHelper(mock_render_process_id) {} | 897 : EmbeddedWorkerTestHelper(mock_render_process_id), |
| 898 update_found_(false) {} |
898 virtual ~UpdateJobTestHelper() { | 899 virtual ~UpdateJobTestHelper() { |
899 if (registration_.get()) | 900 if (registration_.get()) |
900 registration_->RemoveListener(this); | 901 registration_->RemoveListener(this); |
901 } | 902 } |
902 | 903 |
903 ServiceWorkerStorage* storage() { return context()->storage(); } | 904 ServiceWorkerStorage* storage() { return context()->storage(); } |
904 ServiceWorkerJobCoordinator* job_coordinator() { | 905 ServiceWorkerJobCoordinator* job_coordinator() { |
905 return context()->job_coordinator(); | 906 return context()->job_coordinator(); |
906 } | 907 } |
907 | 908 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 entry.mask = changed_mask; | 966 entry.mask = changed_mask; |
966 entry.info = info; | 967 entry.info = info; |
967 attribute_change_log_.push_back(entry); | 968 attribute_change_log_.push_back(entry); |
968 } | 969 } |
969 | 970 |
970 virtual void OnRegistrationFailed( | 971 virtual void OnRegistrationFailed( |
971 ServiceWorkerRegistration* registration) OVERRIDE { | 972 ServiceWorkerRegistration* registration) OVERRIDE { |
972 NOTREACHED(); | 973 NOTREACHED(); |
973 } | 974 } |
974 | 975 |
| 976 virtual void OnRegistrationFinishedUninstalling( |
| 977 ServiceWorkerRegistration* registration) OVERRIDE { |
| 978 NOTREACHED(); |
| 979 } |
| 980 |
| 981 virtual void OnUpdateFound( |
| 982 ServiceWorkerRegistration* registration) OVERRIDE { |
| 983 ASSERT_FALSE(update_found_); |
| 984 update_found_ = true; |
| 985 } |
| 986 |
975 // ServiceWorkerVersion::Listener overrides | 987 // ServiceWorkerVersion::Listener overrides |
976 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) OVERRIDE { | 988 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) OVERRIDE { |
977 StateChangeLogEntry entry; | 989 StateChangeLogEntry entry; |
978 entry.version_id = version->version_id(); | 990 entry.version_id = version->version_id(); |
979 entry.status = version->status(); | 991 entry.status = version->status(); |
980 state_change_log_.push_back(entry); | 992 state_change_log_.push_back(entry); |
981 } | 993 } |
982 | 994 |
983 scoped_refptr<ServiceWorkerRegistration> registration_; | 995 scoped_refptr<ServiceWorkerRegistration> registration_; |
984 | 996 |
985 std::vector<AttributeChangeLogEntry> attribute_change_log_; | 997 std::vector<AttributeChangeLogEntry> attribute_change_log_; |
986 std::vector<StateChangeLogEntry> state_change_log_; | 998 std::vector<StateChangeLogEntry> state_change_log_; |
| 999 bool update_found_; |
987 }; | 1000 }; |
988 | 1001 |
989 } // namespace | 1002 } // namespace |
990 | 1003 |
991 TEST_F(ServiceWorkerJobTest, Update_NoChange) { | 1004 TEST_F(ServiceWorkerJobTest, Update_NoChange) { |
992 UpdateJobTestHelper* update_helper = | 1005 UpdateJobTestHelper* update_helper = |
993 new UpdateJobTestHelper(render_process_id_); | 1006 new UpdateJobTestHelper(render_process_id_); |
994 helper_.reset(update_helper); | 1007 helper_.reset(update_helper); |
995 scoped_refptr<ServiceWorkerRegistration> registration = | 1008 scoped_refptr<ServiceWorkerRegistration> registration = |
996 update_helper->SetupInitialRegistration(kNoChangeOrigin); | 1009 update_helper->SetupInitialRegistration(kNoChangeOrigin); |
(...skipping 20 matching lines...) Expand all Loading... |
1017 ASSERT_TRUE(registration->active_version()); | 1030 ASSERT_TRUE(registration->active_version()); |
1018 EXPECT_EQ(first_version.get(), registration->active_version()); | 1031 EXPECT_EQ(first_version.get(), registration->active_version()); |
1019 EXPECT_FALSE(registration->installing_version()); | 1032 EXPECT_FALSE(registration->installing_version()); |
1020 EXPECT_FALSE(registration->waiting_version()); | 1033 EXPECT_FALSE(registration->waiting_version()); |
1021 EXPECT_TRUE(update_helper->attribute_change_log_.empty()); | 1034 EXPECT_TRUE(update_helper->attribute_change_log_.empty()); |
1022 ASSERT_EQ(1u, update_helper->state_change_log_.size()); | 1035 ASSERT_EQ(1u, update_helper->state_change_log_.size()); |
1023 EXPECT_NE(registration->active_version()->version_id(), | 1036 EXPECT_NE(registration->active_version()->version_id(), |
1024 update_helper->state_change_log_[0].version_id); | 1037 update_helper->state_change_log_[0].version_id); |
1025 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, | 1038 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, |
1026 update_helper->state_change_log_[0].status); | 1039 update_helper->state_change_log_[0].status); |
| 1040 EXPECT_FALSE(update_helper->update_found_); |
1027 } | 1041 } |
1028 | 1042 |
1029 TEST_F(ServiceWorkerJobTest, Update_NewVersion) { | 1043 TEST_F(ServiceWorkerJobTest, Update_NewVersion) { |
1030 UpdateJobTestHelper* update_helper = | 1044 UpdateJobTestHelper* update_helper = |
1031 new UpdateJobTestHelper(render_process_id_); | 1045 new UpdateJobTestHelper(render_process_id_); |
1032 helper_.reset(update_helper); | 1046 helper_.reset(update_helper); |
1033 scoped_refptr<ServiceWorkerRegistration> registration = | 1047 scoped_refptr<ServiceWorkerRegistration> registration = |
1034 update_helper->SetupInitialRegistration(kNewVersionOrigin); | 1048 update_helper->SetupInitialRegistration(kNewVersionOrigin); |
1035 ASSERT_TRUE(registration.get()); | 1049 ASSERT_TRUE(registration.get()); |
1036 update_helper->state_change_log_.clear(); | 1050 update_helper->state_change_log_.clear(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 | 1111 |
1098 EXPECT_EQ(registration->active_version()->version_id(), | 1112 EXPECT_EQ(registration->active_version()->version_id(), |
1099 update_helper->state_change_log_[3].version_id); | 1113 update_helper->state_change_log_[3].version_id); |
1100 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, | 1114 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, |
1101 update_helper->state_change_log_[3].status); | 1115 update_helper->state_change_log_[3].status); |
1102 | 1116 |
1103 EXPECT_EQ(registration->active_version()->version_id(), | 1117 EXPECT_EQ(registration->active_version()->version_id(), |
1104 update_helper->state_change_log_[4].version_id); | 1118 update_helper->state_change_log_[4].version_id); |
1105 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 1119 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, |
1106 update_helper->state_change_log_[4].status); | 1120 update_helper->state_change_log_[4].status); |
| 1121 |
| 1122 EXPECT_TRUE(update_helper->update_found_); |
1107 } | 1123 } |
1108 | 1124 |
1109 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { | 1125 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { |
1110 bool called; | 1126 bool called; |
1111 scoped_refptr<ServiceWorkerRegistration> registration; | 1127 scoped_refptr<ServiceWorkerRegistration> registration; |
1112 job_coordinator()->Register( | 1128 job_coordinator()->Register( |
1113 GURL("http://www.example.com/one/"), | 1129 GURL("http://www.example.com/one/"), |
1114 GURL("http://www.example.com/service_worker.js"), | 1130 GURL("http://www.example.com/service_worker.js"), |
1115 render_process_id_, | 1131 render_process_id_, |
1116 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 1132 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 EXPECT_TRUE(called); | 1187 EXPECT_TRUE(called); |
1172 | 1188 |
1173 // Verify the registration was not modified by the Update. | 1189 // Verify the registration was not modified by the Update. |
1174 EXPECT_TRUE(registration->is_uninstalling()); | 1190 EXPECT_TRUE(registration->is_uninstalling()); |
1175 EXPECT_EQ(active_version, registration->active_version()); | 1191 EXPECT_EQ(active_version, registration->active_version()); |
1176 EXPECT_EQ(NULL, registration->waiting_version()); | 1192 EXPECT_EQ(NULL, registration->waiting_version()); |
1177 EXPECT_EQ(NULL, registration->installing_version()); | 1193 EXPECT_EQ(NULL, registration->installing_version()); |
1178 } | 1194 } |
1179 | 1195 |
1180 } // namespace content | 1196 } // namespace content |
OLD | NEW |