Move console protection in util.

This will allow testing.
Add util.enableConsoleProtection tests.