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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/css/fontfaceset-add-remove-while-loading.html

Issue 2629543004: Convert some fontfaceset tests to use jsharness (Closed)
Patch Set: fix minor formatting issue Created 3 years, 11 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
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script> 2 <script src='../../resources/testharness.js'></script>
3 <script src='../../resources/testharnessreport.js'></script>
4
3 <script> 5 <script>
4 description('Tests that FontFaceSet is correctly updated when added or removed a FontFace while loading.');
5
6 window.jsTestIsAsync = true;
7 6
8 function loadingDonePromise() { 7 function loadingDonePromise() {
9 return new Promise(function(resolve) { 8 return new Promise(function(resolve) {
10 function handler(e) { 9 function handler(e) {
11 document.fonts.removeEventListener('loadingdone', handler); 10 document.fonts.removeEventListener('loadingdone', handler);
12 resolve(e); 11 resolve(e);
13 }; 12 };
14 document.fonts.addEventListener('loadingdone', handler); 13 document.fonts.addEventListener('loadingdone', handler);
15 }); 14 });
16 } 15 }
17 16
18 Promise.resolve().then(function() { 17 promise_test(() => {
19 face1 = new FontFace('face1', 'url(../../resources/Ahem.ttf)', {}); 18 let face1 = new FontFace('face1', 'url(../../resources/Ahem.ttf)', {});
20 shouldBeEqualToString('face1.status', 'unloaded'); 19 assert_equals(face1.status, 'unloaded');
21 20
22 face1.load(); 21 let face1Loaded = face1.load();
23 shouldBeEqualToString('face1.status', 'loading'); 22 assert_equals(face1.status, 'loading');
24 shouldBeEqualToString('document.fonts.status', 'loaded'); 23 assert_equals(document.fonts.status, 'loaded')
meade_UTC10 2017/01/13 03:12:45 This is loaded, not loading, because face1 is not
Kunihiko Sakamoto 2017/02/07 10:13:15 That's right.
25 24
26 document.fonts.add(face1); 25 let loadingDone = loadingDonePromise();
27 shouldBeEqualToString('document.fonts.status', 'loading'); 26 document.fonts.add(face1);
28 return document.fonts.ready; 27 assert_equals(document.fonts.status, 'loading');
29 }).then(function() {
30 shouldBeEqualToString('face1.status', 'loaded');
31 shouldBeEqualToString('document.fonts.status', 'loaded');
32 28
33 face2 = new FontFace('face2', 'url(../../resources/Ahem.ttf)', {}); 29 return Promise.all([face1Loaded, loadingDone]).then(() => {
Kunihiko Sakamoto 2017/02/07 10:13:15 Originally this was document.fonts.ready. Didn't t
meade_UTC10 2017/02/09 07:42:33 Huh, it does work. Maybe I was fiddling with somet
34 shouldBeEqualToString('face2.status', 'unloaded'); 30 assert_equals(document.fonts.status, 'loaded');
Kunihiko Sakamoto 2017/02/07 10:13:15 Can you also check that face1.status is 'loaded' h
meade_UTC10 2017/02/09 07:42:33 With this style of tests, face1 is not in scope he
Kunihiko Sakamoto 2017/02/09 08:18:15 Hmm, I think face1 should be accessible here?
meade_UTC10 2017/02/14 00:51:42 oops, I think I misread where this comment is in t
31 });
32 }, 'document.fonts.add() called while a FontFace is loading.');
35 33
36 document.fonts.add(face2); 34 promise_test(() => {
37 var face2loaded = face2.load() 35 assert_equals(document.fonts.status, 'loaded');
38 shouldBeEqualToString('document.fonts.status', 'loading');
39 36
40 var loadingdone = loadingDonePromise(); 37 let face2 = new FontFace('face2', 'url(../../resources/Ahem.ttf)', {});
41 document.fonts.delete(face2); 38 assert_equals(face2.status, 'unloaded');
42 shouldBeEqualToString('document.fonts.status', 'loading');
43 shouldBeEqualToString('face2.status', 'loading');
44 39
45 return Promise.all([face2loaded, loadingdone]); 40 document.fonts.add(face2);
46 }).then(function() { 41 let face2Loaded = face2.load();
47 shouldBeEqualToString('face2.status', 'loaded'); 42 assert_equals(document.fonts.status, 'loading');
48 shouldBeEqualToString('document.fonts.status', 'loaded');
49 43
50 face3 = new FontFace('face3', 'url(../../resources/Ahem.ttf)', {}); 44 let loadingDone = loadingDonePromise();
51 shouldBeEqualToString('face3.status', 'unloaded'); 45 document.fonts.delete(face2);
46 assert_equals(document.fonts.status, 'loading');
47 assert_equals(face2.status, 'loading');
48
49 return Promise.all([face2Loaded, loadingDone]).then(() => {
50 assert_equals(document.fonts.status, 'loaded');
meade_UTC10 2017/01/13 03:12:45 I don't really understand the final checks in this
Kunihiko Sakamoto 2017/02/07 10:13:15 IIRC, these are checking that deleting face2 from
meade_UTC10 2017/02/09 07:42:33 Thanks for the explanation. Another thing I was wo
Kunihiko Sakamoto 2017/02/09 08:18:15 I don't remember why... :) Maybe we can merge thos
meade_UTC10 2017/02/14 00:51:42 Done.
51 });
52 }, 'document.fonts.delete() called while a FontFace is loading.');
53
54 promise_test(() => {
55 assert_equals(document.fonts.status, 'loaded');
56
57 let face3 = new FontFace('face3', 'url(../../resources/Ahem.ttf)', {});
58 assert_equals(face3.status, 'unloaded');
52 59
53 document.fonts.add(face3); 60 document.fonts.add(face3);
54 face3.load(); 61 face3.load();
55 shouldBeEqualToString('document.fonts.status', 'loading'); 62 assert_equals(document.fonts.status, 'loading');
56 63
57 document.fonts.clear(); 64 document.fonts.clear();
58 shouldBeEqualToString('document.fonts.status', 'loading'); 65 assert_equals(document.fonts.status, 'loading');
59 shouldBeEqualToString('face3.status', 'loading'); 66 assert_equals(face3.status, 'loading');
meade_UTC10 2017/01/13 03:12:45 ditto...
60 return document.fonts.ready; 67
61 }).then(function() { 68 return document.fonts.ready.then(() => {
62 shouldBeEqualToString('document.fonts.status', 'loaded'); 69 assert_equals(document.fonts.status, 'loaded');
63 finishJSTest(); 70 });
64 }).catch(function (err) { 71 }, 'document.fonts.clear() called while a FontFace is loading.');
65 testFailed('Unexpected rejection: ' + err);
66 finishJSTest();
67 });
68 72
69 </script> 73 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698