1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1037329
-->
<head>
<meta charset="utf-8">
<title>System Update API Test</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1037329">Test System Update API</a>
<script type="application/javascript;version=1.8">
'use strict';
SimpleTest.waitForExplicitFinish();
function setup() {
window.gUrl = SimpleTest.getTestFileURL('preload-SystemUpdateManager-jsm.js');
window.gScript = SpecialPowers.loadChromeScript(gUrl);
return Promise.resolve();
}
function testGetProviders() {
return new Promise(function(resolve, reject) {
navigator.updateManager.getProviders().then(function(providerInfos) {
info('num of providers: ' + providerInfos.length);
for (let providerInfo of providerInfos) {
info('provider info: ' + JSON.stringify(providerInfo));
}
resolve(providerInfos);
});
});
}
function testSetActiveProvider(providerInfos) {
return new Promise(function(resolve, reject) {
//Find the mock provider for our testing provider instead.
//Set the mock provider as active provider.
let targetProvider = providerInfos[0];
for(let provider of providerInfos) {
if(provider.uuid == "{17a84227-28f4-453d-9b80-9ae75a5682e0}") {
info('target provider uuid: ' + provider.uuid);
targetProvider = provider;
break;
}
}
is("{17a84227-28f4-453d-9b80-9ae75a5682e0}", targetProvider.uuid, 'get the dynamically added provider');
navigator.updateManager.setActiveProvider(targetProvider.uuid).then(function(activeProvider) {
info('active provider info: ' + JSON.stringify(activeProvider.info));
is(activeProvider.name, targetProvider.name, 'expected name of active provider');
is(activeProvider.uuid, targetProvider.uuid, 'expected uuid of active provider');
resolve({name : activeProvider.name, uuid : activeProvider.uuid});
});
});
}
function testGetActiveProvider(providerInfo) {
info('test GetActiveProvider');
return new Promise(function(resolve, reject) {
navigator.updateManager.getActiveProvider().then(function(activeProvider) {
is(activeProvider.name, providerInfo.name, 'expected name of active provider');
is(activeProvider.uuid, providerInfo.uuid, 'expected uuid of active provider');
resolve(activeProvider);
});
});
}
function testCheckForUpdate(provider) {
info('test CheckForUpdate');
return new Promise(function(resolve, reject) {
provider.addEventListener('updateavailable', function(event) {
ok(true, 'receive updateavailable event');
info('event: ' + JSON.stringify(event.detail));
resolve(provider);
});
provider.checkForUpdate();
});
}
function testStartDownload(provider) {
info('test StartDownload');
return new Promise(function(resolve, reject) {
provider.addEventListener('progress', function(event) {
ok(true, 'receive progress event');
is(event.loaded, 10, 'expected loaded');
is(event.total, 100, 'expected total');
resolve(provider);
});
provider.startDownload();
});
}
function testStopDownload(provider) {
info('test StopDownload');
return new Promise(function(resolve, reject) {
provider.stopDownload();
resolve(provider);
});
}
function testApplyUpdate(provider) {
info('test ApplyUpdate');
return new Promise(function(resolve, reject) {
provider.applyUpdate();
resolve(provider);
});
}
function testGetParameter(provider) {
info('test GetParameter');
return new Promise(function(resolve, reject) {
let dummy = provider.getParameter('dummy');
is(dummy, 'dummy-value', 'expected parameter');
resolve(provider);
});
}
function testSetParameter(provider) {
info('test SetParameter');
return new Promise(function(resolve, reject) {
provider.setParameter('dummy', 'dummy-value');
resolve();
});
}
function testSetActiveProviderError() {
info('test setActiveProvider error');
return new Promise(function(resolve, reject) {
navigator.updateManager.setActiveProvider('something not exsited').then(function(provider) {
ok(false, 'should not success');
resolve();
}, function(reason) {
info('error message: ' + reason);
ok(true, 'expected error while setActiveProvider');
resolve();
});
});
}
function runTest() {
ok(navigator.updateManager, 'should have navigator.updateManager');
setup()
.then(testGetProviders)
.then(testSetActiveProvider)
.then(testGetActiveProvider)
.then(testCheckForUpdate)
.then(testStartDownload)
.then(testStopDownload)
.then(testApplyUpdate)
.then(testGetParameter)
.then(testSetParameter)
.then(testSetActiveProviderError)
.then(function() {
info('test finished');
gScript.destroy();
SimpleTest.finish();
});
}
SpecialPowers.pushPermissions([
{type: 'system-update', allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({
'set': [
['dom.system_update.enabled', true],
['dom.system_update.debug', true],
['dom.system_update.active', '@mozilla.org/test-update-provider;1'],
]
}, runTest);
}
);
</script>
</pre>
</body>
</html>
|