| <!DOCTYPE html> |
| <!-- |
| Copyright 2023 The Cobalt Authors. All Rights Reserved. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <html> |
| |
| <head> |
| <title>Cobalt Telemetry Test</title> |
| <script src='black_box_js_test_utils.js'></script> |
| </head> |
| |
| <body> |
| <script> |
| const metrics = window.h5vcc.metrics; |
| const EVENT_INTERVAL_SECS = 5; |
| let lastMetricType = ''; |
| let lastPayload = ''; |
| let payloadCount = 0; |
| |
| function metricEventHandler(metricType, payload) { |
| lastMetricType = metricType; |
| lastPayload = payload; |
| payloadCount++; |
| } |
| |
| function initTelemetry() { |
| metrics.enable(); |
| metrics.setMetricEventInterval(EVENT_INTERVAL_SECS); |
| metrics.onMetricEvent(metricEventHandler); |
| } |
| window.onload = function () { |
| initTelemetry(); |
| |
| setupFinished(); |
| |
| setTimeout(() => { |
| assertTrue(metrics.isEnabled(), 'metrics should be enabled'); |
| assertEqual('COBALT_UMA', lastMetricType, 'metricType should be uma'); |
| assertTrue(lastPayload.length > 0, 'payload should be non-empty'); |
| assertEqual(1, payloadCount, 'only one payload sent'); |
| }, 4000); |
| |
| setTimeout(() => { |
| assertEqual('COBALT_UMA', lastMetricType, 'metricType should be uma'); |
| assertTrue(lastPayload.length > 0, 'payload should be non-empty'); |
| assertEqual(2, payloadCount, 'two payloads sent'); |
| |
| metrics.disable(); |
| |
| setTimeout(() => { |
| assertFalse(metrics.isEnabled(), 'should disable metrics'); |
| onEndTest(); |
| }, 1000); |
| }, 11000); |
| } |
| </script> |
| </body> |
| |
| </html> |