battery-status-helpers.js (1174B)
1 'use strict'; 2 3 // These tests rely on the User Agent providing an implementation of 4 // platform battery status backends. 5 // 6 // In Chromium-based browsers this implementation is provided by a polyfill 7 // in order to reduce the amount of test-only code shipped to users. To enable 8 // these tests the browser must be run with these options: 9 // 10 // --enable-blink-features=MojoJS,MojoJSTest 11 12 let mockBatteryMonitor = undefined; 13 14 function assert_implements_battery() { 15 assert_implements(navigator.getBattery, 'missing navigator.getBattery'); 16 } 17 18 function battery_status_test(func, name, properties) { 19 promise_test(async t => { 20 if (mockBatteryMonitor === undefined) { 21 if (isChromiumBased) { 22 const mocks = 23 await import('/resources/chromium/mock-battery-monitor.js'); 24 mockBatteryMonitor = mocks.mockBatteryMonitor; 25 } 26 } 27 assert_implements( 28 mockBatteryMonitor, 'missing mockBatteryMonitor after initialization'); 29 30 mockBatteryMonitor.start(); 31 32 t.add_cleanup(() => { 33 mockBatteryMonitor.reset(); 34 return mockBatteryMonitor.stop(); 35 }); 36 return func(t, mockBatteryMonitor); 37 }, name, properties); 38 }