2 <script src=
"../../resources/js-test.js"></script>
4 description('Tests that FontFaceSet is correctly updated when added or removed a FontFace while loading.');
6 window
.jsTestIsAsync
= true;
8 function loadingDonePromise() {
9 return new Promise(function(resolve
) {
11 document
.fonts
.removeEventListener('loadingdone', handler
);
14 document
.fonts
.addEventListener('loadingdone', handler
);
18 Promise
.resolve().then(function() {
19 face1
= new FontFace('face1', 'url(../../resources/Ahem.ttf)', {});
20 shouldBeEqualToString('face1.status', 'unloaded');
23 shouldBeEqualToString('face1.status', 'loading');
24 shouldBeEqualToString('document.fonts.status', 'loaded');
26 document
.fonts
.add(face1
);
27 shouldBeEqualToString('document.fonts.status', 'loading');
28 return document
.fonts
.ready
;
30 shouldBeEqualToString('face1.status', 'loaded');
31 shouldBeEqualToString('document.fonts.status', 'loaded');
33 face2
= new FontFace('face2', 'url(../../resources/Ahem.ttf)', {});
34 shouldBeEqualToString('face2.status', 'unloaded');
36 document
.fonts
.add(face2
);
37 var face2loaded
= face2
.load()
38 shouldBeEqualToString('document.fonts.status', 'loading');
40 var loadingdone
= loadingDonePromise();
41 document
.fonts
.delete(face2
);
42 shouldBeEqualToString('document.fonts.status', 'loading');
43 shouldBeEqualToString('face2.status', 'loading');
45 return Promise
.all([face2loaded
, loadingdone
]);
47 shouldBeEqualToString('face2.status', 'loaded');
48 shouldBeEqualToString('document.fonts.status', 'loaded');
50 face3
= new FontFace('face3', 'url(../../resources/Ahem.ttf)', {});
51 shouldBeEqualToString('face3.status', 'unloaded');
53 document
.fonts
.add(face3
);
55 shouldBeEqualToString('document.fonts.status', 'loading');
57 document
.fonts
.clear();
58 shouldBeEqualToString('document.fonts.status', 'loading');
59 shouldBeEqualToString('face3.status', 'loading');
60 return document
.fonts
.ready
;
62 shouldBeEqualToString('document.fonts.status', 'loaded');
64 }).catch(function (err
) {
65 testFailed('Unexpected rejection: ' + err
);