Index: content/browser/service_worker/service_worker_registration_unittest.cc |
diff --git a/content/browser/service_worker/service_worker_registration_unittest.cc b/content/browser/service_worker/service_worker_registration_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0186c63bc97279b0838ae90c5b77af9f44fb5cc6 |
--- /dev/null |
+++ b/content/browser/service_worker/service_worker_registration_unittest.cc |
@@ -0,0 +1,83 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// 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_registration.h" |
+ |
+#include "base/files/scoped_temp_dir.h" |
+#include "base/logging.h" |
+#include "base/message_loop/message_loop.h" |
+#include "content/browser/browser_thread_impl.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
+ |
+namespace content { |
+ |
+class ServiceWorkerRegistrationTest : public testing::Test { |
+ public: |
+ ServiceWorkerRegistrationTest() |
+ : io_thread_(BrowserThread::IO, &message_loop_) {} |
+ |
+ virtual void SetUp() OVERRIDE {} |
+ |
+ protected: |
+ base::MessageLoopForIO message_loop_; |
+ BrowserThreadImpl io_thread_; |
+}; |
+ |
+TEST_F(ServiceWorkerRegistrationTest, Shutdown) { |
+ |
michaeln
2013/11/13 01:53:24
style nit: blank line not needed (ditto below)
alecflett
2013/11/13 18:28:24
Done.
|
+ int64 registration_id = -1L; |
+ scoped_refptr<ServiceWorkerRegistration> registration = |
+ new ServiceWorkerRegistration( |
+ GURL("http://www.example.com/*"), |
+ GURL("http://www.example.com/service_worker.js"), |
+ registration_id); |
+ |
+ scoped_refptr<ServiceWorkerVersion> active_version = |
+ new ServiceWorkerVersion(registration); |
+ registration->set_active_version(active_version); |
+ |
+ registration->Shutdown(); |
+ |
+ DCHECK(registration->IsShutdown()); |
+ DCHECK(active_version->IsShutdown()); |
+ DCHECK(registration->HasOneRef()); |
+ DCHECK(active_version->HasOneRef()); |
+} |
+ |
+// Make sure that activation does not leak |
+TEST_F(ServiceWorkerRegistrationTest, ActivateInWaiting) { |
+ |
+ int64 registration_id = -1L; |
+ scoped_refptr<ServiceWorkerRegistration> registration = |
+ new ServiceWorkerRegistration( |
+ GURL("http://www.example.com/*"), |
+ GURL("http://www.example.com/service_worker.js"), |
+ registration_id); |
+ |
+ scoped_refptr<ServiceWorkerVersion> version_1 = |
+ new ServiceWorkerVersion(registration); |
+ registration->set_active_version(version_1); |
+ |
+ scoped_refptr<ServiceWorkerVersion> version_2 = |
+ new ServiceWorkerVersion(registration); |
+ registration->set_in_waiting_version(version_2); |
+ |
+ registration->ActivateInWaitingVersion(); |
michaeln
2013/11/13 01:53:24
lets DCHECK_EQ(version_2, registration->active_ver
alecflett
2013/11/13 18:28:24
Done.
|
+ DCHECK(version_1->IsShutdown()); |
+ DCHECK(version_1->HasOneRef()); |
+ version_1 = NULL; |
+ |
+ DCHECK(!version_2->IsShutdown()); |
+ DCHECK(!version_2->HasOneRef()); |
+ |
+ registration->Shutdown(); |
+ |
+ DCHECK(registration->IsShutdown()); |
+ DCHECK(version_2->IsShutdown()); |
+ DCHECK(registration->HasOneRef()); |
+ DCHECK(version_2->HasOneRef()); |
+} |
+ |
+} // namespace content |