@Test
public void testTrackReferrer() throws Exception {

    DownloadTracker downloadTracker = new DownloadTracker(mTracker);
    downloadTracker.trackNewAppDownload(new TrackMe(), new DownloadTracker.Extra.None());
    verify(mTracker).track(mCaptor.capture());
    checkNewAppDownload(mCaptor.getValue());
    String downloadParams = mCaptor.getValue().get(QueryParams.DOWNLOAD);
    Matcher m = REGEX_DOWNLOADTRACK.matcher(downloadParams);
    assertTrue(downloadParams, m.matches());
    assertEquals(3, m.groupCount());
    assertEquals("package", m.group(1));
    assertEquals(123, Integer.parseInt(m.group(2)));
    assertEquals(null, m.group(3));
    assertEquals("http://installer", mCaptor.getValue().get(QueryParams.REFERRER));
    when(mPackageManager.getInstallerPackageName(anyString())).thenReturn(null);
    downloadTracker.trackNewAppDownload(new TrackMe(), new DownloadTracker.Extra.None());
    verify(mTracker, times(2)).track(mCaptor.capture());
    checkNewAppDownload(mCaptor.getValue());
    m = REGEX_DOWNLOADTRACK.matcher(mCaptor.getValue().get(QueryParams.DOWNLOAD));
    assertTrue(m.matches());
    assertEquals(3, m.groupCount());
    assertEquals("package", m.group(1));
    assertEquals(123, Integer.parseInt(m.group(2)));
    assertEquals(null, m.group(3));
    assertEquals(null, mCaptor.getValue().get(QueryParams.REFERRER));
}