mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
b3bbc0dadf
* 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
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package firefox
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func setupMozHistoryDB(t *testing.T) string {
|
|
t.Helper()
|
|
return createTestDB(t, "places.sqlite", []string{mozPlacesSchema},
|
|
insertMozPlace(1, "https://github.com", "GitHub", 100, 1700000000000000),
|
|
insertMozPlace(2, "https://go.dev", "Go", 50, 1710000000000000),
|
|
insertMozPlace(3, "https://example.com", "Example", 200, 1690000000000000),
|
|
)
|
|
}
|
|
|
|
func TestExtractHistories(t *testing.T) {
|
|
path := setupMozHistoryDB(t)
|
|
|
|
got, err := extractHistories(path)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 3)
|
|
|
|
// Verify sort order: visit count ascending (Firefox convention)
|
|
assert.Equal(t, 50, got[0].VisitCount)
|
|
assert.Equal(t, 100, got[1].VisitCount)
|
|
assert.Equal(t, 200, got[2].VisitCount)
|
|
|
|
// Verify field mapping (first = least visited)
|
|
assert.Equal(t, "https://go.dev", got[0].URL)
|
|
assert.Equal(t, "Go", got[0].Title)
|
|
assert.False(t, got[0].LastVisit.IsZero())
|
|
}
|
|
|
|
func TestCountHistories(t *testing.T) {
|
|
path := setupMozHistoryDB(t)
|
|
|
|
count, err := countHistories(path)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 3, count)
|
|
}
|
|
|
|
func TestCountHistories_Empty(t *testing.T) {
|
|
path := createTestDB(t, "places.sqlite", []string{mozPlacesSchema})
|
|
|
|
count, err := countHistories(path)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 0, count)
|
|
}
|
|
|
|
func TestExtractHistories_NullFields(t *testing.T) {
|
|
path := createTestDB(t, "places.sqlite", []string{mozPlacesSchema},
|
|
// last_visit_date=NULL, title=NULL — COALESCE should handle
|
|
`INSERT INTO moz_places (id, url, visit_count, rev_host, guid, url_hash)
|
|
VALUES (1, 'https://null.test', 1, '', 'g1', 0)`,
|
|
)
|
|
|
|
got, err := extractHistories(path)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 1)
|
|
assert.Equal(t, "https://null.test", got[0].URL)
|
|
assert.Empty(t, got[0].Title)
|
|
}
|