Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_registration_unittest.cc
blob3fb6611a2f3b2b07b8b93da96588206e4fc464bc
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"
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"
14 namespace content {
16 class ServiceWorkerRegistrationTest : public testing::Test {
17 public:
18 ServiceWorkerRegistrationTest()
19 : io_thread_(BrowserThread::IO, &message_loop_) {}
21 virtual void SetUp() OVERRIDE {}
23 protected:
24 base::MessageLoopForIO message_loop_;
25 BrowserThreadImpl io_thread_;
28 TEST_F(ServiceWorkerRegistrationTest, Shutdown) {
29 const int64 registration_id = -1L;
30 const int64 version_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);
37 scoped_refptr<ServiceWorkerVersion> active_version =
38 new ServiceWorkerVersion(registration, NULL, version_id);
39 registration->set_active_version(active_version);
41 registration->Shutdown();
43 DCHECK(registration->is_shutdown());
44 DCHECK(active_version->is_shutdown());
45 DCHECK(registration->HasOneRef());
46 DCHECK(active_version->HasOneRef());
49 // Make sure that activation does not leak
50 TEST_F(ServiceWorkerRegistrationTest, ActivatePending) {
51 int64 registration_id = -1L;
52 scoped_refptr<ServiceWorkerRegistration> registration =
53 new ServiceWorkerRegistration(
54 GURL("http://www.example.com/*"),
55 GURL("http://www.example.com/service_worker.js"),
56 registration_id);
58 const int64 version_1_id = 1L;
59 const int64 version_2_id = 2L;
60 scoped_refptr<ServiceWorkerVersion> version_1 =
61 new ServiceWorkerVersion(registration, NULL, version_1_id);
62 registration->set_active_version(version_1);
64 scoped_refptr<ServiceWorkerVersion> version_2 =
65 new ServiceWorkerVersion(registration, NULL, version_2_id);
66 registration->set_pending_version(version_2);
68 registration->ActivatePendingVersion();
69 DCHECK_EQ(version_2, registration->active_version());
70 DCHECK(version_1->is_shutdown());
71 DCHECK(version_1->HasOneRef());
72 version_1 = NULL;
74 DCHECK(!version_2->is_shutdown());
75 DCHECK(!version_2->HasOneRef());
77 registration->Shutdown();
79 DCHECK(registration->is_shutdown());
80 DCHECK(version_2->is_shutdown());
81 DCHECK(registration->HasOneRef());
82 DCHECK(version_2->HasOneRef());
85 } // namespace content