1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var BaseMunger = require('cordova-common').ConfigChanges.PlatformMunger;
|
21 | var PlatformMunger = require('../../template/cordova/lib/ConfigChanges').PlatformMunger;
|
22 | var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
|
23 | var PluginInfo = require('../../template/cordova/lib/PluginInfo.js').PluginInfo;
|
24 | var Api = require('../../template/cordova/Api');
|
25 | var AppxManifest = require('../../template/cordova/lib/AppxManifest');
|
26 |
|
27 | var os = require('os');
|
28 | var path = require('path');
|
29 | var shell = require('shelljs');
|
30 |
|
31 | var configChanges = require('../../template/cordova/lib/ConfigChanges');
|
32 | var tempDir = path.join(os.tmpdir(), 'windows');
|
33 | var WINDOWS_MANIFEST = 'package.windows.appxmanifest';
|
34 | var WINDOWS10_MANIFEST = 'package.windows10.appxmanifest';
|
35 | var FIXTURES = path.join(__dirname, 'fixtures');
|
36 | var DUMMY_PLUGIN = 'org.test.plugins.capabilityplugin';
|
37 | var CONFIG_PLUGIN = 'org.test.configtest';
|
38 |
|
39 | var dummyPlugin = path.join(FIXTURES, DUMMY_PLUGIN);
|
40 | var configplugin = path.join(FIXTURES, CONFIG_PLUGIN);
|
41 | var dummyProjName = 'testProj';
|
42 | var windowsProject = path.join(FIXTURES, dummyProjName);
|
43 | var windows_testapp_jsproj = path.join(FIXTURES, 'testProj/platforms/windows/CordovaApp.Windows.jsproj');
|
44 |
|
45 | describe('PlatformMunger', function () {
|
46 | var munge, munger;
|
47 |
|
48 | beforeEach(function () {
|
49 | shell.mkdir('-p', tempDir);
|
50 | munge = { parents: { 'foo/bar': [
|
51 | { before: undefined, count: 1, xml: '<DummyElement name="Dummy" />' }
|
52 | ] } };
|
53 | munger = new PlatformMunger('windows', tempDir);
|
54 | spyOn(BaseMunger.prototype, 'apply_file_munge').and.callThrough();
|
55 | });
|
56 |
|
57 | afterEach(function () {
|
58 | shell.rm('-rf', tempDir);
|
59 | });
|
60 |
|
61 | describe('apply_file_munge method', function () {
|
62 |
|
63 | it('should call parent\'s method with the same parameters', function () {
|
64 | munger.apply_file_munge(WINDOWS_MANIFEST, munge, false);
|
65 | expect(BaseMunger.prototype.apply_file_munge).toHaveBeenCalledWith(WINDOWS_MANIFEST, munge, false);
|
66 | });
|
67 |
|
68 | it('should additionally call parent\'s method with another munge if removing changes from windows 10 appxmanifest', function () {
|
69 | munger.apply_file_munge(WINDOWS10_MANIFEST, munge, true);
|
70 | expect(BaseMunger.prototype.apply_file_munge).toHaveBeenCalledWith(WINDOWS10_MANIFEST, munge, true);
|
71 | });
|
72 |
|
73 | it('should remove uap: capabilities added by windows prepare step', function () {
|
74 |
|
75 | var baseMunge = { parents: { '/Package/Capabilities': [
|
76 |
|
77 | { before: undefined, count: 1, xml: '<uap:Capability Name=\"privateNetworkClientServer\">' },
|
78 | { before: undefined, count: 1, xml: '<Capability Name=\"enterpriseAuthentication\">' }
|
79 | ] } };
|
80 |
|
81 | var capabilitiesMunge = { parents: { '/Package/Capabilities': [
|
82 | { before: undefined, count: 1, xml: '<uap:Capability Name=\"privateNetworkClientServer\">' },
|
83 | { before: undefined, count: 1, xml: '<uap:Capability Name=\"enterpriseAuthentication\">' }
|
84 | ] } };
|
85 | munger.apply_file_munge(WINDOWS10_MANIFEST, baseMunge, true);
|
86 | expect(BaseMunger.prototype.apply_file_munge).toHaveBeenCalledWith(WINDOWS10_MANIFEST, capabilitiesMunge, true);
|
87 | });
|
88 | });
|
89 | });
|
90 |
|
91 | describe('Capabilities within package.windows.appxmanifest', function () {
|
92 |
|
93 | var testDir, windowsPlatform, windowsManifest, windowsManifest10, dummyPluginInfo, api;
|
94 |
|
95 | beforeEach(function () {
|
96 | testDir = path.join(__dirname, 'testDir');
|
97 | shell.mkdir('-p', testDir);
|
98 | shell.cp('-rf', windowsProject + '/*', testDir);
|
99 | windowsPlatform = path.join(testDir, 'platforms/windows');
|
100 | windowsManifest = path.join(windowsPlatform, WINDOWS_MANIFEST);
|
101 | windowsManifest10 = path.join(windowsPlatform, WINDOWS10_MANIFEST);
|
102 | dummyPluginInfo = new PluginInfo(dummyPlugin);
|
103 | api = new Api();
|
104 | api.root = windowsPlatform;
|
105 | api.locations.root = windowsPlatform;
|
106 | api.locations.www = path.join(windowsPlatform, 'www');
|
107 | });
|
108 |
|
109 | afterEach(function () {
|
110 | shell.rm('-rf', testDir);
|
111 | });
|
112 |
|
113 | function getPluginCapabilities (pluginInfo) {
|
114 | return pluginInfo.getConfigFiles()[0].xmls;
|
115 | }
|
116 |
|
117 | function getManifestCapabilities (manifest) {
|
118 | var appxmanifest = AppxManifest.get(manifest, true);
|
119 | return appxmanifest.getCapabilities();
|
120 | }
|
121 |
|
122 | var fail = jasmine.createSpy('fail')
|
123 | .and.callFake(function (err) {
|
124 | console.error(err);
|
125 | });
|
126 |
|
127 | it('should be removed using overriden PlatformMunger', function (done) {
|
128 | api.addPlugin(dummyPluginInfo)
|
129 | .then(function () {
|
130 |
|
131 | expect(getManifestCapabilities(windowsManifest).length).toBe(getPluginCapabilities(dummyPluginInfo).length + 1);
|
132 | api.removePlugin(dummyPluginInfo);
|
133 | })
|
134 | .then(function () {
|
135 | expect(getManifestCapabilities(windowsManifest).length).toBe(1);
|
136 | })
|
137 | .catch(fail)
|
138 | .finally(function () {
|
139 | expect(fail).not.toHaveBeenCalled();
|
140 | done();
|
141 | });
|
142 | });
|
143 |
|
144 | it('should be added with uap prefixes when install plugin', function (done) {
|
145 | api.addPlugin(dummyPluginInfo)
|
146 | .then(function () {
|
147 |
|
148 | var manifestCapabilities = getManifestCapabilities(windowsManifest10);
|
149 | expect(manifestCapabilities.length).toBe(getPluginCapabilities(dummyPluginInfo).length + 1);
|
150 |
|
151 |
|
152 | var uapPrefixedCapsCount = manifestCapabilities.filter(function (capability) {
|
153 | return capability.type === 'uap:Capability';
|
154 | }).length;
|
155 |
|
156 | expect(uapPrefixedCapsCount).toBe(2);
|
157 | api.removePlugin(dummyPluginInfo);
|
158 | })
|
159 | .then(function () {
|
160 | expect(getManifestCapabilities(windowsManifest10).length).toBe(1);
|
161 | })
|
162 | .catch(fail)
|
163 | .finally(function () {
|
164 | expect(fail).not.toHaveBeenCalled();
|
165 | done();
|
166 | });
|
167 | });
|
168 |
|
169 | it('should be added as DeviceCapabilities when install plugin', function (done) {
|
170 | function isDeviceCapability (capability) {
|
171 | return capability.type === 'DeviceCapability';
|
172 | }
|
173 |
|
174 | function checkCapabilitiesAfterInstall (manifest) {
|
175 |
|
176 | var manifestCapabilities = getManifestCapabilities(manifest);
|
177 | var pluginCapabilities = getPluginCapabilities(dummyPluginInfo);
|
178 |
|
179 | expect(manifestCapabilities.length).toBe(pluginCapabilities.length + 1);
|
180 |
|
181 | var manifestDeviceCapabilties = manifestCapabilities.filter(isDeviceCapability);
|
182 | expect(manifestDeviceCapabilties.length).toBe(1);
|
183 | }
|
184 |
|
185 | function checkCapabilitiesAfterRemove (manifest) {
|
186 | var manifestCapabilities = getManifestCapabilities(manifest);
|
187 | expect(manifestCapabilities.length).toBe(1);
|
188 | }
|
189 |
|
190 | api.addPlugin(dummyPluginInfo)
|
191 | .then(function () {
|
192 | checkCapabilitiesAfterInstall(windowsManifest);
|
193 | checkCapabilitiesAfterInstall(windowsManifest10);
|
194 | api.removePlugin(dummyPluginInfo);
|
195 | })
|
196 | .then(function () {
|
197 | checkCapabilitiesAfterRemove(windowsManifest);
|
198 | checkCapabilitiesAfterRemove(windowsManifest10);
|
199 | })
|
200 | .catch(fail)
|
201 | .finally(function () {
|
202 | expect(fail).not.toHaveBeenCalled();
|
203 | done();
|
204 | });
|
205 | });
|
206 | });
|
207 |
|
208 | describe('generate_plugin_config_munge for windows project', function () {
|
209 | beforeEach(function () {
|
210 | shell.mkdir('-p', tempDir);
|
211 | shell.cp('-rf', windows_testapp_jsproj, tempDir);
|
212 | });
|
213 |
|
214 | afterEach(function () {
|
215 | shell.rm('-rf', tempDir);
|
216 | });
|
217 |
|
218 | it('should special case config-file elements for windows', function () {
|
219 | var pluginInfoProvider = new PluginInfoProvider();
|
220 | var munger = new configChanges.PlatformMunger('windows', tempDir, 'unused', null, pluginInfoProvider);
|
221 | var munge = munger.generate_plugin_config_munge(new PluginInfo(configplugin), {});
|
222 | var windows81AppxManifest = munge.files['package.windows.appxmanifest'];
|
223 | var winphone81AppxManifest = munge.files['package.phone.appxmanifest'];
|
224 | var windows10AppxManifest = munge.files['package.windows10.appxmanifest'];
|
225 |
|
226 |
|
227 | expect(windows81AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />');
|
228 | expect(windows81AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win81-win-and-phone" />');
|
229 | expect(windows81AppxManifest.parents['/Parent/Capabilities'][2].xml).toBe('<Capability Note="should-exist-for-win81-win-only" />');
|
230 | expect(windows81AppxManifest.parents['/Parent/Capabilities'][3].xml).toBe('<Capability Note="should-exist-for-win10-and-win81-win-and-phone" />');
|
231 | expect(windows81AppxManifest.parents['/Parent/Capabilities'].length).toBe(4);
|
232 |
|
233 |
|
234 | expect(winphone81AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />');
|
235 | expect(winphone81AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win81-win-and-phone" />');
|
236 | expect(winphone81AppxManifest.parents['/Parent/Capabilities'][2].xml).toBe('<Capability Note="should-exist-for-win81-phone-only" />');
|
237 | expect(winphone81AppxManifest.parents['/Parent/Capabilities'][3].xml).toBe('<Capability Note="should-exist-for-win10-and-win81-win-and-phone" />');
|
238 | expect(winphone81AppxManifest.parents['/Parent/Capabilities'].length).toBe(4);
|
239 |
|
240 | expect(windows10AppxManifest.parents['/Parent/Capabilities'][0].xml).toBe('<Capability Note="should-exist-for-all-appxmanifest-target-files" />');
|
241 | expect(windows10AppxManifest.parents['/Parent/Capabilities'][1].xml).toBe('<Capability Note="should-exist-for-win10-and-win81-win-and-phone" />');
|
242 | expect(windows10AppxManifest.parents['/Parent/Capabilities'][2].xml).toBe('<Capability Note="should-exist-in-win10-only" />');
|
243 | expect(windows10AppxManifest.parents['/Parent/Capabilities'].length).toBe(3);
|
244 | });
|
245 |
|
246 | it('should not process change w/o target package.appxmanifest', function () {
|
247 | var testChanges = [
|
248 | {
|
249 | target: 'package.windows.appxmanifest'
|
250 | },
|
251 | {
|
252 | target: 'package.appxmanifest'
|
253 | }
|
254 | ];
|
255 |
|
256 | var changes = AppxManifest.processChanges(testChanges);
|
257 | expect(changes.length).toBe(4);
|
258 | expect(changes[0].target).toBe(testChanges[0].target);
|
259 | });
|
260 |
|
261 | it('should apply changes to all manifests in case of incorrect "deviceTarget" attribute', function () {
|
262 | var testChanges = [{
|
263 | deviceTarget: 'wrong_device_target',
|
264 | target: 'package.appxmanifest'
|
265 | }];
|
266 |
|
267 | var changes = AppxManifest.processChanges(testChanges);
|
268 | expect(changes.length).toBe(3);
|
269 | expect(changes[0].target).toBe('package.windows.appxmanifest');
|
270 | expect(changes[1].target).toBe('package.phone.appxmanifest');
|
271 | expect(changes[2].target).toBe('package.windows10.appxmanifest');
|
272 | });
|
273 | });
|