OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 | |
5 /** | 4 /** |
6 * @interface | 5 * @interface |
7 */ | 6 */ |
8 class LighthousePort { | 7 class LighthousePort { |
9 /** | 8 /** |
10 * @param {!string} eventName, 'message', 'close' | 9 * @param {!string} eventName, 'message', 'close' |
11 * @param {function(string|undefined)} cb | 10 * @param {function(string|undefined)} cb |
12 */ | 11 */ |
13 on(eventName, cb) { } | 12 on(eventName, cb) { |
| 13 } |
14 | 14 |
15 /** | 15 /** |
16 * @param {string} message | 16 * @param {string} message |
17 */ | 17 */ |
18 send(message) { } | 18 send(message) { |
| 19 } |
19 | 20 |
20 close() { } | 21 close() { |
| 22 } |
21 } | 23 } |
22 | 24 |
23 /** | 25 /** |
24 * @constructor | |
25 * @implements {LighthousePort} | 26 * @implements {LighthousePort} |
26 * @implements {Service} | 27 * @implements {Service} |
| 28 * @unrestricted |
27 */ | 29 */ |
28 function Audits2Service() | 30 var Audits2Service = class { |
29 { | 31 /** |
30 } | 32 * @override |
| 33 * @param {function(string)} |
| 34 */ |
| 35 setNotify(notify) { |
| 36 this._notify = notify; |
| 37 } |
31 | 38 |
32 Audits2Service.prototype = { | 39 /** |
33 /** | 40 * @return {!Promise} |
34 * @override | 41 */ |
35 * @param {function(string)} | 42 start() { |
36 */ | 43 return window.runLighthouseInWorker(this, 'https://www.webkit.org', {flags:
{mobile: true}}, [ |
37 setNotify: function(notify) | 44 'is-on-https', |
38 { | 45 'redirects-http', |
39 this._notify = notify; | 46 'service-worker', |
40 }, | 47 'works-offline', |
| 48 'viewport', |
| 49 'manifest-display', |
| 50 'without-javascript', |
| 51 'first-meaningful-paint', |
| 52 'speed-index-metric', |
| 53 'estimated-input-latency', |
| 54 'time-to-interactive', |
| 55 'user-timings', |
| 56 'screenshots', |
| 57 'critical-request-chains', |
| 58 'manifest-exists', |
| 59 'manifest-background-color', |
| 60 'manifest-theme-color', |
| 61 'manifest-icons-min-192', |
| 62 'manifest-icons-min-144', |
| 63 'manifest-name', |
| 64 'manifest-short-name', |
| 65 'manifest-short-name-length', |
| 66 'manifest-start-url', |
| 67 'meta-theme-color', |
| 68 'aria-valid-attr', |
| 69 'aria-allowed-attr', |
| 70 'color-contrast', |
| 71 'image-alt', |
| 72 'label', |
| 73 'tabindex', |
| 74 'content-width', |
| 75 'geolocation-on-start' |
| 76 ]); |
| 77 } |
41 | 78 |
42 /** | 79 /** |
43 * @return {!Promise} | 80 * @return {!Promise} |
44 */ | 81 */ |
45 start: function() | 82 stop() { |
46 { | 83 this._onClose(); |
47 return window.runLighthouseInWorker(this, "https://www.webkit.org", { fl
ags: { mobile: true } }, [ | 84 return Promise.resolve(); |
48 "is-on-https", | 85 } |
49 "redirects-http", | |
50 "service-worker", | |
51 "works-offline", | |
52 "viewport", | |
53 "manifest-display", | |
54 "without-javascript", | |
55 "first-meaningful-paint", | |
56 "speed-index-metric", | |
57 "estimated-input-latency", | |
58 "time-to-interactive", | |
59 "user-timings", | |
60 "screenshots", | |
61 "critical-request-chains", | |
62 "manifest-exists", | |
63 "manifest-background-color", | |
64 "manifest-theme-color", | |
65 "manifest-icons-min-192", | |
66 "manifest-icons-min-144", | |
67 "manifest-name", | |
68 "manifest-short-name", | |
69 "manifest-short-name-length", | |
70 "manifest-start-url", | |
71 "meta-theme-color", | |
72 "aria-valid-attr", | |
73 "aria-allowed-attr", | |
74 "color-contrast", | |
75 "image-alt", | |
76 "label", | |
77 "tabindex", | |
78 "content-width", | |
79 "geolocation-on-start" | |
80 ]); | |
81 }, | |
82 | 86 |
83 /** | 87 /** |
84 * @return {!Promise} | 88 * @param {!Object=} params |
85 */ | 89 * @return {!Promise} |
86 stop: function() | 90 */ |
87 { | 91 dispatchProtocolMessage(params) { |
88 this._onClose(); | 92 this._onMessage(params['message']); |
89 return Promise.resolve(); | 93 return Promise.resolve(); |
90 }, | 94 } |
91 | 95 |
92 /** | 96 /** |
93 * @param {!Object=} params | 97 * @override |
94 * @return {!Promise} | 98 * @return {!Promise} |
95 */ | 99 */ |
96 dispatchProtocolMessage: function(params) | 100 dispose() { |
97 { | 101 return Promise.resolve(); |
98 this._onMessage(params["message"]); | 102 } |
99 return Promise.resolve(); | |
100 }, | |
101 | 103 |
102 /** | 104 /** |
103 * @override | 105 * @param {string} message |
104 * @return {!Promise} | 106 */ |
105 */ | 107 send(message) { |
106 dispose: function() | 108 this._notify('sendProtocolMessage', {message: message}); |
107 { | 109 } |
108 return Promise.resolve(); | |
109 }, | |
110 | 110 |
111 /** | 111 close() { |
112 * @param {string} message | 112 } |
113 */ | |
114 send: function(message) | |
115 { | |
116 this._notify("sendProtocolMessage", { message: message }); | |
117 }, | |
118 | 113 |
119 close: function() | 114 /** |
120 { | 115 * @param {string} eventName |
121 }, | 116 * @param {function(string|undefined)} cb |
122 | 117 */ |
123 /** | 118 on(eventName, cb) { |
124 * @param {string} eventName | 119 if (eventName === 'message') |
125 * @param {function(string|undefined)} cb | 120 this._onMessage = cb; |
126 */ | 121 if (eventName === 'close') |
127 on: function(eventName, cb) | 122 this._onClose = cb; |
128 { | 123 } |
129 if (eventName === "message") | |
130 this._onMessage = cb; | |
131 if (eventName === "close") | |
132 this._onClose = cb; | |
133 } | |
134 }; | 124 }; |
135 | 125 |
136 // Make lighthouse happy. | 126 // Make lighthouse happy. |
137 global = self; | 127 global = self; |
138 global.isVinn = true; | 128 global.isVinn = true; |
139 global.document = {}; | 129 global.document = {}; |
140 global.document.documentElement = {}; | 130 global.document.documentElement = {}; |
141 global.document.documentElement.style = { WebkitAppearance: "WebkitAppearance"}; | 131 global.document.documentElement.style = { |
| 132 WebkitAppearance: 'WebkitAppearance' |
| 133 }; |
OLD | NEW |