ServiceWorker: Stabilize wait_for_state() helper

To avoid timeout failure, wait_for_state() should check the condition of the
state of the given worker and the expected state, and reject a promise if
it's never fulfilled.


BUG=n/a
TEST=n/a

Review URL: https://codereview.chromium.org/581043002

git-svn-id: svn://svn.chromium.org/blink/trunk@182220 bbb929c8-8fbe-4397-9dbb-9b2b20218538