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

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

Issue 26442004: Service worker registration error support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Additional issues from michaeln 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) 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.
4
5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/browser/service_worker/service_worker_context.h"
11 #include "content/common/service_worker_messages.h"
12 #include "content/public/common/content_switches.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using base::MessageLoop;
16
17 namespace content {
18
19 class ServiceWorkerDispatcherHostTest : public testing::Test {
20 protected:
21 virtual void SetUp() {
22 context_ = new ServiceWorkerContext(base::FilePath(), NULL);
23 }
24
25 virtual void TearDown() {
26 DCHECK(context_->HasOneRef());
27 context_ = NULL;
28 }
29
30 scoped_refptr<ServiceWorkerContext> context_;
31 };
32
33 namespace {
34
35 static const int kRenderProcessId = 1;
36
37 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
38 public:
39 TestingServiceWorkerDispatcherHost(int process_id,
40 ServiceWorkerContext* context)
41 : ServiceWorkerDispatcherHost(process_id, context) {}
42
43 virtual bool Send(IPC::Message* message) OVERRIDE {
44 sent_messages_.push_back(message);
45 return true;
46 }
47
48 ScopedVector<IPC::Message> sent_messages_;
49
50 protected:
51 virtual ~TestingServiceWorkerDispatcherHost() {}
52 };
53
54 } // namespace
55
56 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) {
57 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
58 switches::kEnableServiceWorker));
59
60 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
61 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_);
62
63 ChildProcessSecurityPolicyImpl* policy =
64 ChildProcessSecurityPolicyImpl::GetInstance();
65 policy->Add(kRenderProcessId);
66
67 bool handled;
68 dispatcher_host->OnMessageReceived(
69 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
70 &handled);
71 DCHECK(handled);
72
73 // TODO(alecflett): Pump the message loop when this becomes async.
74 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
75 DCHECK_EQ(ServiceWorkerMsg_ServiceWorkerRegistered::ID,
76 dispatcher_host->sent_messages_[0]->type());
77 }
78
79 TEST_F(ServiceWorkerDispatcherHostTest, Enabled) {
80 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
81 switches::kEnableServiceWorker));
82 CommandLine::ForCurrentProcess()->AppendSwitch(
83 switches::kEnableServiceWorker);
84
85 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
86 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_);
87
88 ChildProcessSecurityPolicyImpl* policy =
89 ChildProcessSecurityPolicyImpl::GetInstance();
90 policy->Add(kRenderProcessId);
91
92 bool handled;
93 dispatcher_host->OnMessageReceived(
94 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
95 &handled);
96 DCHECK(handled);
97
98 // TODO(alecflett): Pump the message loop when this becomes async.
99 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
100 DCHECK_EQ(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID,
101 dispatcher_host->sent_messages_[0]->type());
102 }
103
104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698