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

Unified Diff: content/browser/service_worker/service_worker_job_unittest.cc

Issue 1381153004: Service Worker: Change the criteria for bumping the last update check time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update the unittest. Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_job_unittest.cc
diff --git a/content/browser/service_worker/service_worker_job_unittest.cc b/content/browser/service_worker/service_worker_job_unittest.cc
index e49c8294d64896eb2982149518a22db44f21098e..e1ba643ec0d66c297716ed40d97255b619156fb7 100644
--- a/content/browser/service_worker/service_worker_job_unittest.cc
+++ b/content/browser/service_worker/service_worker_job_unittest.cc
@@ -781,7 +781,9 @@ class UpdateJobTestHelper
UpdateJobTestHelper(int mock_render_process_id)
: EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id),
- update_found_(false) {}
+ update_found_(false),
+ force_bypass_cache_for_scripts_(false),
+ worker_failure_(false) {}
~UpdateJobTestHelper() override {
if (registration_.get())
registration_->RemoveListener(this);
@@ -792,6 +794,18 @@ class UpdateJobTestHelper
return context()->job_coordinator();
}
+ bool force_bypass_cache_for_scripts() const {
+ return force_bypass_cache_for_scripts_;
+ }
+ void set_force_bypass_cache_for_scripts(bool force_bypass_cache_for_scripts) {
+ force_bypass_cache_for_scripts_ = force_bypass_cache_for_scripts;
+ }
+
+ bool worker_failure() const { return worker_failure_; }
+ void set_worker_failure(bool worker_failure) {
falken 2015/12/16 08:27:48 A bit ambiguous of a name. "set_force_start_worker
+ worker_failure_ = worker_failure;
+ }
+
scoped_refptr<ServiceWorkerRegistration> SetupInitialRegistration(
const GURL& test_origin) {
scoped_refptr<ServiceWorkerRegistration> registration;
@@ -827,6 +841,10 @@ class UpdateJobTestHelper
ASSERT_TRUE(version);
version->AddListener(this);
+ // If |force_bypass_cache_for_scripts_| is set, simulate bypassing the
+ // network cache.
+ if (force_bypass_cache_for_scripts())
+ version->set_force_bypass_cache_for_scripts(true);
if (!is_update) {
// Spoof caching the script for the initial version.
int64 resource_id = storage()->NewResourceId();
@@ -848,8 +866,13 @@ class UpdateJobTestHelper
version->script_cache_map()->NotifyFinishedCaching(
script, kMockScriptSize, net::URLRequestStatus(), std::string());
}
- EmbeddedWorkerTestHelper::OnStartWorker(embedded_worker_id, version_id,
- scope, script);
+ // If |worker_failure_| is set, simulate worker script evaluation failure.
+ if (!worker_failure())
+ EmbeddedWorkerTestHelper::OnStartWorker(embedded_worker_id, version_id,
+ scope, script);
+ else
+ EmbeddedWorkerTestHelper::OnStartWorkerFailed(embedded_worker_id,
+ version_id, scope, script);
falken 2015/12/16 08:27:48 nit: braces for the bodies of these
}
// ServiceWorkerRegistration::Listener overrides
@@ -886,6 +909,8 @@ class UpdateJobTestHelper
std::vector<AttributeChangeLogEntry> attribute_change_log_;
std::vector<StateChangeLogEntry> state_change_log_;
bool update_found_;
+ bool force_bypass_cache_for_scripts_;
+ bool worker_failure_;
};
// Helper class for update tests that evicts the active version when the update
@@ -973,19 +998,34 @@ TEST_F(ServiceWorkerJobTest, Update_BumpLastUpdateCheckTime) {
scoped_refptr<ServiceWorkerRegistration> registration =
update_helper->SetupInitialRegistration(kNoChangeOrigin);
- // Run an update where the last update check was less than 24 hours ago. The
- // check time shouldn't change, as we didn't bypass cache.
+ registration->AddListener(update_helper);
+
+ // Run an update that does not bypass the network cache. The check time
+ // should not be updated.
registration->set_last_update_check(kToday);
registration->active_version()->StartUpdate();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(kToday, registration->last_update_check());
- // Run an update where the last update check was over 24 hours ago. The
- // check time should change, as the cache was bypassed.
+ // Run an update that bypasses the network cache. The check time should be
+ // updated.
+ update_helper->set_force_bypass_cache_for_scripts(true);
registration->set_last_update_check(kYesterday);
registration->active_version()->StartUpdate();
base::RunLoop().RunUntilIdle();
EXPECT_LT(kYesterday, registration->last_update_check());
+
+ // Run an update to a worker that loads successfully but fails to start up
+ // (script evaluation failure). The check time should be updated.
+ update_helper->state_change_log_.clear();
+ update_helper->set_force_bypass_cache_for_scripts(true);
+ update_helper->set_worker_failure(true);
+ registration->set_last_update_check(kYesterday);
+ registration->active_version()->StartUpdate();
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(ServiceWorkerVersion::REDUNDANT,
+ update_helper->state_change_log_[0].status);
+ EXPECT_LT(kYesterday, registration->last_update_check());
}
TEST_F(ServiceWorkerJobTest, Update_NewVersion) {

Powered by Google App Engine
This is Rietveld 408576698