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

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

Issue 113133013: Refactor job coordination into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove WeakPtr usage from Storage Created 6 years, 11 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_job_unittest.cc
diff --git a/content/browser/service_worker/service_worker_storage_unittest.cc b/content/browser/service_worker/service_worker_job_unittest.cc
similarity index 83%
copy from content/browser/service_worker/service_worker_storage_unittest.cc
copy to content/browser/service_worker/service_worker_job_unittest.cc
index bd6d629eb80a16b124ce0d5aa064e0bb14d6b5e7..79e099609b6b9e728fa75a60cbb99c93ce29e3da 100644
--- a/content/browser/service_worker/service_worker_storage_unittest.cc
+++ b/content/browser/service_worker/service_worker_job_unittest.cc
@@ -2,16 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/service_worker/service_worker_storage.h"
-
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "content/browser/browser_thread_impl.h"
+#include "content/browser/service_worker/service_worker_job_coordinator.h"
#include "content/browser/service_worker/service_worker_registration.h"
+#include "content/browser/service_worker/service_worker_registration_status.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
+// Unit tests for testing all job registration tasks.
namespace content {
namespace {
@@ -46,7 +47,7 @@ void SaveFoundRegistrationCallback(
// it ensures that the resulting status matches the expectation.
// 'called' is useful for making sure a sychronous callback is or
// isn't called.
-ServiceWorkerStorage::RegistrationCallback SaveRegistration(
+ServiceWorkerRegisterJob::RegistrationCallback SaveRegistration(
ServiceWorkerRegistrationStatus expected_status,
bool* called,
scoped_refptr<ServiceWorkerRegistration>* registration) {
@@ -75,7 +76,7 @@ void SaveUnregistrationCallback(ServiceWorkerRegistrationStatus expected_status,
*called = true;
}
-ServiceWorkerStorage::UnregistrationCallback SaveUnregistration(
+ServiceWorkerRegisterJob::UnregistrationCallback SaveUnregistration(
ServiceWorkerRegistrationStatus expected_status,
bool* called) {
*called = false;
@@ -84,13 +85,14 @@ ServiceWorkerStorage::UnregistrationCallback SaveUnregistration(
} // namespace
-class ServiceWorkerStorageTest : public testing::Test {
+class ServiceWorkerJobTest : public testing::Test {
public:
- ServiceWorkerStorageTest()
+ ServiceWorkerJobTest()
: browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
virtual void SetUp() OVERRIDE {
storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL));
+ job_coordinator_.reset(new ServiceWorkerJobCoordinator(storage_.get()));
}
virtual void TearDown() OVERRIDE { storage_.reset(); }
@@ -98,31 +100,13 @@ class ServiceWorkerStorageTest : public testing::Test {
protected:
TestBrowserThreadBundle browser_thread_bundle_;
scoped_ptr<ServiceWorkerStorage> storage_;
+ scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_;
};
-TEST_F(ServiceWorkerStorageTest, PatternMatches) {
- ASSERT_TRUE(ServiceWorkerStorage::PatternMatches(
- GURL("http://www.example.com/*"), GURL("http://www.example.com/")));
- ASSERT_TRUE(ServiceWorkerStorage::PatternMatches(
- GURL("http://www.example.com/*"),
- GURL("http://www.example.com/page.html")));
-
- ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
- GURL("http://www.example.com/*"), GURL("https://www.example.com/")));
- ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
- GURL("http://www.example.com/*"),
- GURL("https://www.example.com/page.html")));
-
- ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
- GURL("http://www.example.com/*"), GURL("http://www.foo.com/")));
- ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
- GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html")));
-}
-
-TEST_F(ServiceWorkerStorageTest, SameDocumentSameRegistration) {
+TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
scoped_refptr<ServiceWorkerRegistration> original_registration;
bool called;
- storage_->Register(
+ job_coordinator_->Register(
GURL("http://www.example.com/*"),
GURL("http://www.example.com/service_worker.js"),
SaveRegistration(REGISTRATION_OK, &called, &original_registration));
@@ -151,10 +135,10 @@ TEST_F(ServiceWorkerStorageTest, SameDocumentSameRegistration) {
ASSERT_EQ(registration1, registration2);
}
-TEST_F(ServiceWorkerStorageTest, SameMatchSameRegistration) {
+TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
bool called;
scoped_refptr<ServiceWorkerRegistration> original_registration;
- storage_->Register(
+ job_coordinator_->Register(
GURL("http://www.example.com/*"),
GURL("http://www.example.com/service_worker.js"),
SaveRegistration(REGISTRATION_OK, &called, &original_registration));
@@ -184,17 +168,17 @@ TEST_F(ServiceWorkerStorageTest, SameMatchSameRegistration) {
ASSERT_EQ(registration1, registration2);
}
-TEST_F(ServiceWorkerStorageTest, DifferentMatchDifferentRegistration) {
+TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
bool called1;
scoped_refptr<ServiceWorkerRegistration> original_registration1;
- storage_->Register(
+ job_coordinator_->Register(
GURL("http://www.example.com/one/*"),
GURL("http://www.example.com/service_worker.js"),
SaveRegistration(REGISTRATION_OK, &called1, &original_registration1));
bool called2;
scoped_refptr<ServiceWorkerRegistration> original_registration2;
- storage_->Register(
+ job_coordinator_->Register(
GURL("http://www.example.com/two/*"),
GURL("http://www.example.com/service_worker.js"),
SaveRegistration(REGISTRATION_OK, &called2, &original_registration2));
@@ -224,12 +208,13 @@ TEST_F(ServiceWorkerStorageTest, DifferentMatchDifferentRegistration) {
}
// Make sure basic registration is working.
-TEST_F(ServiceWorkerStorageTest, Register) {
+TEST_F(ServiceWorkerJobTest, Register) {
bool called = false;
scoped_refptr<ServiceWorkerRegistration> registration;
- storage_->Register(GURL("http://www.example.com/*"),
- GURL("http://www.example.com/service_worker.js"),
- SaveRegistration(REGISTRATION_OK, &called, &registration));
+ job_coordinator_->Register(
+ GURL("http://www.example.com/*"),
+ GURL("http://www.example.com/service_worker.js"),
+ SaveRegistration(REGISTRATION_OK, &called, &registration));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
@@ -239,20 +224,22 @@ TEST_F(ServiceWorkerStorageTest, Register) {
}
// Make sure registrations are cleaned up when they are unregistered.
-TEST_F(ServiceWorkerStorageTest, Unregister) {
+TEST_F(ServiceWorkerJobTest, Unregister) {
GURL pattern("http://www.example.com/*");
bool called;
scoped_refptr<ServiceWorkerRegistration> registration;
- storage_->Register(pattern,
- GURL("http://www.example.com/service_worker.js"),
- SaveRegistration(REGISTRATION_OK, &called, &registration));
+ job_coordinator_->Register(
+ pattern,
+ GURL("http://www.example.com/service_worker.js"),
+ SaveRegistration(REGISTRATION_OK, &called, &registration));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
- storage_->Unregister(pattern, SaveUnregistration(REGISTRATION_OK, &called));
+ job_coordinator_->Unregister(pattern,
+ SaveUnregistration(REGISTRATION_OK, &called));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
@@ -273,12 +260,12 @@ TEST_F(ServiceWorkerStorageTest, Unregister) {
// Make sure that when a new registration replaces an existing
// registration, that the old one is cleaned up.
-TEST_F(ServiceWorkerStorageTest, RegisterNewScript) {
+TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
GURL pattern("http://www.example.com/*");
bool called;
scoped_refptr<ServiceWorkerRegistration> old_registration;
- storage_->Register(
+ job_coordinator_->Register(
pattern,
GURL("http://www.example.com/service_worker.js"),
SaveRegistration(REGISTRATION_OK, &called, &old_registration));
@@ -301,7 +288,7 @@ TEST_F(ServiceWorkerStorageTest, RegisterNewScript) {
old_registration_by_pattern = NULL;
scoped_refptr<ServiceWorkerRegistration> new_registration;
- storage_->Register(
+ job_coordinator_->Register(
pattern,
GURL("http://www.example.com/service_worker_new.js"),
SaveRegistration(REGISTRATION_OK, &called, &new_registration));
@@ -328,13 +315,13 @@ TEST_F(ServiceWorkerStorageTest, RegisterNewScript) {
// Make sure that when registering a duplicate pattern+script_url
// combination, that the same registration is used.
-TEST_F(ServiceWorkerStorageTest, RegisterDuplicateScript) {
+TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
GURL pattern("http://www.example.com/*");
GURL script_url("http://www.example.com/service_worker.js");
bool called;
scoped_refptr<ServiceWorkerRegistration> old_registration;
- storage_->Register(
+ job_coordinator_->Register(
pattern,
script_url,
SaveRegistration(REGISTRATION_OK, &called, &old_registration));
@@ -355,7 +342,7 @@ TEST_F(ServiceWorkerStorageTest, RegisterDuplicateScript) {
ASSERT_TRUE(old_registration_by_pattern);
scoped_refptr<ServiceWorkerRegistration> new_registration;
- storage_->Register(
+ job_coordinator_->Register(
pattern,
script_url,
SaveRegistration(REGISTRATION_OK, &called, &new_registration));

Powered by Google App Engine
This is Rietveld 408576698