Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/WebKit/LayoutTests/battery-status/resources/mock-battery-monitor.js

Issue 2643713002: Port BatteryMonitor into Device Service (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/device/manifest.json ('k') | third_party/WebKit/Source/modules/battery/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 "use strict"; 1 "use strict";
2 2
3 let mockBatteryMonitor = loadMojoModules( 3 let mockBatteryMonitor = loadMojoModules('mockBatteryMonitor', [
4 'mockBatteryMonitor', 4 'device/battery/battery_monitor.mojom',
5 ['device/battery/battery_monitor.mojom', 5 'device/battery/battery_status.mojom',
6 'device/battery/battery_status.mojom', 6 'services/device/public/interfaces/constants.mojom',
7 'mojo/public/js/bindings', 7 'mojo/public/js/bindings',
8 ]).then(mojo => { 8 ]).then(mojo => {
9 let [batteryMonitor, batteryStatus, bindings] = mojo.modules; 9 let [batteryMonitor, batteryStatus, deviceConstants, bindings] = mojo.modules;
10 10
11 class MockBatteryMonitor { 11 class MockBatteryMonitor {
12 constructor(interfaceProvider) { 12 constructor(connector) {
13 interfaceProvider.addInterfaceOverrideForTesting( 13 connector.addInterfaceOverrideForTesting(
14 batteryMonitor.BatteryMonitor.name, 14 deviceConstants.kServiceName, batteryMonitor.BatteryMonitor.name,
15 handle => this.bindingSet_.addBinding(this, handle)); 15 handle => this.bindingSet_.addBinding(this, handle));
16 16
17 this.interfaceProvider_ = interfaceProvider;
18 this.pendingRequests_ = []; 17 this.pendingRequests_ = [];
19 this.status_ = null; 18 this.status_ = null;
20 this.bindingSet_ = new bindings.BindingSet(batteryMonitor.BatteryMonitor); 19 this.bindingSet_ = new bindings.BindingSet(batteryMonitor.BatteryMonitor);
21 } 20 }
22 21
23 queryNextStatus() { 22 queryNextStatus() {
24 let result = new Promise(resolve => this.pendingRequests_.push(resolve)); 23 let result = new Promise(resolve => this.pendingRequests_.push(resolve));
25 this.runCallbacks_(); 24 this.runCallbacks_();
26 return result; 25 return result;
27 } 26 }
(...skipping 10 matching lines...) Expand all
38 runCallbacks_() { 37 runCallbacks_() {
39 if (!this.status_ || !this.pendingRequests_.length) 38 if (!this.status_ || !this.pendingRequests_.length)
40 return; 39 return;
41 40
42 while (this.pendingRequests_.length) { 41 while (this.pendingRequests_.length) {
43 this.pendingRequests_.pop()({status: this.status_}); 42 this.pendingRequests_.pop()({status: this.status_});
44 } 43 }
45 this.status_ = null; 44 this.status_ = null;
46 } 45 }
47 } 46 }
48 return new MockBatteryMonitor(mojo.interfaces); 47 return new MockBatteryMonitor(mojo.connector);
49 }); 48 });
50 49
51 let batteryInfo; 50 let batteryInfo;
52 let lastSetMockBatteryInfo; 51 let lastSetMockBatteryInfo;
53 52
54 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime, 53 function setAndFireMockBatteryInfo(charging, chargingTime, dischargingTime,
55 level) { 54 level) {
56 lastSetMockBatteryInfo = { charging: charging, 55 lastSetMockBatteryInfo = { charging: charging,
57 chargingTime: chargingTime, 56 chargingTime: chargingTime,
58 dischargingTime: dischargingTime, 57 dischargingTime: dischargingTime,
(...skipping 13 matching lines...) Expand all
72 'lastSetMockBatteryInfo.dischargingTime'); 71 'lastSetMockBatteryInfo.dischargingTime');
73 shouldBe('batteryInfo.level', 'lastSetMockBatteryInfo.level'); 72 shouldBe('batteryInfo.level', 'lastSetMockBatteryInfo.level');
74 } 73 }
75 74
76 function batteryStatusFailure() { 75 function batteryStatusFailure() {
77 testFailed('failed to successfully resolve the promise'); 76 testFailed('failed to successfully resolve the promise');
78 setTimeout(finishJSTest, 0); 77 setTimeout(finishJSTest, 0);
79 } 78 }
80 79
81 var mockBatteryMonitorReady = mockBatteryMonitor.then(); 80 var mockBatteryMonitorReady = mockBatteryMonitor.then();
OLDNEW
« no previous file with comments | « services/device/manifest.json ('k') | third_party/WebKit/Source/modules/battery/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698