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

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

Issue 1283273002: Service Worker: Change last update check location and HTTP cache bypass rule (2/2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address the latest spec change. Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_write_to_cache_job_unittest.cc
diff --git a/content/browser/service_worker/service_worker_write_to_cache_job_unittest.cc b/content/browser/service_worker/service_worker_write_to_cache_job_unittest.cc
index 18115d9b8aa24b82b95b028b1dc49c1ed2ab22a0..e6973c8de485f22442ad984ce2646c8a2f0151bd 100644
--- a/content/browser/service_worker/service_worker_write_to_cache_job_unittest.cc
+++ b/content/browser/service_worker/service_worker_write_to_cache_job_unittest.cc
@@ -84,6 +84,17 @@ net::URLRequestJob* CreateInvalidMimeTypeJob(
true);
}
+net::URLRequestJob* CreateErrorReponseJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) {
+ const char kErrorHeaders[] =
+ "HTTP/1.1 404 Not Found\0"
+ "\0";
nhiroki 2015/09/07 07:05:59 nit: These lines could be squashed into line 90.
jungkees 2015/09/08 16:01:13 Done.
+ return new net::URLRequestTestJob(
+ request, network_delegate,
+ std::string(kErrorHeaders, arraysize(kErrorHeaders)), kScriptCode, true);
+}
+
class SSLCertificateErrorJob : public net::URLRequestTestJob {
public:
SSLCertificateErrorJob(net::URLRequest* request,
@@ -360,7 +371,9 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test {
// Performs the net request for an update of |registration_|'s incumbent
// to the script |response|. Returns the new version.
scoped_refptr<ServiceWorkerVersion> UpdateScript(
- const std::string& response) {
+ const std::string& response,
+ bool status_success = true,
+ bool network_accessed = true) {
int render_process_id = NextRenderProcessId();
int provider_id = NextProviderId();
scoped_refptr<ServiceWorkerVersion> new_version =
@@ -369,8 +382,16 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test {
CreateHostForVersion(render_process_id, provider_id, new_version);
SetUpScriptRequest(render_process_id, provider_id);
- mock_protocol_handler_->SetCreateJobCallback(
- base::Bind(&CreateResponseJob, response));
+ if (status_success)
+ mock_protocol_handler_->SetCreateJobCallback(
+ base::Bind(&CreateResponseJob, response));
+ else
+ mock_protocol_handler_->SetCreateJobCallback(
+ base::Bind(&CreateErrorReponseJob));
+ // Whether the script load request accessed the network or was served from
+ // HTTPCache.
+ if (network_accessed)
+ new_version->embedded_worker()->OnNetworkAccessedForScriptLoad();
nhiroki 2015/09/07 07:05:59 This might not be necessary after incorporating my
jungkees 2015/09/08 16:01:13 Yes, this part has been removed.
request_->Start();
base::RunLoop().RunUntilIdle();
return new_version;
@@ -573,4 +594,35 @@ TEST_F(ServiceWorkerWriteToCacheJobTest, Update_EmptyScript) {
EXPECT_EQ(kInvalidServiceWorkerResponseId, GetResourceId(version.get()));
}
+TEST_F(ServiceWorkerWriteToCacheJobTest, Update_BumpLastUpdateCheckTime) {
+ std::string response = GenerateLongResponse();
+ CreateIncumbent(response);
+
+ // Script was served from HTTPCache.
+ base::Time current = base::Time::Now();
+ registration_->set_last_update_check(current);
+ scoped_refptr<ServiceWorkerVersion> version = UpdateScript(
+ response, true /* status_success */, false /* network_accessed */);
+ EXPECT_EQ(current, registration_->last_update_check());
+
+ // Same script but the request accessed the network.
+ version = UpdateScript(response);
+ EXPECT_LT(current, registration_->last_update_check());
+
+ // Changed the first byte and the request accessed the network.
+ response[0] = 'x';
+ current = base::Time::Now();
+ registration_->set_last_update_check(current);
+ version = UpdateScript(response);
+ VerifyResource(GetResourceId(version.get()), response);
+ registration_->SetWaitingVersion(version);
+ EXPECT_LT(current, registration_->last_update_check());
+
+ // The request accessed the network but received a non-2xx error.
+ current = base::Time::Now();
+ registration_->set_last_update_check(current);
+ version = UpdateScript(response, false /* status_success */);
+ EXPECT_EQ(current, registration_->last_update_check());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698