Polymerize Enrollment dialog: propagate authenticator dialog via property

Bug: 811556
Change-Id: I502b94eccfedd5a487fd306c37f5db7af378b70a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1683956
Commit-Queue: Denis Kuznetsov <antrim@chromium.org>
Reviewed-by: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#674485}
diff --git a/chrome/browser/chromeos/login/test/enrollment_ui_mixin.cc b/chrome/browser/chromeos/login/test/enrollment_ui_mixin.cc
index 70cce19..3ea80fd 100644
--- a/chrome/browser/chromeos/login/test/enrollment_ui_mixin.cc
+++ b/chrome/browser/chromeos/login/test/enrollment_ui_mixin.cc
@@ -120,7 +120,7 @@
                                                const std::string& location) {
   OobeJS().TypeIntoPath(asset_id, {kEnrollmentUI, "oauth-enroll-asset-id"});
   OobeJS().TypeIntoPath(location, {kEnrollmentUI, "oauth-enroll-location"});
-  OobeJS().TapOnPath({kEnrollmentUI, "enroll-attributes-submit-button"});
+  OobeJS().TapOnPath({kEnrollmentUI, "attributes-submit"});
 }
 
 void EnrollmentUIMixin::SetExitHandler() {
diff --git a/chrome/browser/resources/chromeos/login/enterprise_enrollment.html b/chrome/browser/resources/chromeos/login/enterprise_enrollment.html
index c03d5bb..e36297e0 100644
--- a/chrome/browser/resources/chromeos/login/enterprise_enrollment.html
+++ b/chrome/browser/resources/chromeos/login/enterprise_enrollment.html
@@ -52,7 +52,9 @@
           </div>
           <div slot="bottom-buttons"
                class="flex layout horizontal center self-start">
-            <oobe-back-button id="oobe-signin-back-button"></oobe-back-button>
+            <oobe-back-button id="oobe-signin-back-button"
+                disabled="[[authenticatorDialogDisplayed_]]"
+                on-click="onBackButtonClicked_"></oobe-back-button>
           </div>
         </oobe-dialog>
       </div>
@@ -118,7 +120,8 @@
                  i18n-values="alt:enrollmentSuccessIllustrationTitle">
           </div>
           <div slot="bottom-buttons" class="layout horizontal end-justified">
-            <oobe-text-button inverse id="enroll-success-done-button"
+            <oobe-text-button inverse id="success-done-button"
+                on-tap="onEnrollmentFinished_"
                 class="focus-on-show">
               <div i18n-content="oauthEnrollDone"></div>
             </oobe-text-button>
@@ -154,12 +157,12 @@
             </gaia-input>
           </div>
           <div slot="bottom-buttons" class="layout horizontal end-justified">
-            <oobe-text-button id="enroll-attributes-skip-button">
+            <oobe-text-button id="attributes-skip" on-tap="skipAttributes_">
               <div i18n-content="oauthEnrollSkip"></div>
             </oobe-text-button>
             <div class="flex"></div>
-            <oobe-next-button
-                id="enroll-attributes-submit-button"></oobe-next-button>
+            <oobe-next-button id="attributes-submit"
+                on-tap="submitAttributes_"></oobe-next-button>
           </div>
         </oobe-dialog>
       </div>
@@ -167,6 +170,8 @@
     <div id="oauth-saml-notice-container">
       <span id="oauth-saml-notice-message"></span>
     </div>
-    <navigation-bar id="oauth-enroll-navigation"></navigation-bar>
+    <navigation-bar id="oauth-enroll-navigation"
+        disabled="[[authenticatorDialogDisplayed_]]"
+        on-close="cancel" on-refresh="cancel"></navigation-bar>
   </template>
 </dom-module>
diff --git a/chrome/browser/resources/chromeos/login/enterprise_enrollment.js b/chrome/browser/resources/chromeos/login/enterprise_enrollment.js
index 7f550abf..477449d 100644
--- a/chrome/browser/resources/chromeos/login/enterprise_enrollment.js
+++ b/chrome/browser/resources/chromeos/login/enterprise_enrollment.js
@@ -60,6 +60,14 @@
     },
 
     /**
+     * Indicates if authenticator have shown internal dialog.
+     */
+    authenticatorDialogDisplayed_: {
+      type: Boolean,
+      value: false,
+    },
+
+    /**
      * Domain the device was enrolled to.
      */
     enrolledDomain_: {
@@ -223,15 +231,13 @@
 
     this.authenticator_.addEventListener(
         'dialogShown', (function(e) {
-                         this.navigation_.disabled = true;
-                         this.$['oobe-signin-back-button'].disabled = true;
+                         this.authenticatorDialogDisplayed_ = true;
                          // TODO(alemate): update the visual style.
                        }).bind(this));
 
     this.authenticator_.addEventListener(
         'dialogHidden', (function(e) {
-                          this.navigation_.disabled = false;
-                          this.$['oobe-signin-back-button'].disabled = false;
+                          this.authenticatorDialogDisplayed_ = false;
                           // TODO(alemate): update the visual style.
                         }).bind(this));
 
@@ -248,21 +254,6 @@
               loadTimeData.getString('fatalEnrollmentError'), false);
         }).bind(this);
 
