Commit 04b4421b authored by Roger Yang's avatar Roger Yang Committed by Jonathan Almeida
Browse files

No issue: Add validate code set

parent 6d86e0a6
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -11,6 +11,17 @@ private const val SEARCH_TYPE_SAP_FOLLOW_ON = "sap-follow-on"
private const val SEARCH_TYPE_SAP = "sap"
private const val SEARCH_TYPE_ORGANIC = "organic"
private const val CHANNEL_KEY = "channel"
private val validCodeSet = setOf(
    "MOZ2", "MOZ4", "MOZ5", "MOZA", "MOZB", "MOZD", "MOZE", "MOZI", "MOZM", "MOZO", "MOZT",
    "MOZW", "MOZSL01", "MOZSL02", "MOZSL03", "monline_dg", "monline_3_dg", "monline_4_dg",
    "monline_7_dg", "firefox-a", "firefox-b", "firefox-b-1", "firefox-b-ab", "firefox-b-1-ab",
    "firefox-b-d", "firefox-b-1-d", "firefox-b-e", "firefox-b-1-e", "firefox-b-m",
    "firefox-b-1-m", "firefox-b-o", "firefox-b-1-o", "firefox-b-lm", "firefox-b-1-lm",
    "firefox-b-lg", "firefox-b-huawei-h1611", "firefox-b-is-oem1", "firefox-b-oem1",
    "firefox-b-oem2", "firefox-b-tinno", "firefox-b-pn-wt", "firefox-b-pn-wt-us", "ubuntu",
    "ffab", "ffcm", "ffhp", "ffip", "ffit", "ffnt", "ffocus", "ffos", "ffsb", "fpas", "fpsa",
    "ftas", "ftsa", "newext", "1000969a"
)

/**
 * Get a String in a specific format allowing to identify how an ads/search provider was used.
@@ -35,6 +46,11 @@ internal fun getTrackKey(
                .substringBefore("/", "")
        }

        // For Bug 1751920
        if (!validCodeSet.contains(code)) {
            code = null
        }

        // Glean doesn't allow code starting with a figure
        if (code != null && code.isNotEmpty()) {
            val codeStart = code.first()
+20 −1
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ class InContentTelemetryTest {
        assertEquals(Component.FEATURE_SEARCH, facts[0].component)
        assertEquals(Action.INTERACTION, facts[0].action)
        assertEquals(InContentTelemetry.IN_CONTENT_SEARCH, facts[0].item)
        assertEquals("bing.in-content.sap.mozmba", facts[0].value)
        assertEquals("bing.in-content.sap.none", facts[0].value)
    }

    @Test
@@ -165,6 +165,25 @@ class InContentTelemetryTest {
        assertEquals("google.in-content.sap-follow-on.firefox-b-m", facts[0].value)
    }

    @Test
    fun `GIVEN a invalid Google sap-follow-on WHEN trackPartnerUrlTypeMetric is called THEN emit an appropriate IN_CONTENT_SEARCH fact`() {
        val url = "https://www.google.com/search?q=aaa&client=firefox-b-mTesting&oq=random"
        val facts = mutableListOf<Fact>()
        Facts.registerProcessor(object : FactProcessor {
            override fun process(fact: Fact) {
                facts.add(fact)
            }
        })

        telemetry.trackPartnerUrlTypeMetric(url, listOf())

        assertEquals(1, facts.size)
        assertEquals(Component.FEATURE_SEARCH, facts[0].component)
        assertEquals(Action.INTERACTION, facts[0].action)
        assertEquals(InContentTelemetry.IN_CONTENT_SEARCH, facts[0].item)
        assertEquals("google.in-content.sap-follow-on.none", facts[0].value)
    }

    @Test
    fun `GIVEN a Google sap-follow-on from topSite WHEN trackPartnerUrlTypeMetric is called THEN emit an appropriate IN_CONTENT_SEARCH fact`() {
        val url = "https://www.google.com/search?q=aaa&client=firefox-b-m&channel=ts&oq=random"