Files
HackBrowserData/browser/firefox/extract_download_test.go
T
Roger b3bbc0dadf feat: add CountEntries to skip decryption for list --detail (#562)
* feat: add CountEntries to skip decryption for list --detail (#549)
* test: add CountEntries and countCategory tests at browser level
* fix: address review feedback on CountRows and countLocalStorage
* test: add CountRows unit tests
2026-04-07 22:28:39 +08:00

51 lines
1.3 KiB
Go

package firefox
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func setupMozDownloadDB(t *testing.T) string {
t.Helper()
return createTestDB(t, "places.sqlite", []string{mozPlacesSchema, mozAnnosSchema},
insertMozPlace(1, "https://example.com/old.zip", "Old File", 0, 0),
insertMozPlace(2, "https://example.com/new.pdf", "New File", 0, 0),
insertMozAnno(1, "/tmp/old.zip", 1700000000000000),
insertMozAnno(2, "/tmp/new.pdf", 1710000000000000),
)
}
func TestExtractDownloads(t *testing.T) {
path := setupMozDownloadDB(t)
got, err := extractDownloads(path)
require.NoError(t, err)
require.Len(t, got, 2)
// Verify sort order: StartTime descending
assert.Equal(t, "https://example.com/new.pdf", got[0].URL)
assert.Equal(t, "https://example.com/old.zip", got[1].URL)
// Verify field mapping
assert.Equal(t, "/tmp/new.pdf", got[0].TargetPath)
assert.False(t, got[0].StartTime.IsZero())
}
func TestCountDownloads(t *testing.T) {
path := setupMozDownloadDB(t)
count, err := countDownloads(path)
require.NoError(t, err)
assert.Equal(t, 2, count)
}
func TestCountDownloads_Empty(t *testing.T) {
path := createTestDB(t, "places.sqlite", []string{mozPlacesSchema, mozAnnosSchema})
count, err := countDownloads(path)
require.NoError(t, err)
assert.Equal(t, 0, count)
}