Skip to content

Commit

Permalink
Bug 1858193: Add a test for parsing font files
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrittervg authored and mergify[bot] committed Nov 20, 2023
1 parent 3eb1972 commit a592499
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions fenix/app/src/androidTest/assets/resources/TestTT_-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From: https://raw.githubusercontent.com/fonttools/fonttools/main/LICENSE

MIT License

Copyright (c) 2017 Just van Rossum

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.mozilla.fenix.components

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mozilla.fenix.components.metrics.fonts.FontEnumerationWorker
import org.mozilla.fenix.components.metrics.fonts.FontParser

class FontParserTest {
@Test
fun testSanityAssertion() {
/*
Changing the below constant causes _all_ Nightly users to send a (large) Telemetry event containing
their font information. Do not change this value unless you explicitly intend this.
*/
assertEquals(1, FontEnumerationWorker.kDesiredSubmissions)
}

@Test
fun testFontParsing() {
val assetManager = InstrumentationRegistry.getInstrumentation().context.assets
val font1 = FontParser.parse("no-path", assetManager.open("resources/TestTTF.ttf"))
assertEquals(
"\u0000T\u0000e\u0000s\u0000t\u0000 \u0000T" +
"\u0000T\u0000F",
font1.family,
)
assertEquals(
"\u0000V\u0000e\u0000r\u0000s\u0000i\u0000o\u0000n\u0000 \u00001\u0000." +
"\u00000\u00000\u00000",
font1.fontVersion,
)
assertEquals(
"\u0000T\u0000e\u0000s\u0000t\u0000 \u0000T\u0000T\u0000F",
font1.fullName,
)
assertEquals("\u0000R\u0000e\u0000g\u0000u\u0000l\u0000a\u0000r", font1.subFamily)
assertEquals(
"\u0000F\u0000o\u0000n\u0000t\u0000T\u0000o\u0000o\u0000l\u0000s\u0000:\u0000 " +
"\u0000T\u0000e\u0000s\u0000t\u0000 \u0000T\u0000T\u0000F\u0000:\u0000 \u00002\u00000\u00001\u00005",
font1.uniqueSubFamily,
)
assertEquals(
"C4E8CE309F44A131D061D73B2580E922A7F5ECC8D7109797AC0FF58BF8723B7B",
font1.hash,
)
assertEquals(3516272951, font1.created)
assertEquals(3573411749, font1.modified)
assertEquals(65536, font1.revision)
val font2 = FontParser.parse("no-path", assetManager.open("resources/TestTTC.ttc"))
assertEquals(
"\u0000T\u0000e\u0000s\u0000t\u0000 \u0000T" +
"\u0000T\u0000F",
font2.family,
)
assertEquals(
"\u0000V\u0000e\u0000r\u0000s\u0000i\u0000o\u0000n\u0000 \u00001\u0000." +
"\u00000\u00000\u00000",
font2.fontVersion,
)
assertEquals(
"\u0000T\u0000e\u0000s\u0000t\u0000 \u0000T\u0000T\u0000F",
font2.fullName,
)
assertEquals("\u0000R\u0000e\u0000g\u0000u\u0000l\u0000a\u0000r", font1.subFamily)
assertEquals(
"\u0000F\u0000o\u0000n\u0000t\u0000T\u0000o\u0000o\u0000l\u0000s\u0000:\u0000 " +
"\u0000T\u0000e\u0000s\u0000t\u0000 \u0000T\u0000T\u0000F\u0000:\u0000 \u00002\u00000\u00001\u00005",
font2.uniqueSubFamily,
)
assertEquals(
"A8521588045ED5F1F8B07EECAAC06ED3186C644655BFAC00DD4507CD316FBDC5",
font2.hash,
)
assertEquals(3516272951, font2.created)
assertEquals(3573411749, font2.modified)
assertEquals(65536, font2.revision)
}
}

0 comments on commit a592499

Please sign in to comment.