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

Side by Side Diff: content/browser/service_worker/service_worker_registration_unittest.cc

Issue 70683002: Stub out ServiceWorkerRegistration and Version classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch all parameters to raw pointers Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 int64 registration_id = -1L;
30 scoped_refptr<ServiceWorkerRegistration> registration =
31 new ServiceWorkerRegistration(
32 GURL("http://www.example.com/*"),
33 GURL("http://www.example.com/service_worker.js"),
34 registration_id);
35
36 scoped_refptr<ServiceWorkerVersion> active_version =
37 new ServiceWorkerVersion(registration);
38 registration->set_active_version(active_version);
39
40 registration->Shutdown();
41
42 DCHECK(registration->is_shutdown());
43 DCHECK(active_version->is_shutdown());
44 DCHECK(registration->HasOneRef());
45 DCHECK(active_version->HasOneRef());
46 }
47
48 // Make sure that activation does not leak
49 TEST_F(ServiceWorkerRegistrationTest, ActivatePending) {
50 int64 registration_id = -1L;
51 scoped_refptr<ServiceWorkerRegistration> registration =
52 new ServiceWorkerRegistration(
53 GURL("http://www.example.com/*"),
54 GURL("http://www.example.com/service_worker.js"),
55 registration_id);
56
57 scoped_refptr<ServiceWorkerVersion> version_1 =
58 new ServiceWorkerVersion(registration);
59 registration->set_active_version(version_1);
60
61 scoped_refptr<ServiceWorkerVersion> version_2 =
62 new ServiceWorkerVersion(registration);
63 registration->set_pending_version(version_2);
64
65 registration->ActivatePendingVersion();
66 DCHECK_EQ(version_2, registration->active_version());
67 DCHECK(version_1->is_shutdown());
68 DCHECK(version_1->HasOneRef());
69 version_1 = NULL;
70
71 DCHECK(!version_2->is_shutdown());
72 DCHECK(!version_2->HasOneRef());
73
74 registration->Shutdown();
75
76 DCHECK(registration->is_shutdown());
77 DCHECK(version_2->is_shutdown());
78 DCHECK(registration->HasOneRef());
79 DCHECK(version_2->HasOneRef());
80 }
81
82 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698