-    this.$['enroll-success-done-button']
-        .addEventListener('tap', this.onEnrollmentFinished_.bind(this));
-
-    this.$['enroll-attributes-skip-button']
-        .addEventListener('tap', this.onSkipButtonClicked.bind(this));
-    this.$['enroll-attributes-submit-button']
-        .addEventListener('tap', this.onAttributesSubmitted.bind(this));
-
-    this.navigation_.addEventListener('close', this.cancel.bind(this));
-    this.navigation_.addEventListener('refresh', this.cancel.bind(this));
-
-    this.$['oobe-signin-back-button'].addEventListener(
-        'click', this.onBackButtonClicked_.bind(this));
-
-
     this.$['oauth-enroll-learn-more-link']
         .addEventListener('click', function(event) {
           chrome.send('oauthEnrollOnLearnMore');
@@ -317,7 +308,7 @@
           'mode-' + modes[i], data.enrollment_mode == modes[i]);
     }
     this.isManualEnrollment_ = data.enrollment_mode === 'manual';
-    this.navigation_.disabled = false;
+    this.authenticatorDialogDisplayed_ = false;
 
     this.offlineAdUi_.onBeforeShow();
     if (!this.currentStep_) {
@@ -449,6 +440,7 @@
 
   doReload: function() {
     this.lastBackMessageValue_ = false;
+    this.authenticatorDialogDisplayed_ = false;
     this.authenticator_.reload();
     this.updateControlsState();
   },
@@ -493,11 +485,20 @@
    * Skips the device attribute update,
    * shows the successful enrollment step.
    */
-  onSkipButtonClicked: function() {
+  skipAttributes_: function() {
     this.showStep(ENROLLMENT_STEP.SUCCESS);
   },
 
   /**
+   * Uploads the device attributes to server. This goes to C++ side through
+   * |chrome| and launches the device attribute update negotiation.
+   */
+  submitAttributes_: function() {
+    this.screen.onAttributesEntered_(this.$['oauth-enroll-asset-id'].value,
+        this.$['oauth-enroll-location'].value);
+  },
+
+  /**
    * Skips the device attribute update,
    * shows the successful enrollment step.
    */
@@ -512,16 +513,6 @@
     }
   },
 
-
-  /**
-   * Uploads the device attributes to server. This goes to C++ side through
-   * |chrome| and launches the device attribute update negotiation.
-   */
-  onAttributesSubmitted: function() {
-    this.screen.onAttributesEntered_(this.$['oauth-enroll-asset-id'].value,
-        this.$['oauth-enroll-location'].value);
-  },
-
   /**
    * Returns true if we are at the begging of enrollment flow (i.e. the email
    * page).