OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/service_worker/service_worker_registration.h" | |
6 | |
7 #include "base/files/scoped_temp_dir.h" | |
8 #include "base/logging.h" | |
9 #include "base/message_loop/message_loop.h" | |
10 #include "content/browser/browser_thread_impl.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "url/gurl.h" | |
13 | |
14 namespace content { | |
15 | |
16 class ServiceWorkerRegistrationTest : public testing::Test { | |
17 public: | |
18 ServiceWorkerRegistrationTest() | |
19 : io_thread_(BrowserThread::IO, &message_loop_) {} | |
20 | |
21 virtual void SetUp() OVERRIDE {} | |
22 | |
23 protected: | |
24 base::MessageLoopForIO message_loop_; | |
25 BrowserThreadImpl io_thread_; | |
26 }; | |
27 | |
28 TEST_F(ServiceWorkerRegistrationTest, Shutdown) { | |
29 | |
michaeln
2013/11/13 01:53:24
style nit: blank line not needed (ditto below)
alecflett
2013/11/13 18:28:24
Done.
| |
30 int64 registration_id = -1L; | |
31 scoped_refptr<ServiceWorkerRegistration> registration = | |
32 new ServiceWorkerRegistration( | |
33 GURL("http://www.example.com/*"), | |
34 GURL("http://www.example.com/service_worker.js"), | |
35 registration_id); | |
36 | |
37 scoped_refptr<ServiceWorkerVersion> active_version = | |
38 new ServiceWorkerVersion(registration); | |
39 registration->set_active_version(active_version); | |
40 | |
41 registration->Shutdown(); | |
42 | |
43 DCHECK(registration->IsShutdown()); | |
44 DCHECK(active_version->IsShutdown()); | |
45 DCHECK(registration->HasOneRef()); | |
46 DCHECK(active_version->HasOneRef()); | |
47 } | |
48 | |
49 // Make sure that activation does not leak | |
50 TEST_F(ServiceWorkerRegistrationTest, ActivateInWaiting) { | |
51 | |
52 int64 registration_id = -1L; | |
53 scoped_refptr<ServiceWorkerRegistration> registration = | |
54 new ServiceWorkerRegistration( | |
55 GURL("http://www.example.com/*"), | |
56 GURL("http://www.example.com/service_worker.js"), | |
57 registration_id); | |
58 | |
59 scoped_refptr<ServiceWorkerVersion> version_1 = | |
60 new ServiceWorkerVersion(registration); | |
61 registration->set_active_version(version_1); | |
62 | |
63 scoped_refptr<ServiceWorkerVersion> version_2 = | |
64 new ServiceWorkerVersion(registration); | |
65 registration->set_in_waiting_version(version_2); | |
66 | |
67 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.
| |
68 DCHECK(version_1->IsShutdown()); | |
69 DCHECK(version_1->HasOneRef()); | |
70 version_1 = NULL; | |
71 | |
72 DCHECK(!version_2->IsShutdown()); | |
73 DCHECK(!version_2->HasOneRef()); | |
74 | |
75 registration->Shutdown(); | |
76 | |
77 DCHECK(registration->IsShutdown()); | |
78 DCHECK(version_2->IsShutdown()); | |
79 DCHECK(registration->HasOneRef()); | |
80 DCHECK(version_2->HasOneRef()); | |
81 } | |
82 | |
83 } // namespace content | |
OLD | NEW |