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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 | 839 |
840 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) { | 840 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) { |
841 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | 841 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, |
842 "/service_worker/nonexistent.js")); | 842 "/service_worker/nonexistent.js")); |
843 | 843 |
844 // Start a worker for nonexistent URL. | 844 // Start a worker for nonexistent URL. |
845 StartWorker(SERVICE_WORKER_ERROR_NETWORK); | 845 StartWorker(SERVICE_WORKER_ERROR_NETWORK); |
846 } | 846 } |
847 | 847 |
848 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, ReadResourceFailure) { | 848 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, ReadResourceFailure) { |
849 // Create and store a registration. | 849 // Create a registration. |
850 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | 850 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, |
851 "/service_worker/worker.js")); | 851 "/service_worker/worker.js")); |
852 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 852 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
853 StoreRegistration(version_->version_id(), SERVICE_WORKER_OK); | |
854 | 853 |
855 // Add a non-existent resource to the version. | 854 // Add a non-existent resource to the version. |
856 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 855 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
857 records.push_back( | 856 records.push_back( |
858 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100)); | 857 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100)); |
859 version_->script_cache_map()->SetResources(records); | 858 version_->script_cache_map()->SetResources(records); |
860 | 859 |
| 860 // Store the registration. |
| 861 StoreRegistration(version_->version_id(), SERVICE_WORKER_OK); |
| 862 |
861 // Start the worker. We'll fail to read the resource. | 863 // Start the worker. We'll fail to read the resource. |
862 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE); | 864 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE); |
863 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status()); | 865 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status()); |
864 | 866 |
865 // The registration should be deleted from storage since the broken worker was | 867 // The registration should be deleted from storage since the broken worker was |
866 // the stored one. | 868 // the stored one. |
867 RunOnIOThread(base::Bind(&self::RemoveLiveRegistrationOnIOThread, this, | 869 RunOnIOThread(base::Bind(&self::RemoveLiveRegistrationOnIOThread, this, |
868 registration_->id())); | 870 registration_->id())); |
869 FindRegistrationForId(registration_->id(), | 871 FindRegistrationForId(registration_->id(), |
870 registration_->pattern().GetOrigin(), | 872 registration_->pattern().GetOrigin(), |
(...skipping 19 matching lines...) Expand all Loading... |
890 | 892 |
891 // Add a non-existent resource to the version. | 893 // Add a non-existent resource to the version. |
892 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 894 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
893 records.push_back( | 895 records.push_back( |
894 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100)); | 896 ServiceWorkerDatabase::ResourceRecord(30, version_->script_url(), 100)); |
895 version_->script_cache_map()->SetResources(records); | 897 version_->script_cache_map()->SetResources(records); |
896 | 898 |
897 // Make a waiting version and store it. | 899 // Make a waiting version and store it. |
898 RunOnIOThread(base::Bind(&self::AddWaitingWorkerOnIOThread, this, | 900 RunOnIOThread(base::Bind(&self::AddWaitingWorkerOnIOThread, this, |
899 "/service_worker/worker.js")); | 901 "/service_worker/worker.js")); |
| 902 registration_->waiting_version()->script_cache_map()->SetResources(records); |
900 StoreRegistration(registration_->waiting_version()->version_id(), | 903 StoreRegistration(registration_->waiting_version()->version_id(), |
901 SERVICE_WORKER_OK); | 904 SERVICE_WORKER_OK); |
902 | 905 |
903 // Start the broken worker. We'll fail to read from disk and the worker should | 906 // Start the broken worker. We'll fail to read from disk and the worker should |
904 // be doomed. | 907 // be doomed. |
905 StopWorker(SERVICE_WORKER_OK); // in case it's already running | 908 StopWorker(SERVICE_WORKER_OK); // in case it's already running |
906 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE); | 909 StartWorker(SERVICE_WORKER_ERROR_DISK_CACHE); |
907 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status()); | 910 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, version_->status()); |
908 | 911 |
909 // The registration should still be in storage since the waiting worker was | 912 // The registration should still be in storage since the waiting worker was |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1479 ASSERT_EQ(SERVICE_WORKER_OK, status); |
1477 // Stop the worker. | 1480 // Stop the worker. |
1478 StopWorker(SERVICE_WORKER_OK); | 1481 StopWorker(SERVICE_WORKER_OK); |
1479 // Restart the worker. | 1482 // Restart the worker. |
1480 StartWorker(SERVICE_WORKER_OK); | 1483 StartWorker(SERVICE_WORKER_OK); |
1481 // Stop the worker. | 1484 // Stop the worker. |
1482 StopWorker(SERVICE_WORKER_OK); | 1485 StopWorker(SERVICE_WORKER_OK); |
1483 } | 1486 } |
1484 | 1487 |
1485 } // namespace content | 1488 } // namespace content |
OLD | NEW |