Avoid dead loop when token is string format

The token needs to be a callable object in http.Client, so we assign
a lambda expression to it when it is a string, but current implementation
will cause dead loop since it is x = lambda: x. This patch fixes it
and improves the corresponding test code.

Change-Id: Id41edd705b46196404e5cb3483a290074bde12d0
Closes-Bug: #1301877
Merge "Avoid dead loop when token is string format"