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

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

Issue 2628553002: ServiceWorker: OnSimpleEventFinished could be called after timed out (Closed)
Patch Set: Fix comments Created 3 years, 11 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 <stdint.h> 5 #include <stdint.h>
6 #include <tuple> 6 #include <tuple>
7 7
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = 363 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern =
364 FindRegistrationForPattern(pattern); 364 FindRegistrationForPattern(pattern);
365 365
366 ASSERT_EQ(new_registration, old_registration); 366 ASSERT_EQ(new_registration, old_registration);
367 } 367 }
368 368
369 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { 369 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper {
370 public: 370 public:
371 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} 371 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
372 372
373 void OnStartWorker(int embedded_worker_id, 373 void OnStartWorker(
374 int64_t service_worker_version_id, 374 int embedded_worker_id,
375 const GURL& scope, 375 int64_t service_worker_version_id,
376 const GURL& script_url, 376 const GURL& scope,
377 bool pause_after_download) override { 377 const GURL& script_url,
378 bool pause_after_download,
379 mojom::ServiceWorkerEventDispatcherRequest request) override {
378 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 380 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
379 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); 381 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id);
380 } 382 }
381 }; 383 };
382 384
383 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { 385 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
384 helper_.reset(new FailToStartWorkerTestHelper); 386 helper_.reset(new FailToStartWorkerTestHelper);
385 387
386 scoped_refptr<ServiceWorkerRegistration> registration = 388 scoped_refptr<ServiceWorkerRegistration> registration =
387 RunRegisterJob(GURL("http://www.example.com/"), 389 RunRegisterJob(GURL("http://www.example.com/"),
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 EXPECT_TRUE(called); 824 EXPECT_TRUE(called);
823 EXPECT_TRUE(registration.get()); 825 EXPECT_TRUE(registration.get());
824 EXPECT_TRUE(registration->active_version()); 826 EXPECT_TRUE(registration->active_version());
825 EXPECT_FALSE(registration->installing_version()); 827 EXPECT_FALSE(registration->installing_version());
826 EXPECT_FALSE(registration->waiting_version()); 828 EXPECT_FALSE(registration->waiting_version());
827 registration_ = registration; 829 registration_ = registration;
828 return registration; 830 return registration;
829 } 831 }
830 832
831 // EmbeddedWorkerTestHelper overrides 833 // EmbeddedWorkerTestHelper overrides
832 void OnStartWorker(int embedded_worker_id, 834 void OnStartWorker(
833 int64_t version_id, 835 int embedded_worker_id,
834 const GURL& scope, 836 int64_t version_id,
835 const GURL& script, 837 const GURL& scope,
836 bool pause_after_download) override { 838 const GURL& script,
839 bool pause_after_download,
840 mojom::ServiceWorkerEventDispatcherRequest request) override {
837 const std::string kMockScriptBody = "mock_script"; 841 const std::string kMockScriptBody = "mock_script";
838 const uint64_t kMockScriptSize = 19284; 842 const uint64_t kMockScriptSize = 19284;
839 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); 843 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id);
840 ServiceWorkerRegistration* registration = 844 ServiceWorkerRegistration* registration =
841 context()->GetLiveRegistration(version->registration_id()); 845 context()->GetLiveRegistration(version->registration_id());
842 bool is_update = registration->active_version() && 846 bool is_update = registration->active_version() &&
843 version != registration->active_version(); 847 version != registration->active_version();
844 848
845 ASSERT_TRUE(version); 849 ASSERT_TRUE(version);
846 version->AddListener(this); 850 version->AddListener(this);
(...skipping 29 matching lines...) Expand all
876 } 880 }
877 881
878 // Spoof caching the script for the new version. 882 // Spoof caching the script for the new version.
879 WriteStringResponse(storage(), resource_id, "mock_different_script"); 883 WriteStringResponse(storage(), resource_id, "mock_different_script");
880 version->script_cache_map()->NotifyFinishedCaching( 884 version->script_cache_map()->NotifyFinishedCaching(
881 script, kMockScriptSize, net::OK, std::string()); 885 script, kMockScriptSize, net::OK, std::string());
882 version->SetMainScriptHttpResponseInfo( 886 version->SetMainScriptHttpResponseInfo(
883 EmbeddedWorkerTestHelper::CreateHttpResponseInfo()); 887 EmbeddedWorkerTestHelper::CreateHttpResponseInfo());
884 } 888 }
885 889
886 EmbeddedWorkerTestHelper::OnStartWorker( 890 EmbeddedWorkerTestHelper::OnStartWorker(embedded_worker_id, version_id,
887 embedded_worker_id, version_id, scope, script, pause_after_download); 891 scope, script, pause_after_download,
892 std::move(request));
888 } 893 }
889 894
890 void OnResumeAfterDownload(int embedded_worker_id) override { 895 void OnResumeAfterDownload(int embedded_worker_id) override {
891 if (!force_start_worker_failure_) { 896 if (!force_start_worker_failure_) {
892 EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id); 897 EmbeddedWorkerTestHelper::OnResumeAfterDownload(embedded_worker_id);
893 } else { 898 } else {
894 SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id); 899 SimulateWorkerThreadStarted(GetNextThreadId(), embedded_worker_id);
895 SimulateWorkerScriptEvaluated(embedded_worker_id, false); 900 SimulateWorkerScriptEvaluated(embedded_worker_id, false);
896 } 901 }
897 } 902 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 bool force_start_worker_failure_ = false; 937 bool force_start_worker_failure_ = false;
933 }; 938 };
934 939
935 // Helper class for update tests that evicts the active version when the update 940 // Helper class for update tests that evicts the active version when the update
936 // worker is about to be started. 941 // worker is about to be started.
937 class EvictIncumbentVersionHelper : public UpdateJobTestHelper { 942 class EvictIncumbentVersionHelper : public UpdateJobTestHelper {
938 public: 943 public:
939 EvictIncumbentVersionHelper() {} 944 EvictIncumbentVersionHelper() {}
940 ~EvictIncumbentVersionHelper() override {} 945 ~EvictIncumbentVersionHelper() override {}
941 946
942 void OnStartWorker(int embedded_worker_id, 947 void OnStartWorker(
943 int64_t version_id, 948 int embedded_worker_id,
944 const GURL& scope, 949 int64_t version_id,
945 const GURL& script, 950 const GURL& scope,
946 bool pause_after_download) override { 951 const GURL& script,
952 bool pause_after_download,
953 mojom::ServiceWorkerEventDispatcherRequest request) override {
947 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id); 954 ServiceWorkerVersion* version = context()->GetLiveVersion(version_id);
948 ServiceWorkerRegistration* registration = 955 ServiceWorkerRegistration* registration =
949 context()->GetLiveRegistration(version->registration_id()); 956 context()->GetLiveRegistration(version->registration_id());
950 bool is_update = registration->active_version() && 957 bool is_update = registration->active_version() &&
951 version != registration->active_version(); 958 version != registration->active_version();
952 if (is_update) { 959 if (is_update) {
953 // Evict the incumbent worker. 960 // Evict the incumbent worker.
954 ASSERT_FALSE(registration->waiting_version()); 961 ASSERT_FALSE(registration->waiting_version());
955 registration->DeleteVersion( 962 registration->DeleteVersion(
956 make_scoped_refptr(registration->active_version())); 963 make_scoped_refptr(registration->active_version()));
957 } 964 }
958 UpdateJobTestHelper::OnStartWorker(embedded_worker_id, version_id, scope, 965 UpdateJobTestHelper::OnStartWorker(embedded_worker_id, version_id, scope,
959 script, pause_after_download); 966 script, pause_after_download,
967 std::move(request));
960 } 968 }
961 969
962 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override { 970 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override {
963 registration_failed_ = true; 971 registration_failed_ = true;
964 } 972 }
965 973
966 bool registration_failed_ = false; 974 bool registration_failed_ = false;
967 }; 975 };
968 976
969 } // namespace 977 } // namespace
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 // should not be promoted to ACTIVATED because failure occur 1726 // should not be promoted to ACTIVATED because failure occur
1719 // during shutdown. 1727 // during shutdown.
1720 runner->RunUntilIdle(); 1728 runner->RunUntilIdle();
1721 base::RunLoop().RunUntilIdle(); 1729 base::RunLoop().RunUntilIdle();
1722 EXPECT_EQ(new_version.get(), registration->active_version()); 1730 EXPECT_EQ(new_version.get(), registration->active_version());
1723 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); 1731 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1724 registration->RemoveListener(update_helper); 1732 registration->RemoveListener(update_helper);
1725 } 1733 }
1726 1734
1727 } // namespace content 1735 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698