This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
app_hosted_use_cached_icon_test.js
85 lines (68 loc) · 2.28 KB
/
app_hosted_use_cached_icon_test.js
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
/* global __dirname */
'use strict';
var AppInstall =
require('../../../../apps/system/test/marionette/lib/app_install');
var createAppServer = require('./server/parent');
marionette('Homescreen - Hosted app cached icon fetch', function() {
var client = marionette.client({
profile: require(__dirname + '/client_options.js')
});
var server;
setup(function(done) {
var app = __dirname + '/fixtures/template_app';
createAppServer(app, client, function(err, _server) {
server = _server;
done(err);
});
});
var home, system, appInstall;
setup(function() {
home = client.loader.getAppClass('homescreen');
system = client.loader.getAppClass('system');
appInstall = new AppInstall(client);
system.waitForFullyLoaded();
});
teardown(function(done) {
server.close(done);
});
test('fallback to default icon', function() {
var iconURL = server.manifest.icons['128'];
// correctly install the app...
client.switchToFrame();
appInstall.install(server.manifestURL);
// switch back to the homescreen
client.switchToFrame(system.getHomescreenIframe());
var icon = home.getIcon(server.manifestURL);
// ensure it is cached
home.waitForIconImageUrl(icon, 'app-icon');
var id = home.getIconId(icon);
client.waitFor(function() {
var metadata = client.executeAsyncScript(function() {
window.wrappedJSObject.appWindow.apps.metadata.getAll().then(
marionetteScriptFinished);
});
for (var i = 0, iLen = metadata.length; i < iLen; i++) {
if (metadata[i].id.startsWith(id) &&
typeof metadata[i].icon !== 'undefined') {
return true;
}
}
return false;
});
// ensure http fails so we use the cached icon
server.fail(iconURL);
// Reload the homescreen
home.restart();
icon = home.getIcon(server.manifestURL);
// check for the cached icon...
home.waitForIconImageUrl(icon, 'user-set');
// allow the request to succeed
server.unfail(iconURL);
// trigger the download of a new icon
client.executeScript(function() {
window.wrappedJSObject.dispatchEvent(new CustomEvent('online'));
});
// now shows the freshly redownloaded icon
home.waitForIconImageUrl(icon, 'app-icon');
});
});