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

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

Issue 61023005: service worker scaffolding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "content/browser/service_worker/service_worker_context.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/common/service_worker_messages.h" 10 #include "content/common/service_worker_messages.h"
11 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using base::MessageLoop; 14 using base::MessageLoop;
15 15
16 namespace content { 16 namespace content {
17 17
18 class ServiceWorkerDispatcherHostTest : public testing::Test { 18 class ServiceWorkerDispatcherHostTest : public testing::Test {
19 protected: 19 protected:
20 virtual void SetUp() { 20 virtual void SetUp() {
21 context_ = new ServiceWorkerContext(base::FilePath(), NULL); 21 context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL));
22 } 22 }
23 23
24 virtual void TearDown() { 24 virtual void TearDown() {
25 DCHECK(context_->HasOneRef()); 25 context_.reset();
26 context_ = NULL;
27 } 26 }
28 27
29 scoped_refptr<ServiceWorkerContext> context_; 28 scoped_ptr<ServiceWorkerContextCore> context_;
30 }; 29 };
31 30
32 namespace {
33
34 static const int kRenderProcessId = 1; 31 static const int kRenderProcessId = 1;
35 32
36 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { 33 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
37 public: 34 public:
38 TestingServiceWorkerDispatcherHost(int process_id, 35 TestingServiceWorkerDispatcherHost(int process_id,
39 ServiceWorkerContext* context) 36 ServiceWorkerContextCore* context)
40 : ServiceWorkerDispatcherHost(process_id, context) {} 37 : ServiceWorkerDispatcherHost(process_id) {
38 context_ = context->AsWeakPtr();
39 }
41 40
42 virtual bool Send(IPC::Message* message) OVERRIDE { 41 virtual bool Send(IPC::Message* message) OVERRIDE {
43 sent_messages_.push_back(message); 42 sent_messages_.push_back(message);
44 return true; 43 return true;
45 } 44 }
46 45
47 ScopedVector<IPC::Message> sent_messages_; 46 ScopedVector<IPC::Message> sent_messages_;
48 47
49 protected: 48 protected:
50 virtual ~TestingServiceWorkerDispatcherHost() {} 49 virtual ~TestingServiceWorkerDispatcherHost() {}
51 }; 50 };
52 51
53 } // namespace
54 52
55 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) { 53 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) {
56 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( 54 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kEnableServiceWorker)); 55 switches::kEnableServiceWorker));
58 56
59 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = 57 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
60 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_); 58 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_.get());
61 59
62 bool handled; 60 bool handled;
63 dispatcher_host->OnMessageReceived( 61 dispatcher_host->OnMessageReceived(
64 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), 62 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
65 &handled); 63 &handled);
66 DCHECK(handled); 64 DCHECK(handled);
67 65
68 // TODO(alecflett): Pump the message loop when this becomes async. 66 // TODO(alecflett): Pump the message loop when this becomes async.
69 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size()); 67 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
70 DCHECK_EQ( 68 DCHECK_EQ(
71 static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID), 69 static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID),
72 dispatcher_host->sent_messages_[0]->type()); 70 dispatcher_host->sent_messages_[0]->type());
73 } 71 }
74 72
75 TEST_F(ServiceWorkerDispatcherHostTest, Enabled) { 73 TEST_F(ServiceWorkerDispatcherHostTest, Enabled) {
76 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( 74 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
77 switches::kEnableServiceWorker)); 75 switches::kEnableServiceWorker));
78 CommandLine::ForCurrentProcess()->AppendSwitch( 76 CommandLine::ForCurrentProcess()->AppendSwitch(
79 switches::kEnableServiceWorker); 77 switches::kEnableServiceWorker);
80 78
81 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = 79 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
82 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_); 80 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_.get());
83 81
84 bool handled; 82 bool handled;
85 dispatcher_host->OnMessageReceived( 83 dispatcher_host->OnMessageReceived(
86 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), 84 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
87 &handled); 85 &handled);
88 DCHECK(handled); 86 DCHECK(handled);
89 87
90 // TODO(alecflett): Pump the message loop when this becomes async. 88 // TODO(alecflett): Pump the message loop when this becomes async.
91 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size()); 89 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
92 DCHECK_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID), 90 DCHECK_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID),
93 dispatcher_host->sent_messages_[0]->type()); 91 dispatcher_host->sent_messages_[0]->type());
94 } 92 }
95 93
96 } // namespace content 94 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698