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

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

Issue 2002883002: ServiceWorker: Store the existence of fetch event handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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 <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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 base::Bind(&self::DispatchInstallEventOnIOThread, this, done, result), 644 base::Bind(&self::DispatchInstallEventOnIOThread, this, done, result),
645 CreateReceiver(BrowserThread::UI, done, result)); 645 CreateReceiver(BrowserThread::UI, done, result));
646 } 646 }
647 647
648 void DispatchInstallEventOnIOThread(const base::Closure& done, 648 void DispatchInstallEventOnIOThread(const base::Closure& done,
649 ServiceWorkerStatusCode* result) { 649 ServiceWorkerStatusCode* result) {
650 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 650 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
651 int request_id = 651 int request_id =
652 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL, 652 version_->StartRequest(ServiceWorkerMetrics::EventType::INSTALL,
653 CreateReceiver(BrowserThread::UI, done, result)); 653 CreateReceiver(BrowserThread::UI, done, result));
654 version_->DispatchSimpleEvent<ServiceWorkerHostMsg_InstallEventFinished>( 654 version_->DispatchEvent<ServiceWorkerHostMsg_InstallEventFinished>(
655 request_id, ServiceWorkerMsg_InstallEvent(request_id)); 655 request_id, ServiceWorkerMsg_InstallEvent(request_id),
656 base::Bind(&self::ReceiveInstallEventOnIOThread, this, done, result));
657 }
658
659 void ReceiveInstallEventOnIOThread(const base::Closure& done,
660 ServiceWorkerStatusCode* out_result,
661 int request_id,
662 blink::WebServiceWorkerEventResult result,
663 bool has_fetch_handler) {
664 version_->FinishRequest(
665 request_id, result == blink::WebServiceWorkerEventResultCompleted);
666 version_->set_has_fetch_handler(has_fetch_handler);
667
668 ServiceWorkerStatusCode status = SERVICE_WORKER_OK;
669 if (result == blink::WebServiceWorkerEventResultRejected)
670 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
671
672 *out_result = status;
673 if (!done.is_null())
674 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done);
656 } 675 }
657 676
658 void StoreOnIOThread(const base::Closure& done, 677 void StoreOnIOThread(const base::Closure& done,
659 ServiceWorkerStatusCode* result, 678 ServiceWorkerStatusCode* result,
660 int64_t version_id) { 679 int64_t version_id) {
661 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 680 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
662 ServiceWorkerVersion* version = 681 ServiceWorkerVersion* version =
663 wrapper()->context()->GetLiveVersion(version_id); 682 wrapper()->context()->GetLiveVersion(version_id);
664 wrapper()->context()->storage()->StoreRegistration( 683 wrapper()->context()->storage()->StoreRegistration(
665 registration_.get(), version, 684 registration_.get(), version,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { 878 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) {
860 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK); 879 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK);
861 } 880 }
862 881
863 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 882 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
864 InstallWithWaitUntil_Fulfilled) { 883 InstallWithWaitUntil_Fulfilled) {
865 InstallTestHelper("/service_worker/worker_install_fulfilled.js", 884 InstallTestHelper("/service_worker/worker_install_fulfilled.js",
866 SERVICE_WORKER_OK); 885 SERVICE_WORKER_OK);
867 } 886 }
868 887
888 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
889 InstallWithFetchHandler) {
890 InstallTestHelper("/service_worker/fetch_event.js", SERVICE_WORKER_OK);
891 EXPECT_TRUE(version_->has_fetch_handler());
892 }
893
894 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
895 InstallWithoutFetchHandler) {
896 InstallTestHelper("/service_worker/worker.js", SERVICE_WORKER_OK);
897 EXPECT_FALSE(version_->has_fetch_handler());
898 }
899
869 // Check that ServiceWorker script requests set a "Service-Worker: script" 900 // Check that ServiceWorker script requests set a "Service-Worker: script"
870 // header. 901 // header.
871 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 902 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
872 ServiceWorkerScriptHeader) { 903 ServiceWorkerScriptHeader) {
873 embedded_test_server()->RegisterRequestHandler( 904 embedded_test_server()->RegisterRequestHandler(
874 base::Bind(&VerifyServiceWorkerHeaderInRequest)); 905 base::Bind(&VerifyServiceWorkerHeaderInRequest));
875 InstallTestHelper("/service_worker/generated_sw.js", SERVICE_WORKER_OK); 906 InstallTestHelper("/service_worker/generated_sw.js", SERVICE_WORKER_OK);
876 } 907 }
877 908
878 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 909 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 NavigateToTestPage(); 1865 NavigateToTestPage();
1835 // The V8 code cache must be stored to the CacheStorage which must be bigger 1866 // The V8 code cache must be stored to the CacheStorage which must be bigger
1836 // than 12 byte. 1867 // than 12 byte.
1837 EXPECT_GT(GetSideDataSize(), kV8CacheTimeStampDataSize); 1868 EXPECT_GT(GetSideDataSize(), kV8CacheTimeStampDataSize);
1838 1869
1839 NavigateToTestPage(); 1870 NavigateToTestPage();
1840 EXPECT_GT(GetSideDataSize(), kV8CacheTimeStampDataSize); 1871 EXPECT_GT(GetSideDataSize(), kV8CacheTimeStampDataSize);
1841 } 1872 }
1842 1873
1843 } // namespace content 1874 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698