Commit Graph

24 Commits

Author SHA1 Message Date
Daniel Martí
46982a1cac rework CancelError into Cancel
That way, cancelling a context while checking the error is much simpler.
The context data already holds onto the cancel func, so this requires no
internal changes.

This renders the Browser.Shutdown API obsolete, even though it doesn't
do exactly the same. If we want Cancel to do a proper shutdown action
before cancelling a browser context and killing the process, we could do
that change within the cancel logic.
2019-04-09 13:06:34 +02:00
Daniel Martí
a29b1ec1d6 deflake TestNavigate
For some reason, this test fails about half the time on Travis, but I
can't get it to fail even after stress-testing hundreds of concurrent
runs.

It might be because Travis is on a much older version of Chrome. We'll
fix that soon, by having chromedp select a specific version of Chrome.

For now, make it more conservative, not assuming that a Location after a
Navigate isn't racy.
2019-04-08 12:38:36 +02:00
Daniel Martí
e482cdfc4d clean up uses of Run in the tests
Many consecutive calls to Run can be collapsed into a single call. While
at it, make the error handling style more consistent. Overall removes 70
lines of repetitive code.
2019-04-01 19:55:40 +01:00
Daniel Martí
0d568ec2a4 change Run to allow many actions
This can simplify some common use cases, like running a few actions
directly, or running no actions at all. It's also an almost entirely
backwards compatible change, as all Run call sites should continue to
compile and work.

Leave Tasks, as it can still be useful for functions to return complex
sequences of actions as a single Action.
2019-04-01 16:59:23 +01:00
Daniel Martí
661ef78880 don't crash when loading pages with iframes
We broke this in the refactor because of a nil pointer dereference, but
we didn't catch that as none of the tests loaded a page with an iframe.
That is, a page with multiple frames.

Add such a test, and fix the bug by creating an almost-empty frame when
we start receiving events about a new frame before it's navigated to.
2019-04-01 12:18:16 +01:00
Daniel Martí
2b925df0fb rewrite TestReload without a sleep 2019-04-01 12:18:16 +01:00
Daniel Martí
f742f327a7 speed up the screenshot tests, and test the images
Using a smaller viewport speeds up both tests, and lets us know what
dimensions to expect in TestCaptureScreenshot.

For TestScreenshot, we can know what dimensions to expect in advance, as
we have the images in testdata.

'go test -run Screenshot' goes from ~0.9s to ~0.5s on my machine.

Finally, don't run ExampleTitle as part of 'go test', as it's slow.
2019-04-01 12:18:16 +01:00
Daniel Martí
da4ac414ed get rid of all sleeps in tests
The navigate sleeps can be replaced by appropriate wait actions.

Some other tests don't need any sleeps at all. This might be because
work is done synchronously now; I haven't been able to get test flakes
after hundreds of test runs with flags like -parallel=32 -count=200.
2019-04-01 12:18:16 +01:00
Daniel Martí
7c1a9fbf3e get rid of all exceptions
We hadn't noticed a few uncaught exceptions being received from the
browser, because the events were ignored. Start printing them via the
error logger.

The ones we were getting were caused by testAllocate running Navigate
actions when the path argument was empty. Navigating to "testdata/"
causes JS exceptions, as it's not a valid page.

Instead, leave the new target pointing at a blank document.
2019-04-01 12:18:16 +01:00
Daniel Martí
92bfcc3c8d collapse a few Navigate actions in the tests 2019-04-01 12:18:16 +01:00
Daniel Martí
3d3bf22ccc start the chromedp v2 refactor
First, we want all of the functionality in a single package; this means
collapsing whatever is useful into the root chromedp package.

The runner package is being replaced by the Allocator interface, with a
default implementation which starts browser processes.

The client package doesn't really have a place in the new design. The
context, allocator, and browser types will handle the connection with
each browser.

Finally, the new API is context-based, hence the addition of context.go.
The tests have been modified to build and run against the new API.
2019-04-01 12:17:28 +01:00
Kenneth Shaw
f683cfc4c1 Minor code cleanup 2018-03-27 04:31:09 +07:00
Kenneth Shaw
b0c2445e67 Splitting repositories 2017-12-28 11:17:14 +07:00
Kenneth Shaw
1e295eddfb Updating to latest protocol.json (clarifying timestamp behavior)
* Disabled AddOnLoadScript/RemoveOnLoadScript
* Updated chromedp-gen fixups for latest timestamp declarations
* Updated to latest protocol.json definitions
2017-07-09 08:40:29 +07:00
Kenneth Shaw
fa3cf26d37 Minor changes to unit tests in attempt to fix issues with travis 2017-06-18 09:32:12 +07:00
Kenneth Shaw
22e287750a Fixing misspelling issues 2017-03-02 09:53:47 +07:00
Randy Cahyana
3a264ed3ff Adding unit test for navigation actions and few minor changes. 2017-02-23 16:39:29 +07:00
Randy Cahyana
a4cd7f9783 Removing external url on navigation and query actions. 2017-02-22 19:55:45 +07:00
Kenneth Shaw
6ce1f2fdfb Reenabling TestStop
- Added contrib/grab-headless_shell.sh to grab latest headless_shell
- Changed travis config to use contrib/grab-headless_shell.sh
- Reenabled TestStop since Page.stopLoading is now available with latest
  available headless_shell
2017-02-22 07:58:30 +07:00
Kenneth Shaw
d15303bae6 Skipping TestStop unit test (Page.stopLoading not available) 2017-02-21 15:06:28 +07:00
Kenneth Shaw
bb2a503425 Standardizing NavigateBack and NavigateForward API 2017-02-21 11:25:36 +07:00
Randy Cahyana
1988de618d Adding unit test for navigation actions. 2017-02-21 09:08:18 +07:00
Kenneth Shaw
dc17e7f8cd Parallelizing unit tests 2017-02-18 13:12:21 +07:00
Randy Cahyana
0db7a9ee72 Increasing unit test coverage on query.go 2017-02-18 10:50:33 +07:00