Skip to content

Commit

Permalink
Add a test to lock in behaviour for nav to iframe
Browse files Browse the repository at this point in the history
This test actually tests that we can navigate to a page with iframes,
click on a link, which navigates to another page with iframes. Once
at the second page it will end the test and we can assert. Without the
fix in the prior commit, this would panic on a deadlock.

NOTE: This only works when we have headless mode on.
  • Loading branch information
ankur22 committed Jun 26, 2023
1 parent 940d764 commit c120d9e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/frame_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"net/http"
"strconv"
"testing"

Expand Down Expand Up @@ -102,6 +103,42 @@ func TestFrameNoPanicWithEmbeddedIFrame(t *testing.T) {
assert.EqualValues(t, "Done!", result)
}

// Without the fix in https://github.com/grafana/xk6-browser/pull/942
// this test would hang on the "sign in" link click.
func TestFrameNoPanicNavigateAndClickOnPageWithIFrames(t *testing.T) {
t.Parallel()

if s, ok := env.Lookup(env.BrowserHeadless); ok {
if v, err := strconv.ParseBool(s); err == nil && v {
// We're skipping this when running in headless
// environments since the bug that the test fixes
// only surfaces when in headfull mode.
// Remove this skip once we have headfull mode in
// CI: https://github.com/grafana/xk6-browser/issues/678
t.Skip("skipped when in headless mode")
}
}

tb := newTestBrowser(
t,
withFileServer(),
withEnvLookup(env.ConstLookup(env.BrowserHeadless, "0")),
)
p := tb.NewPage(nil)
tb.withHandler("/iframeSignIn", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, tb.staticURL("iframe_signin.html"), http.StatusMovedPermanently)
})

_, err := p.Goto(tb.staticURL("iframe_home.html"), nil)
require.NoError(t, err)

err = p.Click(`a[href="/iframeSignIn"]`, nil)
require.NoError(t, err)

result := p.TextContent("#doneDiv", nil)
assert.EqualValues(t, "Sign In Page", result)
}

func TestFrameTitle(t *testing.T) {
p := newTestBrowser(t).NewPage(nil)
p.SetContent(`<html><head><title>Some title</title></head></html>`, nil)
Expand Down
8 changes: 8 additions & 0 deletions tests/static/iframe_home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<a href="/iframeSignIn">Sign In</a>
<iframe src="about:blank"></iframe>
</body>
</html>
8 changes: 8 additions & 0 deletions tests/static/iframe_signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<div id="doneDiv">Sign In Page</div>
<iframe src="about:blank"></iframe>
</body>
</html>

0 comments on commit c120d9e

Please sign in to comment.