mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-06 05:53:25 +01:00
Comments that restated names or narrated the code are gone, and multi-line ones are cut to a line of why. Only comments change: each edited Go file has the same token stream as before. winapi and abe come later.
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
package chromium
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
)
|
|
|
|
func setupBookmarkJSON(t *testing.T) string {
|
|
t.Helper()
|
|
return createTestJSON(t, "Bookmarks", `{
|
|
"roots": {
|
|
"bookmark_bar": {
|
|
"name": "Bookmarks Bar",
|
|
"type": "folder",
|
|
"children": [
|
|
{"name": "Go", "type": "url", "url": "https://go.dev", "date_added": "13360000000000000"},
|
|
{
|
|
"name": "News",
|
|
"type": "folder",
|
|
"children": [
|
|
{"name": "HN", "type": "url", "url": "https://news.ycombinator.com", "date_added": "13350000000000000"}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
"other": {
|
|
"name": "Other",
|
|
"type": "folder",
|
|
"children": [
|
|
{"name": "GitHub", "type": "url", "url": "https://github.com", "date_added": "13370000000000000"}
|
|
]
|
|
}
|
|
}
|
|
}`)
|
|
}
|
|
|
|
func TestExtractBookmarks(t *testing.T) {
|
|
path := setupBookmarkJSON(t)
|
|
|
|
var out testCollector
|
|
err := extractBookmarks(path, &out)
|
|
got := collected[record.Bookmark](t, &out)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 3)
|
|
|
|
// Bookmarks keep the tree's order; the exporter sorts them.
|
|
assert.Equal(t, "Go", got[0].Name)
|
|
assert.Equal(t, "HN", got[1].Name)
|
|
assert.Equal(t, "GitHub", got[2].Name)
|
|
|
|
assert.Equal(t, "https://github.com", got[2].URL)
|
|
assert.Equal(t, "Other", got[2].Folder)
|
|
|
|
assert.Equal(t, "https://news.ycombinator.com", got[1].URL)
|
|
assert.Equal(t, "News", got[1].Folder)
|
|
}
|
|
|
|
func TestExtractBookmarks_FoldersExcluded(t *testing.T) {
|
|
path := createTestJSON(t, "Bookmarks", `{
|
|
"roots": {
|
|
"bookmark_bar": {
|
|
"name": "Bar",
|
|
"type": "folder",
|
|
"children": [
|
|
{"name": "EmptyFolder", "type": "folder", "children": []},
|
|
{"name": "Link", "type": "url", "url": "https://example.com", "date_added": "0"}
|
|
]
|
|
}
|
|
}
|
|
}`)
|
|
|
|
var out testCollector
|
|
err := extractBookmarks(path, &out)
|
|
got := collected[record.Bookmark](t, &out)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 1) // only URL entries, not folders
|
|
assert.Equal(t, "Link", got[0].Name)
|
|
assert.Equal(t, "Bar", got[0].Folder)
|
|
}
|