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/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 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 EXPECT_FALSE(registration->waiting_version()); | 956 EXPECT_FALSE(registration->waiting_version()); |
957 EXPECT_TRUE(update_helper->attribute_change_log_.empty()); | 957 EXPECT_TRUE(update_helper->attribute_change_log_.empty()); |
958 ASSERT_EQ(1u, update_helper->state_change_log_.size()); | 958 ASSERT_EQ(1u, update_helper->state_change_log_.size()); |
959 EXPECT_NE(registration->active_version()->version_id(), | 959 EXPECT_NE(registration->active_version()->version_id(), |
960 update_helper->state_change_log_[0].version_id); | 960 update_helper->state_change_log_[0].version_id); |
961 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, | 961 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, |
962 update_helper->state_change_log_[0].status); | 962 update_helper->state_change_log_[0].status); |
963 EXPECT_FALSE(update_helper->update_found_); | 963 EXPECT_FALSE(update_helper->update_found_); |
964 } | 964 } |
965 | 965 |
966 TEST_F(ServiceWorkerJobTest, Update_BumpLastUpdateCheckTime) { | |
967 const base::Time kToday = base::Time::Now(); | |
968 const base::Time kYesterday = | |
969 kToday - base::TimeDelta::FromDays(1) - base::TimeDelta::FromHours(1); | |
970 UpdateJobTestHelper* update_helper = | |
971 new UpdateJobTestHelper(render_process_id_); | |
972 helper_.reset(update_helper); | |
973 scoped_refptr<ServiceWorkerRegistration> registration = | |
974 update_helper->SetupInitialRegistration(kNoChangeOrigin); | |
975 | |
976 // Run an update where the last update check was less than 24 hours ago. The | |
977 // check time shouldn't change, as we didn't bypass cache. | |
978 registration->set_last_update_check(kToday); | |
979 registration->active_version()->StartUpdate(); | |
980 base::RunLoop().RunUntilIdle(); | |
981 EXPECT_EQ(kToday, registration->last_update_check()); | |
982 | |
983 // Run an update where the last update check was over 24 hours ago. The | |
984 // check time should change, as the cache was bypassed. | |
985 registration->set_last_update_check(kYesterday); | |
986 registration->active_version()->StartUpdate(); | |
987 base::RunLoop().RunUntilIdle(); | |
988 EXPECT_LT(kYesterday, registration->last_update_check()); | |
989 } | |
990 | |
991 TEST_F(ServiceWorkerJobTest, Update_NewVersion) { | 966 TEST_F(ServiceWorkerJobTest, Update_NewVersion) { |
992 UpdateJobTestHelper* update_helper = | 967 UpdateJobTestHelper* update_helper = |
993 new UpdateJobTestHelper(render_process_id_); | 968 new UpdateJobTestHelper(render_process_id_); |
994 helper_.reset(update_helper); | 969 helper_.reset(update_helper); |
995 scoped_refptr<ServiceWorkerRegistration> registration = | 970 scoped_refptr<ServiceWorkerRegistration> registration = |
996 update_helper->SetupInitialRegistration(kNewVersionOrigin); | 971 update_helper->SetupInitialRegistration(kNewVersionOrigin); |
997 ASSERT_TRUE(registration.get()); | 972 ASSERT_TRUE(registration.get()); |
998 update_helper->state_change_log_.clear(); | 973 update_helper->state_change_log_.clear(); |
999 | 974 |
1000 // Run the update job. | 975 // Run the update job. |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 EXPECT_FALSE(registration->is_uninstalling()); | 1466 EXPECT_FALSE(registration->is_uninstalling()); |
1492 EXPECT_FALSE(registration->is_uninstalled()); | 1467 EXPECT_FALSE(registration->is_uninstalled()); |
1493 | 1468 |
1494 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); | 1469 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); |
1495 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); | 1470 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); |
1496 | 1471 |
1497 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); | 1472 FindRegistrationForPattern(pattern, SERVICE_WORKER_OK); |
1498 } | 1473 } |
1499 | 1474 |
1500 } // namespace content | 1475 } // namespace content |
OLD | NEW |