<commit_before>/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @fileoverview Test for password sign-up handler.
 */

goog.provide('firebaseui.auth.widget.handler.PasswordSignUpTest');
goog.setTestOnly('firebaseui.auth.widget.handler.PasswordSignUpTest');

goog.require('firebaseui.auth.soy2.strings');
goog.require('firebaseui.auth.widget.handler.handlePasswordSignUp');
goog.require('firebaseui.auth.widget.handler.handleProviderSignIn');
goog.require('firebaseui.auth.widget.handler.handleSignIn');
goog.require('firebaseui.auth.widget.handler.testHelper');
goog.require('goog.Promise');
goog.require('goog.dom');
goog.require('goog.dom.forms');
goog.require('goog.testing.events');


/**
 * Asserts all the required requests for a successful sign-up.
 */
function assertSuccessfulSignUp() {
  testAuth.assertCreateUserWithEmailAndPassword(
      [passwordAccount.getEmail(), '123123'], function() {
        testAuth.setUser({
          'email': passwordAccount.getEmail(),
          'displayName': passwordAccount.getDisplayName()
        });
        testAuth.currentUser.assertUpdateProfile([{
          'displayName': 'Password User'
        }]);
        return testAuth.currentUser;
      });
}


function testHandlePasswordSignUp() {
  firebaseui.auth.widget.handler.handlePasswordSignUp(
      app, container, passwordAccount.getEmail());
  assertPasswordSignUpPage();
  goog.dom.forms.setValue(getNameElement(), 'Password User');
  goog.dom.forms.setValue(getNewPasswordElement(), '123123');
  submitForm();
  assertSuccessfulSignUp();
  // Sign out from internal instance and then sign in with passed credential to
  // external instance.
  return testAuth.process().then(function() {
    testAuth.setUser({
      'uid': '12345678'
    });
    testAuth.assertSignOut([]);
    return testAuth.process();
  }).then(function() {
    externalAuth.setUser(testAuth.currentUser);
    // Confirm password credential passed and signed in with.
    var cred = new firebase.auth.EmailAuthProvider.credential(
        passwordAccount.getEmail(), '<PASSWORD>');
    externalAuth.assertSignInWithCredential([cred], externalAuth.currentUser);
    return externalAuth.process();
  }).then(function() {
    testUtil.assertGoTo('http://localhost/home');
  });
}


function testHandlePasswordSignUp_reset() {
  // Test reset after password sign-up handler called.
  firebaseui.auth.widget.handler.handlePasswordSignUp(
      app, container, passwordAccount.getEmail());
  assertPasswordSignUpPage();
  // Reset current rendered widget page.
  app.reset();
  // Container should be cleared.
  assertComponentDisposed();
}

function testHandlePasswordSignUp_withoutDisplayName() {
  app.setConfig({
    'signInOptions': [
      {
        provider: 'password',<commit_msg>added extra line feed<commit_after>/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @fileoverview Test for password sign-up handler.
 */

goog.provide('firebaseui.auth.widget.handler.PasswordSignUpTest');
goog.setTestOnly('firebaseui.auth.widget.handler.PasswordSignUpTest');

goog.require('firebaseui.auth.soy2.strings');
goog.require('firebaseui.auth.widget.handler.handlePasswordSignUp');
goog.require('firebaseui.auth.widget.handler.handleProviderSignIn');
goog.require('firebaseui.auth.widget.handler.handleSignIn');
goog.require('firebaseui.auth.widget.handler.testHelper');
goog.require('goog.Promise');
goog.require('goog.dom');
goog.require('goog.dom.forms');
goog.require('goog.testing.events');


/**
 * Asserts all the required requests for a successful sign-up.
 */
function assertSuccessfulSignUp() {
  testAuth.assertCreateUserWithEmailAndPassword(
      [passwordAccount.getEmail(), '<PASSWORD>'], function() {
        testAuth.setUser({
          'email': passwordAccount.getEmail(),
          'displayName': passwordAccount.getDisplayName()
        });
        testAuth.currentUser.assertUpdateProfile([{
          'displayName': 'Password User'
        }]);
        return testAuth.currentUser;
      });
}


function testHandlePasswordSignUp() {
  firebaseui.auth.widget.handler.handlePasswordSignUp(
      app, container, passwordAccount.getEmail());
  assertPasswordSignUpPage();
  goog.dom.forms.setValue(getNameElement(), 'Password User');
  goog.dom.forms.setValue(getNewPasswordElement(), '<PASSWORD>');
  submitForm();
  assertSuccessfulSignUp();
  // Sign out from internal instance and then sign in with passed credential to
  // external instance.
  return testAuth.process().then(function() {
    testAuth.setUser({
      'uid': '12345678'
    });
    testAuth.assertSignOut([]);
    return testAuth.process();
  }).then(function() {
    externalAuth.setUser(testAuth.currentUser);
    // Confirm password credential passed and signed in with.
    var cred = new firebase.auth.EmailAuthProvider.credential(
        passwordAccount.getEmail(), '<PASSWORD>');
    externalAuth.assertSignInWithCredential([cred], externalAuth.currentUser);
    return externalAuth.process();
  }).then(function() {
    testUtil.assertGoTo('http://localhost/home');
  });
}


function testHandlePasswordSignUp_reset() {
  // Test reset after password sign-up handler called.
  firebaseui.auth.widget.handler.handlePasswordSignUp(
      app, container, passwordAccount.getEmail());
  assertPasswordSignUpPage();
  // Reset current rendered widget page.
  app.reset();
  // Container should be cleared.
  assertComponentDisposed();
}


function testHandlePasswordSignUp_withoutDisplayName() {
  app.setConfig({
    'signInOptions': [
      {
        provider: 'password',
{'fraction_non_alphanumeric': 0.1235197121870784, 'fraction_numerical': 0.006895517913356318, 'mean_word_length': 4.299444003177125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3948171', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1821, 'n_words': 440}