Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: content/browser/service_worker/service_worker_job_unittest.cc

Issue 667943003: Standardize usage of virtual/override/final in content/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 ASSERT_TRUE(called); 397 ASSERT_TRUE(called);
398 398
399 ASSERT_EQ(new_registration, old_registration); 399 ASSERT_EQ(new_registration, old_registration);
400 } 400 }
401 401
402 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { 402 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper {
403 public: 403 public:
404 explicit FailToStartWorkerTestHelper(int mock_render_process_id) 404 explicit FailToStartWorkerTestHelper(int mock_render_process_id)
405 : EmbeddedWorkerTestHelper(mock_render_process_id) {} 405 : EmbeddedWorkerTestHelper(mock_render_process_id) {}
406 406
407 virtual void OnStartWorker(int embedded_worker_id, 407 void OnStartWorker(int embedded_worker_id,
408 int64 service_worker_version_id, 408 int64 service_worker_version_id,
409 const GURL& scope, 409 const GURL& scope,
410 const GURL& script_url, 410 const GURL& script_url,
411 bool pause_after_download) override { 411 bool pause_after_download) override {
412 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 412 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
413 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); 413 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id);
414 } 414 }
415 }; 415 };
416 416
417 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { 417 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
418 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_)); 418 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_));
419 419
420 bool called = false; 420 bool called = false;
421 scoped_refptr<ServiceWorkerRegistration> registration; 421 scoped_refptr<ServiceWorkerRegistration> registration;
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 update_found_(false) {} 899 update_found_(false) {}
900 virtual ~UpdateJobTestHelper() { 900 ~UpdateJobTestHelper() override {
901 if (registration_.get()) 901 if (registration_.get())
902 registration_->RemoveListener(this); 902 registration_->RemoveListener(this);
903 } 903 }
904 904
905 ServiceWorkerStorage* storage() { return context()->storage(); } 905 ServiceWorkerStorage* storage() { return context()->storage(); }
906 ServiceWorkerJobCoordinator* job_coordinator() { 906 ServiceWorkerJobCoordinator* job_coordinator() {
907 return context()->job_coordinator(); 907 return context()->job_coordinator();
908 } 908 }
909 909
910 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration( 910 scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration(
911 const GURL& test_origin) { 911 const GURL& test_origin) {
912 scoped_refptr<ServiceWorkerRegistration> registration; 912 scoped_refptr<ServiceWorkerRegistration> registration;
913 bool called = false; 913 bool called = false;
914 job_coordinator()->Register( 914 job_coordinator()->Register(
915 test_origin.Resolve(kScope), 915 test_origin.Resolve(kScope),
916 test_origin.Resolve(kScript), 916 test_origin.Resolve(kScript),
917 NULL, 917 NULL,
918 SaveRegistration(SERVICE_WORKER_OK, &called, &registration)); 918 SaveRegistration(SERVICE_WORKER_OK, &called, &registration));
919 base::RunLoop().RunUntilIdle(); 919 base::RunLoop().RunUntilIdle();
920 EXPECT_TRUE(called); 920 EXPECT_TRUE(called);
921 EXPECT_TRUE(registration.get()); 921 EXPECT_TRUE(registration.get());
922 EXPECT_TRUE(registration->active_version()); 922 EXPECT_TRUE(registration->active_version());
923 EXPECT_FALSE(registration->installing_version()); 923 EXPECT_FALSE(registration->installing_version());
924 EXPECT_FALSE(registration->waiting_version()); 924 EXPECT_FALSE(registration->waiting_version());
925 registration_ = registration; 925 registration_ = registration;
926 return registration; 926 return registration;
927 } 927 }
928 928
929 // EmbeddedWorkerTestHelper overrides 929 // EmbeddedWorkerTestHelper overrides
930 virtual void OnStartWorker(int embedded_worker_id, 930 void OnStartWorker(int embedded_worker_id,
931 int64 version_id, 931 int64 version_id,
932 const GURL& scope, 932 const GURL& scope,
933 const GURL& script, 933 const GURL& script,
934 bool pause_after_download) override { 934 bool pause_after_download) override {
935 const std::string kMockScriptBody = "mock_script"; 935 const std::string kMockScriptBody = "mock_script";
936 const uint64 kMockScriptSize = 19284; 936 const uint64 kMockScriptSize = 19284;
937 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); 937 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id);
938 ASSERT_TRUE(version); 938 ASSERT_TRUE(version);
939 version->AddListener(this); 939 version->AddListener(this);
940 940
941 if (!pause_after_download) { 941 if (!pause_after_download) {
942 // Spoof caching the script for the initial version. 942 // Spoof caching the script for the initial version.
943 int64 resource_id = storage()->NewResourceId(); 943 int64 resource_id = storage()->NewResourceId();
944 version->script_cache_map()->NotifyStartedCaching(script, resource_id); 944 version->script_cache_map()->NotifyStartedCaching(script, resource_id);
945 WriteStringResponse(storage(), resource_id, kMockScriptBody); 945 WriteStringResponse(storage(), resource_id, kMockScriptBody);
946 version->script_cache_map()->NotifyFinishedCaching( 946 version->script_cache_map()->NotifyFinishedCaching(
947 script, kMockScriptSize, net::URLRequestStatus()); 947 script, kMockScriptSize, net::URLRequestStatus());
948 } else { 948 } else {
949 // Spoof caching the script for the new version. 949 // Spoof caching the script for the new version.
950 int64 resource_id = storage()->NewResourceId(); 950 int64 resource_id = storage()->NewResourceId();
951 version->script_cache_map()->NotifyStartedCaching(script, resource_id); 951 version->script_cache_map()->NotifyStartedCaching(script, resource_id);
952 if (script.GetOrigin() == kNoChangeOrigin) 952 if (script.GetOrigin() == kNoChangeOrigin)
953 WriteStringResponse(storage(), resource_id, kMockScriptBody); 953 WriteStringResponse(storage(), resource_id, kMockScriptBody);
954 else 954 else
955 WriteStringResponse(storage(), resource_id, "mock_different_script"); 955 WriteStringResponse(storage(), resource_id, "mock_different_script");
956 version->script_cache_map()->NotifyFinishedCaching( 956 version->script_cache_map()->NotifyFinishedCaching(
957 script, kMockScriptSize, net::URLRequestStatus()); 957 script, kMockScriptSize, net::URLRequestStatus());
958 } 958 }
959 EmbeddedWorkerTestHelper::OnStartWorker( 959 EmbeddedWorkerTestHelper::OnStartWorker(
960 embedded_worker_id, version_id, scope, script, pause_after_download); 960 embedded_worker_id, version_id, scope, script, pause_after_download);
961 } 961 }
962 962
963 // ServiceWorkerRegistration::Listener overrides 963 // ServiceWorkerRegistration::Listener overrides
964 virtual void OnVersionAttributesChanged( 964 void OnVersionAttributesChanged(
965 ServiceWorkerRegistration* registration, 965 ServiceWorkerRegistration* registration,
966 ChangedVersionAttributesMask changed_mask, 966 ChangedVersionAttributesMask changed_mask,
967 const ServiceWorkerRegistrationInfo& info) override { 967 const ServiceWorkerRegistrationInfo& info) override {
968 AttributeChangeLogEntry entry; 968 AttributeChangeLogEntry entry;
969 entry.registration_id = registration->id(); 969 entry.registration_id = registration->id();
970 entry.mask = changed_mask; 970 entry.mask = changed_mask;
971 entry.info = info; 971 entry.info = info;
972 attribute_change_log_.push_back(entry); 972 attribute_change_log_.push_back(entry);
973 } 973 }
974 974
975 virtual void OnRegistrationFailed( 975 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override {
976 NOTREACHED();
977 }
978
979 void OnRegistrationFinishedUninstalling(
976 ServiceWorkerRegistration* registration) override { 980 ServiceWorkerRegistration* registration) override {
977 NOTREACHED(); 981 NOTREACHED();
978 } 982 }
979 983
980 virtual void OnRegistrationFinishedUninstalling( 984 void OnUpdateFound(ServiceWorkerRegistration* registration) override {
981 ServiceWorkerRegistration* registration) override {
982 NOTREACHED();
983 }
984
985 virtual void OnUpdateFound(
986 ServiceWorkerRegistration* registration) override {
987 ASSERT_FALSE(update_found_); 985 ASSERT_FALSE(update_found_);
988 update_found_ = true; 986 update_found_ = true;
989 } 987 }
990 988
991 // ServiceWorkerVersion::Listener overrides 989 // ServiceWorkerVersion::Listener overrides
992 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) override { 990 void OnVersionStateChanged(ServiceWorkerVersion* version) override {
993 StateChangeLogEntry entry; 991 StateChangeLogEntry entry;
994 entry.version_id = version->version_id(); 992 entry.version_id = version->version_id();
995 entry.status = version->status(); 993 entry.status = version->status();
996 state_change_log_.push_back(entry); 994 state_change_log_.push_back(entry);
997 } 995 }
998 996
999 scoped_refptr<ServiceWorkerRegistration> registration_; 997 scoped_refptr<ServiceWorkerRegistration> registration_;
1000 998
1001 std::vector<AttributeChangeLogEntry> attribute_change_log_; 999 std::vector<AttributeChangeLogEntry> attribute_change_log_;
1002 std::vector<StateChangeLogEntry> state_change_log_; 1000 std::vector<StateChangeLogEntry> state_change_log_;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 EXPECT_TRUE(called); 1189 EXPECT_TRUE(called);
1192 1190
1193 // Verify the registration was not modified by the Update. 1191 // Verify the registration was not modified by the Update.
1194 EXPECT_TRUE(registration->is_uninstalling()); 1192 EXPECT_TRUE(registration->is_uninstalling());
1195 EXPECT_EQ(active_version, registration->active_version()); 1193 EXPECT_EQ(active_version, registration->active_version());
1196 EXPECT_EQ(NULL, registration->waiting_version()); 1194 EXPECT_EQ(NULL, registration->waiting_version());
1197 EXPECT_EQ(NULL, registration->installing_version()); 1195 EXPECT_EQ(NULL, registration->installing_version());
1198 } 1196 }
1199 1197
1200 } // namespace content 1198 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698