function waitForTestWindow(win) {
  return new GoogPromise((resolve, reject) => {
    if (!win) {
      fail('Could not open new window. Check if popup blocker is enabled.');
    }

    let attemptCount = 0;
    const intervalToken =
        window
            .setInterval(/**
                            @suppress {strictMissingProperties} suppression
                            added to enable type checking
                          */
                         () => {
                           if (++attemptCount > MAX_WIN_LOAD_TRIES) {
                             try {
                               fail(
                                   'Window did not load after maximum number of checks.');
                             } catch (e) {
                               window.clearInterval(intervalToken);
                               reject(e);
                             }
                           } else if (win.newWinLoaded) {
                             window.clearInterval(intervalToken);
                             resolve(win);
                           }
                         },
                         WIN_LOAD_TRY_TIMEOUT);
  });
}
Returns a promise for `win` once JS has been evaluated in it.
@param {Window} win
@return {!GoogPromise<!Window>} Promise for a window that resolves once the
    window has loaded.