func newDefaultTestBrowser() *Browser { bow := &Browser{} bow.SetUserAgent(agent.Create()) bow.SetState(&jar.State{}) bow.SetCookieJar(jar.NewMemoryCookies()) bow.SetBookmarksJar(jar.NewMemoryBookmarks()) bow.SetHistoryJar(jar.NewMemoryHistory()) bow.SetHeadersJar(jar.NewMemoryHeaders()) bow.SetAttributes(AttributeMap{ SendReferer: true, MetaRefreshHandling: true, FollowRedirects: true, }) return bow }
func TestBookmarks(t *testing.T) { ut.Run(t) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, htmlPage1) })) defer ts.Close() bookmarks := jar.NewMemoryBookmarks() bow := NewBrowser() bow.SetBookmarksJar(bookmarks) bookmarks.Save("test1", ts.URL) bow.OpenBookmark("test1") ut.AssertEquals("Surf Page 1", bow.Title()) ut.AssertContains("<p>Hello, Surf!</p>", bow.Body()) err := bow.Bookmark("test2") ut.AssertNil(err) bow.OpenBookmark("test2") ut.AssertEquals("Surf Page 1", bow.Title()) }
func NewBrowser() *Browser { bow := &Browser{} bow.client = &http.Client{ Jar: bow.cookies, CheckRedirect: bow.shouldRedirect, } bow.SetUserAgent(DefaultUserAgent) bow.SetState(&jar.State{}) bow.SetCookieJar(jar.NewMemoryCookies()) bow.SetBookmarksJar(jar.NewMemoryBookmarks()) bow.SetHistoryJar(jar.NewMemoryHistory()) bow.SetHeadersJar(jar.NewMemoryHeaders()) bow.SetAttributes(AttributeMap{ SendReferer: DefaultSendReferer, MetaRefreshHandling: DefaultMetaRefreshHandling, FollowRedirects: DefaultFollowRedirects, }) return bow }