Viewport tests

I'm at another good stopping point for these, so here's another pull request. I'm trying to not put them all in one enormous code review, just for sanity's sake.
I know the code base is inconsistent, but the style we're moving towards is: 

```
if (...) {
} else {
}
```