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

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

Issue 2602853002: Eliminate network fallback from ServiceWorkerContextRequestHandler. (Closed)
Patch Set: rm class 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_context_request_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 BrowserThread::IO, FROM_HERE, 527 BrowserThread::IO, FROM_HERE,
528 base::Bind(&self::StopOnIOThread, base::Unretained(this), 528 base::Bind(&self::StopOnIOThread, base::Unretained(this),
529 stop_run_loop.QuitClosure(), &status)); 529 stop_run_loop.QuitClosure(), &status));
530 stop_run_loop.Run(); 530 stop_run_loop.Run();
531 ASSERT_EQ(SERVICE_WORKER_OK, status); 531 ASSERT_EQ(SERVICE_WORKER_OK, status);
532 } 532 }
533 533
534 void ActivateTestHelper( 534 void ActivateTestHelper(
535 const std::string& worker_url, 535 const std::string& worker_url,
536 ServiceWorkerStatusCode expected_status) { 536 ServiceWorkerStatusCode expected_status) {
537 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread,
538 base::Unretained(this), worker_url));
539 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 537 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
540 base::RunLoop run_loop; 538 base::RunLoop run_loop;
541 BrowserThread::PostTask( 539 BrowserThread::PostTask(
542 BrowserThread::IO, FROM_HERE, 540 BrowserThread::IO, FROM_HERE,
543 base::Bind(&self::ActivateOnIOThread, base::Unretained(this), 541 base::Bind(&self::ActivateOnIOThread, base::Unretained(this),
544 run_loop.QuitClosure(), &status)); 542 run_loop.QuitClosure(), &status));
545 run_loop.Run(); 543 run_loop.Run();
546 ASSERT_EQ(expected_status, status); 544 ASSERT_EQ(expected_status, status);
547 } 545 }
548 546
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 ServiceWorkerVersion* version = 766 ServiceWorkerVersion* version =
769 wrapper()->context()->GetLiveVersion(version_id); 767 wrapper()->context()->GetLiveVersion(version_id);
770 wrapper()->context()->storage()->StoreRegistration( 768 wrapper()->context()->storage()->StoreRegistration(
771 registration_.get(), version, 769 registration_.get(), version,
772 CreateReceiver(BrowserThread::UI, done, result)); 770 CreateReceiver(BrowserThread::UI, done, result));
773 } 771 }
774 772
775 void ActivateOnIOThread(const base::Closure& done, 773 void ActivateOnIOThread(const base::Closure& done,
776 ServiceWorkerStatusCode* result) { 774 ServiceWorkerStatusCode* result) {
777 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 775 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
778 version_->set_fetch_handler_existence(
779 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
780 version_->SetMainScriptHttpResponseInfo(CreateHttpResponseInfo());
781 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); 776 version_->SetStatus(ServiceWorkerVersion::ACTIVATING);
782 registration_->SetActiveVersion(version_.get()); 777 registration_->SetActiveVersion(version_.get());
783 version_->RunAfterStartWorker( 778 version_->RunAfterStartWorker(
784 ServiceWorkerMetrics::EventType::ACTIVATE, 779 ServiceWorkerMetrics::EventType::ACTIVATE,
785 base::Bind(&self::DispatchActivateEventOnIOThread, 780 base::Bind(&self::DispatchActivateEventOnIOThread,
786 base::Unretained(this), done, result), 781 base::Unretained(this), done, result),
787 CreateReceiver(BrowserThread::UI, done, result)); 782 CreateReceiver(BrowserThread::UI, done, result));
788 } 783 }
789 784
790 void DispatchActivateEventOnIOThread(const base::Closure& done, 785 void DispatchActivateEventOnIOThread(const base::Closure& done,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 base::Unretained(this), registration_->id())); 923 base::Unretained(this), registration_->id()));
929 FindRegistrationForId(registration_->id(), 924 FindRegistrationForId(registration_->id(),
930 registration_->pattern().GetOrigin(), 925 registration_->pattern().GetOrigin(),
931 SERVICE_WORKER_ERROR_NOT_FOUND); 926 SERVICE_WORKER_ERROR_NOT_FOUND);
932 } 927 }
933 928
934 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 929 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
935 ReadResourceFailure_WaitingWorker) { 930 ReadResourceFailure_WaitingWorker) {
936 StartServerAndNavigateToSetup(); 931 StartServerAndNavigateToSetup();
937 // Create a registration and active version. 932 // Create a registration and active version.
938 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, 933 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK);
939 base::Unretained(this), 934 ActivateTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK);
940 "/service_worker/worker.js"));
941 base::RunLoop activate_run_loop;
942 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
943 BrowserThread::PostTask(
944 BrowserThread::IO, FROM_HERE,
945 base::Bind(&self::ActivateOnIOThread, base::Unretained(this),
946 activate_run_loop.QuitClosure(), &status));
947 activate_run_loop.Run();
948 EXPECT_EQ(SERVICE_WORKER_OK, status);
949 ASSERT_TRUE(registration_->active_version()); 935 ASSERT_TRUE(registration_->active_version());
950 936
951 // Give the version a controllee. 937 // Give the version a controllee.
952 RunOnIOThread( 938 RunOnIOThread(
953 base::Bind(&self::AddControlleeOnIOThread, base::Unretained(this))); 939 base::Bind(&self::AddControlleeOnIOThread, base::Unretained(this)));
954 940
955 // Add a non-existent resource to the version. 941 // Add a non-existent resource to the version.
956 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 942 version_->script_cache_map()->resource_map_[version_->script_url()] =
957 records.push_back( 943 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100);
958 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100));
959 version_->script_cache_map()->SetResources(records);
960 944
961 // Make a waiting version and store it. 945 // Make a waiting version and store it.
962 RunOnIOThread(base::Bind(&self::AddWaitingWorkerOnIOThread, 946 RunOnIOThread(base::Bind(&self::AddWaitingWorkerOnIOThread,
963 base::Unretained(this), 947 base::Unretained(this),
964 "/service_worker/worker.js")); 948 "/service_worker/worker.js"));
949 std::vector<ServiceWorkerDatabase::ResourceRecord> records = {
950 ServiceWorkerDatabase::ResourceRecord(31, version_->script_url(), 100)};
965 registration_->waiting_version()->script_cache_map()->SetResources(records); 951 registration_->waiting_version()->script_cache_map()->SetResources(records);
966 StoreRegistration(registration_->waiting_version()->version_id(), 952 StoreRegistration(registration_->waiting_version()->version_id(),
967 SERVICE_WORKER_OK); 953 SERVICE_WORKER_OK);
968 954
969 // Start the broken worker. We'll fail to read from disk and the worker should 955 // Start the broken worker. We'll fail to read from disk and the worker should
970 // be doomed. 956 // be doomed.
971 StopWorker(SERVICE_WORKER_OK); // in case it's already running 957 StopWorker(SERVICE_WORKER_OK); // in case it's already running
972 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE); 958 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE);
973 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status()); 959 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status());
974 960
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 ServiceWorkerScriptHeader) { 1001 ServiceWorkerScriptHeader) {
1016 embedded_test_server()->RegisterRequestHandler( 1002 embedded_test_server()->RegisterRequestHandler(
1017 base::Bind(&VerifyServiceWorkerHeaderInRequest)); 1003 base::Bind(&VerifyServiceWorkerHeaderInRequest));
1018 StartServerAndNavigateToSetup(); 1004 StartServerAndNavigateToSetup();
1019 InstallTestHelper("/service_worker/generated_sw.js", SERVICE_WORKER_OK); 1005 InstallTestHelper("/service_worker/generated_sw.js", SERVICE_WORKER_OK);
1020 } 1006 }
1021 1007
1022 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 1008 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
1023 Activate_NoEventListener) { 1009 Activate_NoEventListener) {
1024 StartServerAndNavigateToSetup(); 1010 StartServerAndNavigateToSetup();
1011 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK);
1025 ActivateTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK); 1012 ActivateTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK);
1026 ASSERT_EQ(ServiceWorkerVersion::ACTIVATING, version_->status()); 1013 ASSERT_EQ(ServiceWorkerVersion::ACTIVATING, version_->status());
1027 } 1014 }
1028 1015
1029 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Activate_Rejected) { 1016 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Activate_Rejected) {
1030 StartServerAndNavigateToSetup(); 1017 StartServerAndNavigateToSetup();
1018 InstallTestHelper("/service_worker/worker_activate_rejected.js",
1019 SERVICE_WORKER_OK);
1031 ActivateTestHelper("/service_worker/worker_activate_rejected.js", 1020 ActivateTestHelper("/service_worker/worker_activate_rejected.js",
1032 SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED); 1021 SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED);
1033 } 1022 }
1034 1023
1035 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 1024 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
1036 InstallWithWaitUntil_Rejected) { 1025 InstallWithWaitUntil_Rejected) {
1037 StartServerAndNavigateToSetup(); 1026 StartServerAndNavigateToSetup();
1038 InstallTestHelper("/service_worker/worker_install_rejected.js", 1027 InstallTestHelper("/service_worker/worker_install_rejected.js",
1039 SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED); 1028 SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED);
1040 } 1029 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 // Terminating a worker, even one in an infinite loop, is treated as if 1146 // Terminating a worker, even one in an infinite loop, is treated as if
1158 // waitUntil was rejected in the renderer code. 1147 // waitUntil was rejected in the renderer code.
1159 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status); 1148 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status);
1160 } 1149 }
1161 1150
1162 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) { 1151 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) {
1163 StartServerAndNavigateToSetup(); 1152 StartServerAndNavigateToSetup();
1164 ServiceWorkerFetchEventResult result; 1153 ServiceWorkerFetchEventResult result;
1165 ServiceWorkerResponse response; 1154 ServiceWorkerResponse response;
1166 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; 1155 std::unique_ptr<storage::BlobDataHandle> blob_data_handle;
1156 InstallTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK);
1167 ActivateTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK); 1157 ActivateTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK);
1168 1158
1169 FetchOnRegisteredWorker(&result, &response, &blob_data_handle); 1159 FetchOnRegisteredWorker(&result, &response, &blob_data_handle);
1170 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); 1160 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result);
1171 EXPECT_EQ(301, response.status_code); 1161 EXPECT_EQ(301, response.status_code);
1172 EXPECT_EQ("Moved Permanently", response.status_text); 1162 EXPECT_EQ("Moved Permanently", response.status_text);
1173 ServiceWorkerHeaderMap expected_headers; 1163 ServiceWorkerHeaderMap expected_headers;
1174 expected_headers["content-language"] = "fi"; 1164 expected_headers["content-language"] = "fi";
1175 expected_headers["content-type"] = "text/html; charset=UTF-8"; 1165 expected_headers["content-type"] = "text/html; charset=UTF-8";
1176 EXPECT_EQ(expected_headers, response.headers); 1166 EXPECT_EQ(expected_headers, response.headers);
1177 1167
1178 std::string body; 1168 std::string body;
1179 RunOnIOThread( 1169 RunOnIOThread(
1180 base::Bind(&ReadResponseBody, 1170 base::Bind(&ReadResponseBody,
1181 &body, base::Owned(blob_data_handle.release()))); 1171 &body, base::Owned(blob_data_handle.release())));
1182 EXPECT_EQ("This resource is gone. Gone, gone, gone.", body); 1172 EXPECT_EQ("This resource is gone. Gone, gone, gone.", body);
1183 } 1173 }
1184 1174
1185 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 1175 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
1186 FetchEvent_ResponseViaCache) { 1176 FetchEvent_ResponseViaCache) {
1187 StartServerAndNavigateToSetup(); 1177 StartServerAndNavigateToSetup();
1188 ServiceWorkerFetchEventResult result; 1178 ServiceWorkerFetchEventResult result;
1189 ServiceWorkerResponse response1; 1179 ServiceWorkerResponse response1;
1190 ServiceWorkerResponse response2; 1180 ServiceWorkerResponse response2;
1191 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; 1181 std::unique_ptr<storage::BlobDataHandle> blob_data_handle;
1192 const base::Time start_time(base::Time::Now()); 1182 const base::Time start_time(base::Time::Now());
1183 InstallTestHelper("/service_worker/fetch_event_response_via_cache.js",
1184 SERVICE_WORKER_OK);
1193 ActivateTestHelper("/service_worker/fetch_event_response_via_cache.js", 1185 ActivateTestHelper("/service_worker/fetch_event_response_via_cache.js",
1194 SERVICE_WORKER_OK); 1186 SERVICE_WORKER_OK);
1195 1187
1196 FetchOnRegisteredWorker(&result, &response1, &blob_data_handle); 1188 FetchOnRegisteredWorker(&result, &response1, &blob_data_handle);
1197 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); 1189 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result);
1198 EXPECT_EQ(200, response1.status_code); 1190 EXPECT_EQ(200, response1.status_code);
1199 EXPECT_EQ("OK", response1.status_text); 1191 EXPECT_EQ("OK", response1.status_text);
1200 EXPECT_TRUE(response1.response_time >= start_time); 1192 EXPECT_TRUE(response1.response_time >= start_time);
1201 EXPECT_FALSE(response1.is_in_cache_storage); 1193 EXPECT_FALSE(response1.is_in_cache_storage);
1202 EXPECT_EQ(std::string(), response2.cache_storage_cache_name); 1194 EXPECT_EQ(std::string(), response2.cache_storage_cache_name);
1203 1195
1204 FetchOnRegisteredWorker(&result, &response2, &blob_data_handle); 1196 FetchOnRegisteredWorker(&result, &response2, &blob_data_handle);
1205 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); 1197 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result);
1206 EXPECT_EQ(200, response2.status_code); 1198 EXPECT_EQ(200, response2.status_code);
1207 EXPECT_EQ("OK", response2.status_text); 1199 EXPECT_EQ("OK", response2.status_text);
1208 EXPECT_EQ(response1.response_time, response2.response_time); 1200 EXPECT_EQ(response1.response_time, response2.response_time);
1209 EXPECT_TRUE(response2.is_in_cache_storage); 1201 EXPECT_TRUE(response2.is_in_cache_storage);
1210 EXPECT_EQ("cache_name", response2.cache_storage_cache_name); 1202 EXPECT_EQ("cache_name", response2.cache_storage_cache_name);
1211 } 1203 }
1212 1204
1213 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 1205 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
1214 FetchEvent_respondWithRejection) { 1206 FetchEvent_respondWithRejection) {
1215 StartServerAndNavigateToSetup(); 1207 StartServerAndNavigateToSetup();
1216 ServiceWorkerFetchEventResult result; 1208 ServiceWorkerFetchEventResult result;
1217 ServiceWorkerResponse response; 1209 ServiceWorkerResponse response;
1218 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; 1210 std::unique_ptr<storage::BlobDataHandle> blob_data_handle;
1211 InstallTestHelper("/service_worker/fetch_event_rejected.js",
1212 SERVICE_WORKER_OK);
1219 ActivateTestHelper("/service_worker/fetch_event_rejected.js", 1213 ActivateTestHelper("/service_worker/fetch_event_rejected.js",
1220 SERVICE_WORKER_OK); 1214 SERVICE_WORKER_OK);
1221 1215
1222 ConsoleListener console_listener; 1216 ConsoleListener console_listener;
1223 RunOnIOThread(base::Bind(&EmbeddedWorkerInstance::AddListener, 1217 RunOnIOThread(base::Bind(&EmbeddedWorkerInstance::AddListener,
1224 base::Unretained(version_->embedded_worker()), 1218 base::Unretained(version_->embedded_worker()),
1225 &console_listener)); 1219 &console_listener));
1226 1220
1227 FetchOnRegisteredWorker(&result, &response, &blob_data_handle); 1221 FetchOnRegisteredWorker(&result, &response, &blob_data_handle);
1228 const base::string16 expected1 = base::ASCIIToUTF16( 1222 const base::string16 expected1 = base::ASCIIToUTF16(
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 base::RunLoop cached_metadata_run_loop; 2539 base::RunLoop cached_metadata_run_loop;
2546 cache_updated_closure_ = cached_metadata_run_loop.QuitClosure(); 2540 cache_updated_closure_ = cached_metadata_run_loop.QuitClosure();
2547 2541
2548 // Start a worker. 2542 // Start a worker.
2549 StartWorker(SERVICE_WORKER_OK); 2543 StartWorker(SERVICE_WORKER_OK);
2550 2544
2551 // Wait for the matadata is stored. This run loop should finish when 2545 // Wait for the matadata is stored. This run loop should finish when
2552 // OnCachedMetadataUpdated() is called. 2546 // OnCachedMetadataUpdated() is called.
2553 cached_metadata_run_loop.Run(); 2547 cached_metadata_run_loop.Run();
2554 2548
2555 // Activate the worker.
2556 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
2557 base::RunLoop activate_run_loop;
2558 BrowserThread::PostTask(
2559 BrowserThread::IO, FROM_HERE,
2560 base::Bind(&self::ActivateOnIOThread, base::Unretained(this),
2561 activate_run_loop.QuitClosure(), &status));
2562 activate_run_loop.Run();
2563 ASSERT_EQ(SERVICE_WORKER_OK, status);
2564 // Stop the worker. 2549 // Stop the worker.
2565 StopWorker(SERVICE_WORKER_OK); 2550 StopWorker(SERVICE_WORKER_OK);
2566 // Restart the worker. 2551 // Restart the worker.
2567 StartWorker(SERVICE_WORKER_OK); 2552 StartWorker(SERVICE_WORKER_OK);
2568 // Stop the worker. 2553 // Stop the worker.
2569 StopWorker(SERVICE_WORKER_OK); 2554 StopWorker(SERVICE_WORKER_OK);
2570 } 2555 }
2571 2556
2572 class CacheStorageSideDataSizeChecker 2557 class CacheStorageSideDataSizeChecker
2573 : public base::RefCountedThreadSafe<CacheStorageSideDataSizeChecker> { 2558 : public base::RefCountedThreadSafe<CacheStorageSideDataSizeChecker> {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 }; 2968 };
2984 2969
2985 // MemoryCoordinatorWithServiceWorkerTest checks if a process won't be 2970 // MemoryCoordinatorWithServiceWorkerTest checks if a process won't be
2986 // suspended when it has one or more shared workers or service workers. 2971 // suspended when it has one or more shared workers or service workers.
2987 // TODO(shimazu): Enable these tests on macos when MemoryMonitorMac is 2972 // TODO(shimazu): Enable these tests on macos when MemoryMonitorMac is
2988 // implemented. 2973 // implemented.
2989 #if !defined(OS_MACOSX) 2974 #if !defined(OS_MACOSX)
2990 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorWithServiceWorkerTest, 2975 IN_PROC_BROWSER_TEST_F(MemoryCoordinatorWithServiceWorkerTest,
2991 CannotSuspendRendererWithServiceWorker) { 2976 CannotSuspendRendererWithServiceWorker) {
2992 StartServerAndNavigateToSetup(); 2977 StartServerAndNavigateToSetup();
2978 InstallTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK);
2993 ActivateTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK); 2979 ActivateTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK);
2994 2980
2995 MemoryCoordinatorImpl* memory_coordinator = 2981 MemoryCoordinatorImpl* memory_coordinator =
2996 MemoryCoordinatorImpl::GetInstance(); 2982 MemoryCoordinatorImpl::GetInstance();
2997 memory_coordinator->SetDelegateForTesting( 2983 memory_coordinator->SetDelegateForTesting(
2998 base::MakeUnique<TestMemoryCoordinatorDelegate>()); 2984 base::MakeUnique<TestMemoryCoordinatorDelegate>());
2999 2985
3000 // Ensure only one process host exists. 2986 // Ensure only one process host exists.
3001 ASSERT_EQ(1, CountRenderProcessHosts()); 2987 ASSERT_EQ(1, CountRenderProcessHosts());
3002 ASSERT_EQ(1u, memory_coordinator->children().size()); 2988 ASSERT_EQ(1u, memory_coordinator->children().size());
3003 2989
3004 // Check the number of workers. 2990 // Check the number of workers.
3005 int render_process_id = memory_coordinator->children().begin()->first; 2991 int render_process_id = memory_coordinator->children().begin()->first;
3006 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id); 2992 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
3007 EXPECT_EQ(1u, rph->GetWorkerRefCount()); 2993 EXPECT_EQ(1u, rph->GetWorkerRefCount());
3008 2994
3009 // A process should be backgrounded to ensure the worker reference count takes 2995 // A process should be backgrounded to ensure the worker reference count takes
3010 // effect in CanSuspendRenderer(). 2996 // effect in CanSuspendRenderer().
3011 shell()->web_contents()->WasHidden(); 2997 shell()->web_contents()->WasHidden();
3012 EXPECT_TRUE(rph->IsProcessBackgrounded()); 2998 EXPECT_TRUE(rph->IsProcessBackgrounded());
3013 2999
3014 // The process which has service worker thread shouldn't be suspended. 3000 // The process which has service worker thread shouldn't be suspended.
3015 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id)); 3001 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id));
3016 } 3002 }
3017 #endif 3003 #endif
3018 3004
3019 } // namespace content 3005 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_context_request_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698