1 // Copyright 2013 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.
5 #include "content/browser/service_worker/service_worker_registration.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/service_worker/service_worker_context_core.h"
13 #include "testing/gtest/include/gtest/gtest.h"
18 class ServiceWorkerRegistrationTest
: public testing::Test
{
20 ServiceWorkerRegistrationTest()
21 : io_thread_(BrowserThread::IO
, &message_loop_
) {}
23 virtual void SetUp() OVERRIDE
{
24 context_
.reset(new ServiceWorkerContextCore(
26 base::MessageLoopProxy::current(),
29 scoped_ptr
<ServiceWorkerProcessManager
>()));
30 context_ptr_
= context_
->AsWeakPtr();
34 scoped_ptr
<ServiceWorkerContextCore
> context_
;
35 base::WeakPtr
<ServiceWorkerContextCore
> context_ptr_
;
36 base::MessageLoopForIO message_loop_
;
37 BrowserThreadImpl io_thread_
;
40 // Make sure that activation does not leak
41 TEST_F(ServiceWorkerRegistrationTest
, ActivatePending
) {
42 int64 registration_id
= -1L;
43 scoped_refptr
<ServiceWorkerRegistration
> registration
=
44 new ServiceWorkerRegistration(
45 GURL("http://www.example.com/*"),
46 GURL("http://www.example.com/service_worker.js"),
50 const int64 version_1_id
= 1L;
51 const int64 version_2_id
= 2L;
52 scoped_refptr
<ServiceWorkerVersion
> version_1
=
53 new ServiceWorkerVersion(registration
, version_1_id
, context_ptr_
);
54 version_1
->SetStatus(ServiceWorkerVersion::ACTIVE
);
55 registration
->set_active_version(version_1
);
57 scoped_refptr
<ServiceWorkerVersion
> version_2
=
58 new ServiceWorkerVersion(registration
, version_2_id
, context_ptr_
);
59 registration
->set_pending_version(version_2
);
61 registration
->ActivatePendingVersion();
62 DCHECK_EQ(version_2
, registration
->active_version());
63 DCHECK(version_1
->HasOneRef());
66 DCHECK(!version_2
->HasOneRef());
69 } // namespace content