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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 353 |
354 ASSERT_EQ(new_registration, old_registration); | 354 ASSERT_EQ(new_registration, old_registration); |
355 } | 355 } |
356 | 356 |
357 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { | 357 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { |
358 public: | 358 public: |
359 explicit FailToStartWorkerTestHelper(int mock_render_process_id) | 359 explicit FailToStartWorkerTestHelper(int mock_render_process_id) |
360 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id) {} | 360 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id) {} |
361 | 361 |
362 void OnStartWorker(int embedded_worker_id, | 362 void OnStartWorker(int embedded_worker_id, |
363 int64 service_worker_version_id, | 363 std::string service_worker_version_uuid, |
364 const GURL& scope, | 364 const GURL& scope, |
365 const GURL& script_url, | 365 const GURL& script_url, |
366 bool pause_after_download) override { | 366 bool pause_after_download) override { |
367 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 367 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
368 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 368 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); |
369 } | 369 } |
370 }; | 370 }; |
371 | 371 |
372 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { | 372 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { |
373 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); | 373 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 // unregistration. | 634 // unregistration. |
635 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { | 635 TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { |
636 GURL script_url("http://www.example.com/service_worker.js"); | 636 GURL script_url("http://www.example.com/service_worker.js"); |
637 scoped_refptr<ServiceWorkerRegistration> registration = | 637 scoped_refptr<ServiceWorkerRegistration> registration = |
638 RunRegisterJob(GURL("http://www.example.com/"), script_url); | 638 RunRegisterJob(GURL("http://www.example.com/"), script_url); |
639 ASSERT_TRUE(registration.get()); | 639 ASSERT_TRUE(registration.get()); |
640 | 640 |
641 // Manually create the waiting worker since there is no way to become a | 641 // Manually create the waiting worker since there is no way to become a |
642 // waiting worker until Update is implemented. | 642 // waiting worker until Update is implemented. |
643 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( | 643 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
644 registration.get(), script_url, 1L, helper_->context()->AsWeakPtr()); | 644 registration.get(), script_url, |
| 645 std::string("2939b50b-fc8d-46ad-86e4-b4295b8fbc86"), |
| 646 helper_->context()->AsWeakPtr()); |
645 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 647 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
646 version->StartWorker(CreateReceiverOnCurrentThread(&status)); | 648 version->StartWorker(CreateReceiverOnCurrentThread(&status)); |
647 base::RunLoop().RunUntilIdle(); | 649 base::RunLoop().RunUntilIdle(); |
648 ASSERT_EQ(SERVICE_WORKER_OK, status); | 650 ASSERT_EQ(SERVICE_WORKER_OK, status); |
649 | 651 |
650 version->SetStatus(ServiceWorkerVersion::INSTALLED); | 652 version->SetStatus(ServiceWorkerVersion::INSTALLED); |
651 registration->SetWaitingVersion(version); | 653 registration->SetWaitingVersion(version); |
652 EXPECT_EQ(ServiceWorkerVersion::RUNNING, | 654 EXPECT_EQ(ServiceWorkerVersion::RUNNING, |
653 version->running_status()); | 655 version->running_status()); |
654 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); | 656 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 public ServiceWorkerRegistration::Listener, | 771 public ServiceWorkerRegistration::Listener, |
770 public ServiceWorkerVersion::Listener { | 772 public ServiceWorkerVersion::Listener { |
771 public: | 773 public: |
772 struct AttributeChangeLogEntry { | 774 struct AttributeChangeLogEntry { |
773 int64 registration_id; | 775 int64 registration_id; |
774 ChangedVersionAttributesMask mask; | 776 ChangedVersionAttributesMask mask; |
775 ServiceWorkerRegistrationInfo info; | 777 ServiceWorkerRegistrationInfo info; |
776 }; | 778 }; |
777 | 779 |
778 struct StateChangeLogEntry { | 780 struct StateChangeLogEntry { |
779 int64 version_id; | 781 std::string version_uuid; |
780 ServiceWorkerVersion::Status status; | 782 ServiceWorkerVersion::Status status; |
781 }; | 783 }; |
782 | 784 |
783 UpdateJobTestHelper(int mock_render_process_id) | 785 UpdateJobTestHelper(int mock_render_process_id) |
784 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id), | 786 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id), |
785 update_found_(false) {} | 787 update_found_(false) {} |
786 ~UpdateJobTestHelper() override { | 788 ~UpdateJobTestHelper() override { |
787 if (registration_.get()) | 789 if (registration_.get()) |
788 registration_->RemoveListener(this); | 790 registration_->RemoveListener(this); |
789 } | 791 } |
(...skipping 17 matching lines...) Expand all Loading... |
807 EXPECT_TRUE(registration.get()); | 809 EXPECT_TRUE(registration.get()); |
808 EXPECT_TRUE(registration->active_version()); | 810 EXPECT_TRUE(registration->active_version()); |
809 EXPECT_FALSE(registration->installing_version()); | 811 EXPECT_FALSE(registration->installing_version()); |
810 EXPECT_FALSE(registration->waiting_version()); | 812 EXPECT_FALSE(registration->waiting_version()); |
811 registration_ = registration; | 813 registration_ = registration; |
812 return registration; | 814 return registration; |
813 } | 815 } |
814 | 816 |
815 // EmbeddedWorkerTestHelper overrides | 817 // EmbeddedWorkerTestHelper overrides |
816 void OnStartWorker(int embedded_worker_id, | 818 void OnStartWorker(int embedded_worker_id, |
817 int64 version_id, | 819 std::string version_uuid, |
818 const GURL& scope, | 820 const GURL& scope, |
819 const GURL& script, | 821 const GURL& script, |
820 bool pause_after_download) override { | 822 bool pause_after_download) override { |
821 const std::string kMockScriptBody = "mock_script"; | 823 const std::string kMockScriptBody = "mock_script"; |
822 const uint64 kMockScriptSize = 19284; | 824 const uint64 kMockScriptSize = 19284; |
823 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 825 ServiceWorkerVersion* version = context()->GetLiveVersion(version_uuid); |
824 ASSERT_TRUE(version); | 826 ASSERT_TRUE(version); |
825 version->AddListener(this); | 827 version->AddListener(this); |
826 | 828 |
827 if (!pause_after_download) { | 829 if (!pause_after_download) { |
828 // Spoof caching the script for the initial version. | 830 // Spoof caching the script for the initial version. |
829 int64 resource_id = storage()->NewResourceId(); | 831 int64 resource_id = storage()->NewResourceId(); |
830 version->script_cache_map()->NotifyStartedCaching(script, resource_id); | 832 version->script_cache_map()->NotifyStartedCaching(script, resource_id); |
831 WriteStringResponse(storage(), resource_id, kMockScriptBody); | 833 WriteStringResponse(storage(), resource_id, kMockScriptBody); |
832 version->script_cache_map()->NotifyFinishedCaching( | 834 version->script_cache_map()->NotifyFinishedCaching( |
833 script, kMockScriptSize, net::URLRequestStatus(), std::string()); | 835 script, kMockScriptSize, net::URLRequestStatus(), std::string()); |
834 } else { | 836 } else { |
835 // Spoof caching the script for the new version. | 837 // Spoof caching the script for the new version. |
836 int64 resource_id = storage()->NewResourceId(); | 838 int64 resource_id = storage()->NewResourceId(); |
837 version->script_cache_map()->NotifyStartedCaching(script, resource_id); | 839 version->script_cache_map()->NotifyStartedCaching(script, resource_id); |
838 if (script.GetOrigin() == kNoChangeOrigin) | 840 if (script.GetOrigin() == kNoChangeOrigin) |
839 WriteStringResponse(storage(), resource_id, kMockScriptBody); | 841 WriteStringResponse(storage(), resource_id, kMockScriptBody); |
840 else | 842 else |
841 WriteStringResponse(storage(), resource_id, "mock_different_script"); | 843 WriteStringResponse(storage(), resource_id, "mock_different_script"); |
842 version->script_cache_map()->NotifyFinishedCaching( | 844 version->script_cache_map()->NotifyFinishedCaching( |
843 script, kMockScriptSize, net::URLRequestStatus(), std::string()); | 845 script, kMockScriptSize, net::URLRequestStatus(), std::string()); |
844 } | 846 } |
845 EmbeddedWorkerTestHelper::OnStartWorker( | 847 EmbeddedWorkerTestHelper::OnStartWorker( |
846 embedded_worker_id, version_id, scope, script, pause_after_download); | 848 embedded_worker_id, version_uuid, scope, script, pause_after_download); |
847 } | 849 } |
848 | 850 |
849 // ServiceWorkerRegistration::Listener overrides | 851 // ServiceWorkerRegistration::Listener overrides |
850 void OnVersionAttributesChanged( | 852 void OnVersionAttributesChanged( |
851 ServiceWorkerRegistration* registration, | 853 ServiceWorkerRegistration* registration, |
852 ChangedVersionAttributesMask changed_mask, | 854 ChangedVersionAttributesMask changed_mask, |
853 const ServiceWorkerRegistrationInfo& info) override { | 855 const ServiceWorkerRegistrationInfo& info) override { |
854 AttributeChangeLogEntry entry; | 856 AttributeChangeLogEntry entry; |
855 entry.registration_id = registration->id(); | 857 entry.registration_id = registration->id(); |
856 entry.mask = changed_mask; | 858 entry.mask = changed_mask; |
857 entry.info = info; | 859 entry.info = info; |
858 attribute_change_log_.push_back(entry); | 860 attribute_change_log_.push_back(entry); |
859 } | 861 } |
860 | 862 |
861 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { | 863 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { |
862 NOTREACHED(); | 864 NOTREACHED(); |
863 } | 865 } |
864 | 866 |
865 void OnUpdateFound(ServiceWorkerRegistration* registration) override { | 867 void OnUpdateFound(ServiceWorkerRegistration* registration) override { |
866 ASSERT_FALSE(update_found_); | 868 ASSERT_FALSE(update_found_); |
867 update_found_ = true; | 869 update_found_ = true; |
868 } | 870 } |
869 | 871 |
870 // ServiceWorkerVersion::Listener overrides | 872 // ServiceWorkerVersion::Listener overrides |
871 void OnVersionStateChanged(ServiceWorkerVersion* version) override { | 873 void OnVersionStateChanged(ServiceWorkerVersion* version) override { |
872 StateChangeLogEntry entry; | 874 StateChangeLogEntry entry; |
873 entry.version_id = version->version_id(); | 875 entry.version_uuid = version->version_uuid(); |
874 entry.status = version->status(); | 876 entry.status = version->status(); |
875 state_change_log_.push_back(entry); | 877 state_change_log_.push_back(entry); |
876 } | 878 } |
877 | 879 |
878 scoped_refptr<ServiceWorkerRegistration> registration_; | 880 scoped_refptr<ServiceWorkerRegistration> registration_; |
879 | 881 |
880 std::vector<AttributeChangeLogEntry> attribute_change_log_; | 882 std::vector<AttributeChangeLogEntry> attribute_change_log_; |
881 std::vector<StateChangeLogEntry> state_change_log_; | 883 std::vector<StateChangeLogEntry> state_change_log_; |
882 bool update_found_; | 884 bool update_found_; |
883 }; | 885 }; |
884 | 886 |
885 // Helper class for update tests that evicts the active version when the update | 887 // Helper class for update tests that evicts the active version when the update |
886 // worker is about to be started. | 888 // worker is about to be started. |
887 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { | 889 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { |
888 public: | 890 public: |
889 EvictIncumbentVersionHelper(int mock_render_process_id) | 891 EvictIncumbentVersionHelper(int mock_render_process_id) |
890 : UpdateJobTestHelper(mock_render_process_id) {} | 892 : UpdateJobTestHelper(mock_render_process_id) {} |
891 ~EvictIncumbentVersionHelper() override {} | 893 ~EvictIncumbentVersionHelper() override {} |
892 | 894 |
893 void OnStartWorker(int embedded_worker_id, | 895 void OnStartWorker(int embedded_worker_id, |
894 int64 version_id, | 896 std::string version_uuid, |
895 const GURL& scope, | 897 const GURL& scope, |
896 const GURL& script, | 898 const GURL& script, |
897 bool pause_after_download) override { | 899 bool pause_after_download) override { |
898 if (pause_after_download) { | 900 if (pause_after_download) { |
899 // Evict the incumbent worker. | 901 // Evict the incumbent worker. |
900 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); | 902 ServiceWorkerVersion* version = context()->GetLiveVersion(version_uuid); |
901 ASSERT_TRUE(version); | 903 ASSERT_TRUE(version); |
902 ServiceWorkerRegistration* registration = | 904 ServiceWorkerRegistration* registration = |
903 context()->GetLiveRegistration(version->registration_id()); | 905 context()->GetLiveRegistration(version->registration_id()); |
904 ASSERT_TRUE(registration); | 906 ASSERT_TRUE(registration); |
905 ASSERT_TRUE(registration->active_version()); | 907 ASSERT_TRUE(registration->active_version()); |
906 ASSERT_FALSE(registration->waiting_version()); | 908 ASSERT_FALSE(registration->waiting_version()); |
907 registration->DeleteVersion( | 909 registration->DeleteVersion( |
908 make_scoped_refptr(registration->active_version())); | 910 make_scoped_refptr(registration->active_version())); |
909 } | 911 } |
910 UpdateJobTestHelper::OnStartWorker(embedded_worker_id, version_id, scope, | 912 UpdateJobTestHelper::OnStartWorker(embedded_worker_id, version_uuid, scope, |
911 script, pause_after_download); | 913 script, pause_after_download); |
912 } | 914 } |
913 | 915 |
914 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { | 916 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { |
915 registration_failed_ = true; | 917 registration_failed_ = true; |
916 } | 918 } |
917 | 919 |
918 bool registration_failed_ = false; | 920 bool registration_failed_ = false; |
919 }; | 921 }; |
920 | 922 |
(...skipping 24 matching lines...) Expand all Loading... |
945 first_version->StartUpdate(); | 947 first_version->StartUpdate(); |
946 base::RunLoop().RunUntilIdle(); | 948 base::RunLoop().RunUntilIdle(); |
947 | 949 |
948 // Verify results. | 950 // Verify results. |
949 ASSERT_TRUE(registration->active_version()); | 951 ASSERT_TRUE(registration->active_version()); |
950 EXPECT_EQ(first_version.get(), registration->active_version()); | 952 EXPECT_EQ(first_version.get(), registration->active_version()); |
951 EXPECT_FALSE(registration->installing_version()); | 953 EXPECT_FALSE(registration->installing_version()); |
952 EXPECT_FALSE(registration->waiting_version()); | 954 EXPECT_FALSE(registration->waiting_version()); |
953 EXPECT_TRUE(update_helper->attribute_change_log_.empty()); | 955 EXPECT_TRUE(update_helper->attribute_change_log_.empty()); |
954 ASSERT_EQ(1u, update_helper->state_change_log_.size()); | 956 ASSERT_EQ(1u, update_helper->state_change_log_.size()); |
955 EXPECT_NE(registration->active_version()->version_id(), | 957 EXPECT_NE(registration->active_version()->version_uuid(), |
956 update_helper->state_change_log_[0].version_id); | 958 update_helper->state_change_log_[0].version_uuid); |
957 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, | 959 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, |
958 update_helper->state_change_log_[0].status); | 960 update_helper->state_change_log_[0].status); |
959 EXPECT_FALSE(update_helper->update_found_); | 961 EXPECT_FALSE(update_helper->update_found_); |
960 } | 962 } |
961 | 963 |
962 TEST_F(ServiceWorkerJobTest, Update_NewVersion) { | 964 TEST_F(ServiceWorkerJobTest, Update_NewVersion) { |
963 UpdateJobTestHelper* update_helper = | 965 UpdateJobTestHelper* update_helper = |
964 new UpdateJobTestHelper(render_process_id_); | 966 new UpdateJobTestHelper(render_process_id_); |
965 helper_.reset(update_helper); | 967 helper_.reset(update_helper); |
966 scoped_refptr<ServiceWorkerRegistration> registration = | 968 scoped_refptr<ServiceWorkerRegistration> registration = |
(...skipping 13 matching lines...) Expand all Loading... |
980 EXPECT_NE(first_version.get(), registration->active_version()); | 982 EXPECT_NE(first_version.get(), registration->active_version()); |
981 EXPECT_FALSE(registration->installing_version()); | 983 EXPECT_FALSE(registration->installing_version()); |
982 EXPECT_FALSE(registration->waiting_version()); | 984 EXPECT_FALSE(registration->waiting_version()); |
983 ASSERT_EQ(3u, update_helper->attribute_change_log_.size()); | 985 ASSERT_EQ(3u, update_helper->attribute_change_log_.size()); |
984 | 986 |
985 UpdateJobTestHelper::AttributeChangeLogEntry entry; | 987 UpdateJobTestHelper::AttributeChangeLogEntry entry; |
986 entry = update_helper->attribute_change_log_[0]; | 988 entry = update_helper->attribute_change_log_[0]; |
987 EXPECT_TRUE(entry.mask.installing_changed()); | 989 EXPECT_TRUE(entry.mask.installing_changed()); |
988 EXPECT_FALSE(entry.mask.waiting_changed()); | 990 EXPECT_FALSE(entry.mask.waiting_changed()); |
989 EXPECT_FALSE(entry.mask.active_changed()); | 991 EXPECT_FALSE(entry.mask.active_changed()); |
990 EXPECT_NE(entry.info.installing_version.version_id, | 992 EXPECT_FALSE(entry.info.installing_version.version_uuid.empty()); |
991 kInvalidServiceWorkerVersionId); | 993 EXPECT_TRUE(entry.info.waiting_version.version_uuid.empty()); |
992 EXPECT_EQ(entry.info.waiting_version.version_id, | 994 EXPECT_FALSE(entry.info.active_version.version_uuid.empty()); |
993 kInvalidServiceWorkerVersionId); | |
994 EXPECT_NE(entry.info.active_version.version_id, | |
995 kInvalidServiceWorkerVersionId); | |
996 | 995 |
997 entry = update_helper->attribute_change_log_[1]; | 996 entry = update_helper->attribute_change_log_[1]; |
998 EXPECT_TRUE(entry.mask.installing_changed()); | 997 EXPECT_TRUE(entry.mask.installing_changed()); |
999 EXPECT_TRUE(entry.mask.waiting_changed()); | 998 EXPECT_TRUE(entry.mask.waiting_changed()); |
1000 EXPECT_FALSE(entry.mask.active_changed()); | 999 EXPECT_FALSE(entry.mask.active_changed()); |
1001 EXPECT_EQ(entry.info.installing_version.version_id, | 1000 EXPECT_TRUE(entry.info.installing_version.version_uuid.empty()); |
1002 kInvalidServiceWorkerVersionId); | 1001 EXPECT_FALSE(entry.info.waiting_version.version_uuid.empty()); |
1003 EXPECT_NE(entry.info.waiting_version.version_id, | 1002 EXPECT_FALSE(entry.info.active_version.version_uuid.empty()); |
1004 kInvalidServiceWorkerVersionId); | |
1005 EXPECT_NE(entry.info.active_version.version_id, | |
1006 kInvalidServiceWorkerVersionId); | |
1007 | 1003 |
1008 entry = update_helper->attribute_change_log_[2]; | 1004 entry = update_helper->attribute_change_log_[2]; |
1009 EXPECT_FALSE(entry.mask.installing_changed()); | 1005 EXPECT_FALSE(entry.mask.installing_changed()); |
1010 EXPECT_TRUE(entry.mask.waiting_changed()); | 1006 EXPECT_TRUE(entry.mask.waiting_changed()); |
1011 EXPECT_TRUE(entry.mask.active_changed()); | 1007 EXPECT_TRUE(entry.mask.active_changed()); |
1012 EXPECT_EQ(entry.info.installing_version.version_id, | 1008 EXPECT_TRUE(entry.info.installing_version.version_uuid.empty()); |
1013 kInvalidServiceWorkerVersionId); | 1009 EXPECT_TRUE(entry.info.waiting_version.version_uuid.empty()); |
1014 EXPECT_EQ(entry.info.waiting_version.version_id, | 1010 EXPECT_FALSE(entry.info.active_version.version_uuid.empty()); |
1015 kInvalidServiceWorkerVersionId); | |
1016 EXPECT_NE(entry.info.active_version.version_id, | |
1017 kInvalidServiceWorkerVersionId); | |
1018 | 1011 |
1019 // expected version state transitions: | 1012 // expected version state transitions: |
1020 // new.installing, new.installed, | 1013 // new.installing, new.installed, |
1021 // old.redundant, | 1014 // old.redundant, |
1022 // new.activating, new.activated | 1015 // new.activating, new.activated |
1023 ASSERT_EQ(5u, update_helper->state_change_log_.size()); | 1016 ASSERT_EQ(5u, update_helper->state_change_log_.size()); |
1024 | 1017 |
1025 EXPECT_EQ(registration->active_version()->version_id(), | 1018 EXPECT_EQ(registration->active_version()->version_uuid(), |
1026 update_helper->state_change_log_[0].version_id); | 1019 update_helper->state_change_log_[0].version_uuid); |
1027 EXPECT_EQ(ServiceWorkerVersion::INSTALLING, | 1020 EXPECT_EQ(ServiceWorkerVersion::INSTALLING, |
1028 update_helper->state_change_log_[0].status); | 1021 update_helper->state_change_log_[0].status); |
1029 | 1022 |
1030 EXPECT_EQ(registration->active_version()->version_id(), | 1023 EXPECT_EQ(registration->active_version()->version_uuid(), |
1031 update_helper->state_change_log_[1].version_id); | 1024 update_helper->state_change_log_[1].version_uuid); |
1032 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, | 1025 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, |
1033 update_helper->state_change_log_[1].status); | 1026 update_helper->state_change_log_[1].status); |
1034 | 1027 |
1035 EXPECT_EQ(first_version->version_id(), | 1028 EXPECT_EQ(first_version->version_uuid(), |
1036 update_helper->state_change_log_[2].version_id); | 1029 update_helper->state_change_log_[2].version_uuid); |
1037 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, | 1030 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, |
1038 update_helper->state_change_log_[2].status); | 1031 update_helper->state_change_log_[2].status); |
1039 | 1032 |
1040 EXPECT_EQ(registration->active_version()->version_id(), | 1033 EXPECT_EQ(registration->active_version()->version_uuid(), |
1041 update_helper->state_change_log_[3].version_id); | 1034 update_helper->state_change_log_[3].version_uuid); |
1042 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, | 1035 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, |
1043 update_helper->state_change_log_[3].status); | 1036 update_helper->state_change_log_[3].status); |
1044 | 1037 |
1045 EXPECT_EQ(registration->active_version()->version_id(), | 1038 EXPECT_EQ(registration->active_version()->version_uuid(), |
1046 update_helper->state_change_log_[4].version_id); | 1039 update_helper->state_change_log_[4].version_uuid); |
1047 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, | 1040 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, |
1048 update_helper->state_change_log_[4].status); | 1041 update_helper->state_change_log_[4].status); |
1049 | 1042 |
1050 EXPECT_TRUE(update_helper->update_found_); | 1043 EXPECT_TRUE(update_helper->update_found_); |
1051 } | 1044 } |
1052 | 1045 |
1053 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { | 1046 TEST_F(ServiceWorkerJobTest, Update_NewestVersionChanged) { |
1054 scoped_refptr<ServiceWorkerRegistration> registration = | 1047 scoped_refptr<ServiceWorkerRegistration> registration = |
1055 RunRegisterJob(GURL("http://www.example.com/one/"), | 1048 RunRegisterJob(GURL("http://www.example.com/one/"), |
1056 GURL("http://www.example.com/service_worker.js")); | 1049 GURL("http://www.example.com/service_worker.js")); |
1057 | 1050 |
1058 ServiceWorkerVersion* active_version = registration->active_version(); | 1051 ServiceWorkerVersion* active_version = registration->active_version(); |
1059 | 1052 |
1060 // Queue an Update, it should abort when it starts and sees the new version. | 1053 // Queue an Update, it should abort when it starts and sees the new version. |
1061 job_coordinator()->Update(registration.get(), false); | 1054 job_coordinator()->Update(registration.get(), false); |
1062 | 1055 |
1063 // Add a waiting version with new script. | 1056 // Add a waiting version with new script. |
1064 scoped_refptr<ServiceWorkerVersion> version = | 1057 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( |
1065 new ServiceWorkerVersion(registration.get(), | 1058 registration.get(), GURL("http://www.example.com/new_worker.js"), |
1066 GURL("http://www.example.com/new_worker.js"), | 1059 std::string( |
1067 2L /* dummy version id */, | 1060 "03fdbf6e-61b6-476a-9379-11d172ade44b") /* dummy version id */, |
1068 helper_->context()->AsWeakPtr()); | 1061 helper_->context()->AsWeakPtr()); |
1069 registration->SetWaitingVersion(version); | 1062 registration->SetWaitingVersion(version); |
1070 | 1063 |
1071 base::RunLoop().RunUntilIdle(); | 1064 base::RunLoop().RunUntilIdle(); |
1072 | 1065 |
1073 // Verify the registration was not modified by the Update. | 1066 // Verify the registration was not modified by the Update. |
1074 EXPECT_EQ(active_version, registration->active_version()); | 1067 EXPECT_EQ(active_version, registration->active_version()); |
1075 EXPECT_EQ(version.get(), registration->waiting_version()); | 1068 EXPECT_EQ(version.get(), registration->waiting_version()); |
1076 EXPECT_EQ(NULL, registration->installing_version()); | 1069 EXPECT_EQ(NULL, registration->installing_version()); |
1077 } | 1070 } |
1078 | 1071 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 EXPECT_FALSE(registration->is_uninstalling()); | 1455 EXPECT_FALSE(registration->is_uninstalling()); |
1463 EXPECT_FALSE(registration->is_uninstalled()); | 1456 EXPECT_FALSE(registration->is_uninstalled()); |
1464 | 1457 |
1465 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); | 1458 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); |
1466 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); | 1459 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); |
1467 | 1460 |
1468 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); | 1461 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); |
1469 } | 1462 } |
1470 | 1463 |
1471 } // namespace content | 1464 } // namespace content |
OLD | NEW |