|
1 | 1 | package html_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "net/http"
|
5 | 6 | "net/url"
|
6 | 7 | "reflect"
|
@@ -52,20 +53,25 @@ type WindowFixture struct {
|
52 | 53 | form html.HTMLFormElement
|
53 | 54 | actualRequest *http.Request
|
54 | 55 | submittedForm url.Values
|
| 56 | + handler http.Handler |
55 | 57 | }
|
56 | 58 |
|
57 | 59 | func (f *WindowFixture) Setup() {
|
58 |
| - win := html.NewWindow(html.WindowOptions{ |
59 |
| - HttpClient: gosthttp.NewHttpClientFromHandler( |
| 60 | + handler := f.handler |
| 61 | + if handler == nil { |
| 62 | + fmt.Println("Overwrite handler") |
| 63 | + handler = |
60 | 64 | http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
61 | 65 | if req.ParseForm() != nil {
|
62 | 66 | panic("Error parsing form")
|
63 | 67 | }
|
64 | 68 | f.actualRequest = req
|
65 | 69 | f.submittedForm = req.Form
|
66 | 70 | f.requests = append(f.requests, req)
|
67 |
| - }), |
68 |
| - ), |
| 71 | + }) |
| 72 | + } |
| 73 | + win := html.NewWindow(html.WindowOptions{ |
| 74 | + HttpClient: gosthttp.NewHttpClientFromHandler(handler), |
69 | 75 | BaseLocation: string(f.BaseLocationFixture),
|
70 | 76 | })
|
71 | 77 | f.Window = htmltest.NewWindowHelper(f.TB, win)
|
@@ -298,3 +304,33 @@ func TestHTMLFormElementSubmitInputWithClickResetButton(t *testing.T) {
|
298 | 304 | w.Submitter.Click()
|
299 | 305 | w.Assert().Nil(w.submittedForm, "A form was submitted")
|
300 | 306 | }
|
| 307 | + |
| 308 | +func TestResubmitFormOn307Redirects(t *testing.T) { |
| 309 | + var ( |
| 310 | + actualRequest *http.Request |
| 311 | + submittedForm url.Values |
| 312 | + ) |
| 313 | + |
| 314 | + mux := http.NewServeMux() |
| 315 | + mux.Handle("POST /form-destination", http.RedirectHandler("/form-redirected", 307)) |
| 316 | + mux.HandleFunc("POST /form-redirected", func(w http.ResponseWriter, r *http.Request) { |
| 317 | + r.ParseForm() |
| 318 | + actualRequest = r |
| 319 | + submittedForm = r.Form |
| 320 | + }) |
| 321 | + |
| 322 | + w, setup := InitFixture( |
| 323 | + t, |
| 324 | + &HTMLFormSubmitInputFixture{}, |
| 325 | + BaseLocationFixture("http://example.com/forms"), |
| 326 | + ) |
| 327 | + |
| 328 | + w.HTMLFormFixture.handler = mux |
| 329 | + setup.Setup() |
| 330 | + form := w.Form() |
| 331 | + form.SetMethod("post") |
| 332 | + form.SetAction("/form-destination") |
| 333 | + form.Submit() |
| 334 | + w.Assert().NotNil(actualRequest, "Request sent to the redirected location") |
| 335 | + w.Assert().Equal([]string{"bar"}, submittedForm["foo"], "Form on second request") |
| 336 | +} |
0 commit comments