OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 from telemetry.internal.backends.chrome_inspector import inspector_websocket |
5 from telemetry.core import exceptions | 6 from telemetry.core import exceptions |
6 | 7 |
7 | |
8 class InspectorServiceWorker(object): | 8 class InspectorServiceWorker(object): |
9 def __init__(self, inspector_websocket, timeout): | 9 def __init__(self, inspector_socket, timeout): |
10 self._websocket = inspector_websocket | 10 self._websocket = inspector_socket |
11 self._websocket.RegisterDomain('ServiceWorker', self._OnNotification) | 11 self._websocket.RegisterDomain('ServiceWorker', self._OnNotification) |
12 # ServiceWorker.enable RPC must be called before calling any other methods | 12 # ServiceWorker.enable RPC must be called before calling any other methods |
13 # in ServiceWorker domain. | 13 # in ServiceWorker domain. |
14 res = self._websocket.SyncRequest( | 14 res = self._websocket.SyncRequest( |
15 {'method': 'ServiceWorker.enable'}, timeout) | 15 {'method': 'ServiceWorker.enable'}, timeout) |
16 if 'error' in res: | 16 if 'error' in res: |
17 raise exceptions.StoryActionError(res['error']['message']) | 17 raise exceptions.StoryActionError(res['error']['message']) |
18 | 18 |
19 def _OnNotification(self, msg): | 19 def _OnNotification(self, msg): |
20 # TODO: track service worker events | 20 # TODO: track service worker events |
21 # (https://chromedevtools.github.io/devtools-protocol/tot/ServiceWorker/) | 21 # (https://chromedevtools.github.io/devtools-protocol/tot/ServiceWorker/) |
22 pass | 22 pass |
23 | 23 |
24 def StopAllWorkers(self, timeout): | 24 def StopAllWorkers(self, timeout): |
25 res = self._websocket.SyncRequest( | 25 res = self._websocket.SyncRequest( |
26 {'method': 'ServiceWorker.stopAllWorkers'}, timeout) | 26 {'method': 'ServiceWorker.stopAllWorkers'}, timeout) |
27 if 'error' in res: | 27 if 'error' in res: |
| 28 code = res['error']['code'] |
| 29 if code == inspector_websocket.InspectorWebsocket.METHOD_NOT_FOUND_CODE: |
| 30 raise NotImplementedError( |
| 31 'DevTools method ServiceWorker.stopAllWorkers is not supported by ' |
| 32 'this browser.') |
28 raise exceptions.StoryActionError(res['error']['message']) | 33 raise exceptions.StoryActionError(res['error']['message']) |
OLD | NEW |