commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
mark.lam@apple.com | 104d993 | 2013-09-07 22:20:15 +0000 | [diff] [blame] | 3 | <script src="../../resources/js-test-pre.js"></script> |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 4 | <style> |
| 5 | @font-face { |
| 6 | font-family: TestFont1; |
| 7 | src: local('Courier New'); |
| 8 | } |
| 9 | |
| 10 | @font-face { |
| 11 | font-family: TestFont2; |
| 12 | src: url(../../resources/Ahem.ttf); |
| 13 | unicode-range: u+61-7a; /* 'a'-'z' */ |
| 14 | } |
| 15 | </style> |
| 16 | <script> |
| 17 | description('Test load events for fontloader.loadFont() with multiple font families.'); |
| 18 | |
| 19 | window.jsTestIsAsync = true; |
| 20 | |
| 21 | var events = {}; |
| 22 | |
| 23 | function countEvent(e) { |
| 24 | if (!events[e.type]) |
| 25 | events[e.type] = 0; |
| 26 | events[e.type] += 1; |
| 27 | } |
| 28 | |
| 29 | function runTests() { |
betravis@adobe.com | 044d3f9 | 2014-07-31 21:38:27 +0000 | [diff] [blame] | 30 | document.fonts.addEventListener('loading', countEvent); |
| 31 | document.fonts.addEventListener('loadstart', countEvent); |
| 32 | document.fonts.addEventListener('load', countEvent); |
| 33 | document.fonts.addEventListener('error', countEvent); |
| 34 | document.fonts.addEventListener('loadingdone', countEvent); |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 35 | |
betravis@adobe.com | 044d3f9 | 2014-07-31 21:38:27 +0000 | [diff] [blame] | 36 | document.fonts.loadFont({ font: '10px TestFont1, TestFont2', onsuccess: onsuccess, onerror: onerror }); |
| 37 | document.fonts.notifyWhenFontsReady(verify); |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | function onsuccess() { |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | function onerror() { |
| 44 | testFailed("Expected success, but onerror() called"); |
| 45 | } |
| 46 | |
| 47 | function verify() { |
commit-queue@webkit.org | 9107e1d | 2014-11-21 18:43:21 +0000 | [diff] [blame] | 48 | shouldBe("events['loading']", "1"); |
| 49 | shouldBe("events['loadstart']", "2"); |
| 50 | shouldBe("events['load']", "2"); |
| 51 | shouldBe("events['error']", "undefined"); |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 52 | shouldBe("events['loadingdone']", "1"); |
commit-queue@webkit.org | 9107e1d | 2014-11-21 18:43:21 +0000 | [diff] [blame] | 53 | shouldBe("document.fonts.checkFont('10px TestFont1, TestFont2')", "true"); |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 54 | finishJSTest(); |
| 55 | } |
| 56 | |
betravis@adobe.com | 044d3f9 | 2014-07-31 21:38:27 +0000 | [diff] [blame] | 57 | if (document.fonts) |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 58 | runTests(); |
| 59 | else { |
betravis@adobe.com | 044d3f9 | 2014-07-31 21:38:27 +0000 | [diff] [blame] | 60 | testFailed('document.fonts does not exist'); |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 61 | finishJSTest(); |
| 62 | } |
| 63 | </script> |
| 64 | </head> |
| 65 | <body> |
mark.lam@apple.com | 104d993 | 2013-09-07 22:20:15 +0000 | [diff] [blame] | 66 | <script src="../../resources/js-test-post.js"></script> |
commit-queue@webkit.org | d7e6fa2 | 2013-03-14 05:59:58 +0000 | [diff] [blame] | 67 | </body> |
| 68 | </html> |