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

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: re-fix tests 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/service_worker/service_worker_context.h"
10 #include "content/common/service_worker_messages.h"
11 #include "content/public/common/content_switches.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using base::MessageLoop;
15
16 namespace content {
17
18 class ServiceWorkerDispatcherHostTest : public testing::Test {
19 protected:
20 virtual void SetUp() {
21 context_ = new ServiceWorkerContext(base::FilePath(), NULL);
22 }
23
24 virtual void TearDown() {
25 DCHECK(context_->HasOneRef());
26 context_ = NULL;
27 }
28
29 scoped_refptr<ServiceWorkerContext> context_;
30 };
31
32 namespace {
33
34 static const int kRenderProcessId = 1;
35
36 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
37 public:
38 TestingServiceWorkerDispatcherHost(int process_id,
39 ServiceWorkerContext* context)
40 : ServiceWorkerDispatcherHost(process_id, context) {}
41
42 virtual bool Send(IPC::Message* message) OVERRIDE {
43 sent_messages_.push_back(message);
44 return true;
45 }
46
47 ScopedVector<IPC::Message> sent_messages_;
48
49 protected:
50 virtual ~TestingServiceWorkerDispatcherHost() {}
51 };
52
53 } // namespace
54
55 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) {
56 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kEnableServiceWorker));
58
59 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
60 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_);
61
62 bool handled;
63 dispatcher_host->OnMessageReceived(
64 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
65 &handled);
66 DCHECK(handled);
67
68 // TODO(alecflett): Pump the message loop when this becomes async.
69 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
70 DCHECK_EQ(
71 static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID),
72 dispatcher_host->sent_messages_[0]->type());
73 }
74
75 TEST_F(ServiceWorkerDispatcherHostTest, Enabled) {
76 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
77 switches::kEnableServiceWorker));
78 CommandLine::ForCurrentProcess()->AppendSwitch(
79 switches::kEnableServiceWorker);
80
81 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
82 new TestingServiceWorkerDispatcherHost(kRenderProcessId, context_);
83
84 bool handled;
85 dispatcher_host->OnMessageReceived(
86 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
87 &handled);
88 DCHECK(handled);
89
90 // TODO(alecflett): Pump the message loop when this becomes async.
91 DCHECK_EQ(1UL, dispatcher_host->sent_messages_.size());
92 DCHECK_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID),
93 dispatcher_host->sent_messages_[0]->type());
94 }
95
96 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698