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

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 years, 4 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: third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
index b3af2f8771afc8f41a5836ab76004d34d5628053..a9bf3d4f8f1d10875bf8a8988ae655535f656279 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerContainerTest.cpp
@@ -132,6 +132,7 @@ class NotReachedWebServiceWorkerProvider : public WebServiceWorkerProvider {
void RegisterServiceWorker(
const WebURL& pattern,
const WebURL& script_url,
+ WebServiceWorkerUpdateViaCache update_via_cache,
std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks)
override {
ADD_FAILURE()
@@ -283,6 +284,9 @@ class StubWebServiceWorkerProvider {
const WebURL& RegisterScriptURL() { return register_script_url_; }
size_t GetRegistrationCallCount() { return get_registration_call_count_; }
const WebURL& GetRegistrationURL() { return get_registration_url_; }
+ WebServiceWorkerUpdateViaCache UpdateViaCache() const {
+ return update_via_cache_;
+ }
private:
class WebServiceWorkerProviderImpl : public WebServiceWorkerProvider {
@@ -295,11 +299,13 @@ class StubWebServiceWorkerProvider {
void RegisterServiceWorker(
const WebURL& pattern,
const WebURL& script_url,
+ WebServiceWorkerUpdateViaCache update_via_cache,
std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks)
override {
owner_.register_call_count_++;
owner_.register_scope_ = pattern;
owner_.register_script_url_ = script_url;
+ owner_.update_via_cache_ = update_via_cache;
registration_callbacks_to_delete_.push_back(std::move(callbacks));
}
@@ -332,6 +338,7 @@ class StubWebServiceWorkerProvider {
WebURL register_script_url_;
size_t get_registration_call_count_;
WebURL get_registration_url_;
+ WebServiceWorkerUpdateViaCache update_via_cache_;
};
TEST_F(ServiceWorkerContainerTest,
@@ -357,6 +364,8 @@ TEST_F(ServiceWorkerContainerTest,
stub_provider.RegisterScope());
EXPECT_EQ(WebURL(KURL(NullURL(), "http://localhost/x/y/worker.js")),
stub_provider.RegisterScriptURL());
+ EXPECT_EQ(WebServiceWorkerUpdateViaCache::kImports,
+ stub_provider.UpdateViaCache());
}
}
@@ -376,6 +385,36 @@ TEST_F(ServiceWorkerContainerTest,
EXPECT_EQ(1ul, stub_provider.GetRegistrationCallCount());
EXPECT_EQ(WebURL(KURL(NullURL(), "http://localhost/x/index.html")),
stub_provider.GetRegistrationURL());
+ EXPECT_EQ(WebServiceWorkerUpdateViaCache::kImports,
+ stub_provider.UpdateViaCache());
+ }
+}
+
+TEST_F(ServiceWorkerContainerTest,
+ RegisterUnregister_UpdateViaCacheOptionDelegatesToProvider) {
+ SetPageURL("http://localhost/x/index.html");
+
+ StubWebServiceWorkerProvider stub_provider;
+ Provide(stub_provider.Provider());
+
+ ServiceWorkerContainer* container = ServiceWorkerContainer::Create(
+ GetExecutionContext(), GetNavigatorServiceWorker());
+
+ // register
+ {
+ ScriptState::Scope script_scope(GetScriptState());
+ RegistrationOptions options;
+ options.setUpdateViaCache("none");
+ container->registerServiceWorker(GetScriptState(), "/x/y/worker.js",
+ options);
+
+ EXPECT_EQ(1ul, stub_provider.RegisterCallCount());
+ EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/")),
+ stub_provider.RegisterScope());
+ EXPECT_EQ(WebURL(KURL(KURL(), "http://localhost/x/y/worker.js")),
+ stub_provider.RegisterScriptURL());
+ EXPECT_EQ(WebServiceWorkerUpdateViaCache::kNone,
+ stub_provider.UpdateViaCache());
}
}

Powered by Google App Engine
This is Rietveld 408576698