OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 class MockEmbeddedWorkerInstanceClient | 66 class MockEmbeddedWorkerInstanceClient |
67 : public mojom::EmbeddedWorkerInstanceClient { | 67 : public mojom::EmbeddedWorkerInstanceClient { |
68 public: | 68 public: |
69 explicit MockEmbeddedWorkerInstanceClient( | 69 explicit MockEmbeddedWorkerInstanceClient( |
70 base::WeakPtr<EmbeddedWorkerTestHelper> helper); | 70 base::WeakPtr<EmbeddedWorkerTestHelper> helper); |
71 ~MockEmbeddedWorkerInstanceClient() override; | 71 ~MockEmbeddedWorkerInstanceClient() override; |
72 | 72 |
73 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 73 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
74 mojom::EmbeddedWorkerInstanceClientRequest request); | 74 mojom::EmbeddedWorkerInstanceClientRequest request); |
75 | 75 |
76 private: | 76 protected: |
77 // Implementation of mojo interfaces. | 77 // Implementation of mojo interfaces. |
78 void StartWorker(const EmbeddedWorkerStartParams& params) override; | 78 void StartWorker(const EmbeddedWorkerStartParams& params) override; |
| 79 void StopWorker(const StopWorkerCallback& callback) override; |
79 | 80 |
80 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; | 81 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; |
81 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; | 82 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; |
82 | 83 |
83 base::Optional<int> embedded_worker_id_; | 84 base::Optional<int> embedded_worker_id_; |
84 | 85 |
| 86 private: |
85 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient); | 87 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient); |
86 }; | 88 }; |
87 | 89 |
88 // If |user_data_directory| is empty, the context makes storage stuff in | 90 // If |user_data_directory| is empty, the context makes storage stuff in |
89 // memory. | 91 // memory. |
90 explicit EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory); | 92 explicit EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory); |
91 ~EmbeddedWorkerTestHelper() override; | 93 ~EmbeddedWorkerTestHelper() override; |
92 | 94 |
93 // Call this to simulate add/associate a process to a pattern. | 95 // Call this to simulate add/associate a process to a pattern. |
94 // This also registers this sender for the process. | 96 // This also registers this sender for the process. |
95 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); | 97 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); |
96 | 98 |
97 // IPC::Sender implementation. | 99 // IPC::Sender implementation. |
98 bool Send(IPC::Message* message) override; | 100 bool Send(IPC::Message* message) override; |
99 | 101 |
100 // IPC::Listener implementation. | 102 // IPC::Listener implementation. |
101 bool OnMessageReceived(const IPC::Message& msg) override; | 103 bool OnMessageReceived(const IPC::Message& msg) override; |
102 | 104 |
| 105 // Register a mojo endpoint object derived from |
| 106 // MockEmbeddedWorkerInstanceClient. |
| 107 void RegisterMockInstanceClient( |
| 108 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); |
| 109 |
103 // IPC sink for EmbeddedWorker messages. | 110 // IPC sink for EmbeddedWorker messages. |
104 IPC::TestSink* ipc_sink() { return &sink_; } | 111 IPC::TestSink* ipc_sink() { return &sink_; } |
105 // Inner IPC sink for script context messages sent via EmbeddedWorker. | 112 // Inner IPC sink for script context messages sent via EmbeddedWorker. |
106 IPC::TestSink* inner_ipc_sink() { return &inner_sink_; } | 113 IPC::TestSink* inner_ipc_sink() { return &inner_sink_; } |
107 | 114 |
108 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* | 115 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* |
109 mock_instance_clients() { | 116 mock_instance_clients() { |
110 return &mock_instance_clients_; | 117 return &mock_instance_clients_; |
111 } | 118 } |
112 | 119 |
(...skipping 10 matching lines...) Expand all Loading... |
123 | 130 |
124 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() { | 131 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() { |
125 return embedded_worker_id_service_worker_version_id_map_; | 132 return embedded_worker_id_service_worker_version_id_map_; |
126 } | 133 } |
127 | 134 |
128 // Only used for tests that force creating a new render process. | 135 // Only used for tests that force creating a new render process. |
129 int new_render_process_id() const { return new_mock_render_process_id_; } | 136 int new_render_process_id() const { return new_mock_render_process_id_; } |
130 | 137 |
131 TestBrowserContext* browser_context() { return browser_context_.get(); } | 138 TestBrowserContext* browser_context() { return browser_context_.get(); } |
132 | 139 |
| 140 base::WeakPtr<EmbeddedWorkerTestHelper> AsWeakPtr() { |
| 141 return weak_factory_.GetWeakPtr(); |
| 142 } |
| 143 |
133 protected: | 144 protected: |
134 // Called when StartWorker, StopWorker and SendMessageToWorker message | 145 // Called when StartWorker, StopWorker and SendMessageToWorker message |
135 // is sent to the embedded worker. Override if necessary. By default | 146 // is sent to the embedded worker. Override if necessary. By default |
136 // they verify given parameters and: | 147 // they verify given parameters and: |
137 // - OnStartWorker calls SimulateWorkerStarted | 148 // - OnStartWorker calls SimulateWorkerStarted |
138 // - OnStopWorker calls SimulateWorkerStoped | 149 // - OnStopWorker calls SimulateWorkerStoped |
139 // - OnSendMessageToWorker calls the message's respective On*Event handler | 150 // - OnSendMessageToWorker calls the message's respective On*Event handler |
140 virtual void OnStartWorker(int embedded_worker_id, | 151 virtual void OnStartWorker(int embedded_worker_id, |
141 int64_t service_worker_version_id, | 152 int64_t service_worker_version_id, |
142 const GURL& scope, | 153 const GURL& scope, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 message_port_message_filters_; | 257 message_port_message_filters_; |
247 | 258 |
248 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; | 259 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; |
249 | 260 |
250 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); | 261 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); |
251 }; | 262 }; |
252 | 263 |
253 } // namespace content | 264 } // namespace content |
254 | 265 |
255 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 266 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
OLD | NEW |