-
-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
344 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
go test test/browsh_test.go | ||
go test test/*.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,76 @@ | ||
package main | ||
package test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
"strconv" | ||
"fmt" | ||
|
||
"github.com/gdamore/tcell" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"browsh" | ||
) | ||
|
||
var simScreen tcell.SimulationScreen | ||
var startupWait = 10 | ||
var browserFingerprint = " ← | x | " | ||
var rootDir = browsh.Shell("git rev-parse --show-toplevel") | ||
|
||
func TestIntegration(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Integration tests") | ||
} | ||
|
||
func GetFrameText() string { | ||
var text string | ||
cells, _, _ := simScreen.GetContents() | ||
for _, element := range cells { | ||
text += string(element.Runes) | ||
} | ||
fmt.Println(text) | ||
return text | ||
} | ||
|
||
var _ = Describe("Integration", func() { | ||
var _ = Describe("Showing a basic webpage", func() { | ||
BeforeEach(func() { | ||
var count = 0 | ||
simScreen = tcell.NewSimulationScreen("UTF-8") | ||
go browsh.Start(simScreen) | ||
for { | ||
if count > startupWait { | ||
var message = "Couldn't find browsh " + | ||
"startup signature within " + | ||
strconv.Itoa(startupWait) + | ||
" seconds" | ||
panic(message) | ||
} | ||
time.Sleep(time.Second) | ||
if (strings.Contains(GetFrameText(), browserFingerprint)) { | ||
break | ||
} | ||
count++ | ||
} | ||
}) | ||
GotoURL(testSiteURL + "/smorgasbord/") | ||
}) | ||
|
||
Describe("Browser UI", func() { | ||
It("should have the page title, buttons and the current URL", func() { | ||
Expect("Smörgåsbord").To(BeInFrameAt(0, 0)) | ||
Expect(" ← |").To(BeInFrameAt(0, 1)) | ||
Expect(" x |").To(BeInFrameAt(4, 1)) | ||
URL := testSiteURL + "/smorgasbord/" | ||
Expect(URL).To(BeInFrameAt(9, 1)) | ||
}) | ||
|
||
Describe("Interaction", func() { | ||
It("should navigate to a new page by using the URL bar", func() { | ||
SpecialKey(tcell.KeyCtrlL) | ||
Keyboard(testSiteURL + "/smorgasbord/another.html") | ||
SpecialKey(tcell.KeyEnter) | ||
Expect("Another").To(BeInFrameAt(0, 0)) | ||
}) | ||
|
||
AfterEach(func() { | ||
browsh.Shell(rootDir + "/webext/contrib/firefoxheadless.sh kill") | ||
It("should navigate to a new page by clicking a link", func() { | ||
simScreen.InjectMouse(12, 21, tcell.Button1, tcell.ModNone) | ||
Expect("Another").To(BeInFrameAt(0, 0)) | ||
}) | ||
|
||
It("should scroll the page by one line", func() { | ||
SpecialKey(tcell.KeyDown) | ||
Expect("meal,▄originating▄in▄").To(BeInFrameAt(12, 12)) | ||
}) | ||
|
||
It("should scroll the page by one page", func() { | ||
SpecialKey(tcell.KeyPgDn) | ||
Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 10)) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("Showing a basic webpage", func() { | ||
It("have the right text", func() { | ||
Expect(GetFrameText()).To(ContainSubstring("Something")) | ||
Describe("Rendering", func() { | ||
It("should render dynamic content", func() { | ||
Expect([3]int32{0, 255, 255}).To(Equal(GetFgColour(39, 3))) | ||
waitForNextFrame() | ||
Expect([3]int32{255, 0, 255}).To(Equal(GetFgColour(39, 3))) | ||
}) | ||
|
||
It("should switch to monochrome mode", func() { | ||
simScreen.InjectKey(tcell.KeyRune, 'M', tcell.ModAlt) | ||
waitForNextFrame() | ||
Expect([3]int32{0, 0, 0}).To(Equal(GetBgColour(0, 2))) | ||
Expect([3]int32{255, 255, 255}).To(Equal(GetFgColour(12, 11))) | ||
}) | ||
|
||
Describe("Text positioning", func() { | ||
It("should position the left/right-aligned coloumns", func() { | ||
Expect("Smörgåsbord▄(Swedish:").To(BeInFrameAt(12, 11)) | ||
Expect("The▄Swedish▄word").To(BeInFrameAt(42, 11)) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
gomegaTypes "github.com/onsi/gomega/types" | ||
) | ||
|
||
// BeInFrameAt is a custom matcher that looks for the expected text at the given | ||
// coordinates. | ||
func BeInFrameAt(x, y int) gomegaTypes.GomegaMatcher { | ||
return &textInFrameMatcher{ | ||
x: x, | ||
y: y, | ||
found: "", | ||
} | ||
} | ||
|
||
type textInFrameMatcher struct { | ||
x int | ||
y int | ||
found string | ||
} | ||
|
||
func (matcher *textInFrameMatcher) Match(actual interface{}) (success bool, err error) { | ||
text, _ := actual.(string) | ||
start := time.Now() | ||
for time.Since(start) < perTestTimeout { | ||
matcher.found = GetText(matcher.x, matcher.y, runeCount(text)) | ||
if matcher.found == text { return true, nil } | ||
time.Sleep(100 * time.Millisecond) | ||
} | ||
return false, fmt.Errorf("Timeout. Expected\n\t%#v\nto be in the Browsh frame, but found\n\t%#v", text, matcher.found) | ||
} | ||
|
||
func (matcher *textInFrameMatcher) FailureMessage(text interface{}) (message string) { | ||
return fmt.Sprintf("Expected\n\t%#v\nto equal\n\t%#v", text, matcher.found) | ||
} | ||
|
||
func (matcher *textInFrameMatcher) NegatedFailureMessage(text interface{}) (message string) { | ||
return fmt.Sprintf("Expected\n\t%#v\nnot to equal of\n\t%#v", text, matcher.found) | ||
} | ||
|
Oops, something went wrong.