github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/igm/sockjs-go.v2/sockjs/iframe_test.go (about) 1 package sockjs 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "testing" 7 ) 8 9 func TestHandler_iframe(t *testing.T) { 10 h := newTestHandler() 11 h.options.SockJSURL = "http://sockjs.com/sockjs.js" 12 rw := httptest.NewRecorder() 13 req, _ := http.NewRequest("GET", "/server/sess/iframe", nil) 14 h.iframe(rw, req) 15 if rw.Body.String() != expected { 16 t.Errorf("Unexpected html content,\ngot:\n'%s'\n\nexpected\n'%s'", rw.Body, expected) 17 } 18 eTag := rw.Header().Get("etag") 19 req.Header.Set("if-none-match", eTag) 20 rw = httptest.NewRecorder() 21 h.iframe(rw, req) 22 if rw.Code != http.StatusNotModified { 23 t.Errorf("Unexpected response, got '%d', expected '%d'", rw.Code, http.StatusNotModified) 24 } 25 } 26 27 var expected = `<!DOCTYPE html> 28 <html> 29 <head> 30 <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 31 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 32 <script> 33 document.domain = document.domain; 34 _sockjs_onload = function(){SockJS.bootstrap_iframe();}; 35 </script> 36 <script src="http://sockjs.com/sockjs.js"></script> 37 </head> 38 <body> 39 <h2>Don't panic!</h2> 40 <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p> 41 </body> 42 </html>`