OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 *called = true; | 43 *called = true; |
44 *out = status; | 44 *out = status; |
45 } | 45 } |
46 | 46 |
47 void SetUpDummyMessagePort(std::vector<MessagePort>* ports) { | 47 void SetUpDummyMessagePort(std::vector<MessagePort>* ports) { |
48 // Let the other end of the pipe close. | 48 // Let the other end of the pipe close. |
49 mojo::MessagePipe pipe; | 49 mojo::MessagePipe pipe; |
50 ports->push_back(MessagePort(std::move(pipe.handle0))); | 50 ports->push_back(MessagePort(std::move(pipe.handle0))); |
51 } | 51 } |
52 | 52 |
53 void NestedLoopRunUntilIdle() { | |
54 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( | |
55 base::MessageLoop::current()); | |
56 base::RunLoop().RunUntilIdle(); | |
57 } | |
shimazu
2017/04/06 05:01:36
I still don't understand why we need nested loop h
leonhsl(Using Gerrit)
2017/04/06 09:58:55
Yeah actually we do not need nested loop here, I s
| |
58 | |
53 } // namespace | 59 } // namespace |
54 | 60 |
55 static const int kRenderFrameId = 1; | 61 static const int kRenderFrameId = 1; |
56 | 62 |
57 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { | 63 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { |
58 public: | 64 public: |
59 TestingServiceWorkerDispatcherHost( | 65 TestingServiceWorkerDispatcherHost( |
60 int process_id, | 66 int process_id, |
61 ServiceWorkerContextWrapper* context_wrapper, | 67 ServiceWorkerContextWrapper* context_wrapper, |
62 ResourceContext* resource_context, | 68 ResourceContext* resource_context, |
(...skipping 14 matching lines...) Expand all Loading... | |
77 | 83 |
78 protected: | 84 protected: |
79 EmbeddedWorkerTestHelper* helper_; | 85 EmbeddedWorkerTestHelper* helper_; |
80 ~TestingServiceWorkerDispatcherHost() override {} | 86 ~TestingServiceWorkerDispatcherHost() override {} |
81 }; | 87 }; |
82 | 88 |
83 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { | 89 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { |
84 public: | 90 public: |
85 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} | 91 FailToStartWorkerTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} |
86 | 92 |
87 void OnStartWorker( | 93 void OnStartWorker(int embedded_worker_id, |
88 int embedded_worker_id, | 94 int64_t service_worker_version_id, |
89 int64_t service_worker_version_id, | 95 const GURL& scope, |
90 const GURL& scope, | 96 const GURL& script_url, |
91 const GURL& script_url, | 97 bool pause_after_download, |
92 bool pause_after_download, | 98 mojom::ServiceWorkerEventDispatcherRequest request, |
93 mojom::ServiceWorkerEventDispatcherRequest request) override { | 99 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo |
94 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 100 instance_host) override { |
95 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 101 mojom::EmbeddedWorkerInstanceHostAssociatedPtr instance_host_ptr; |
102 instance_host_ptr.Bind(std::move(instance_host)); | |
103 instance_host_ptr->OnStopped(); | |
104 NestedLoopRunUntilIdle(); | |
96 } | 105 } |
97 }; | 106 }; |
98 | 107 |
99 class ServiceWorkerDispatcherHostTest : public testing::Test { | 108 class ServiceWorkerDispatcherHostTest : public testing::Test { |
100 protected: | 109 protected: |
101 ServiceWorkerDispatcherHostTest() | 110 ServiceWorkerDispatcherHostTest() |
102 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 111 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
103 | 112 |
104 void SetUp() override { | 113 void SetUp() override { |
105 Initialize(base::MakeUnique<EmbeddedWorkerTestHelper>(base::FilePath())); | 114 Initialize(base::MakeUnique<EmbeddedWorkerTestHelper>(base::FilePath())); |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( | 840 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( |
832 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, | 841 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, |
833 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), | 842 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), |
834 base::Time::Now())); | 843 base::Time::Now())); |
835 | 844 |
836 base::RunLoop().RunUntilIdle(); | 845 base::RunLoop().RunUntilIdle(); |
837 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); | 846 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); |
838 } | 847 } |
839 | 848 |
840 } // namespace content | 849 } // namespace content |
OLD | NEW |