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