I'm afraid the `testContentScriptWhen` utility function makes the tests too "magical": reading the tests is not clear what we're going to test and why. It took me a bit to understand, and I had to read all the utility function.

My personal suggestion is avoid such magical utilities when is possible, at least create utility that doesn't encapsulate the logic of the test: in those tests the assertion about what we're going to tests are in the utility itself, not in the tests.
If you put any assertion in the utility function, and none in the tests, is likely that you're put the test logic in the wrong place.

Write an utility function if you think it will help, but be sure the logic of the test, the test's assertion are in the test itself.