Fix enrollment screen for attestation-based enrollment.

Remove separate ABE success screen.
Replace success text with dedicated polymer element.

TBR: alemate@chromium.org
Bug: 811556
Change-Id: Id26aae8ec6276d57148cbb2a101094f93d28e11c
Reviewed-on: https://chromium-review.googlesource.com/c/1329630
Commit-Queue: Denis Kuznetsov <antrim@chromium.org>
Reviewed-by: Alexander Hendrich <hendrich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610496}
diff --git a/chrome/app/chromeos_strings.grdp b/chrome/app/chromeos_strings.grdp
index b2eeb83..52957246 100644
--- a/chrome/app/chromeos_strings.grdp
+++ b/chrome/app/chromeos_strings.grdp
@@ -2611,9 +2611,10 @@
   <message name="IDS_ENTERPRISE_ENROLLMENT_SUCCESS_ILLUSTRATION_TITLE" desc="Accessible title of the enterprise enrollment screen illustration depicting successful enrollment.">
     Successful enrollment illustration
   </message>
-  <message name="IDS_ENTERPRISE_ENROLLMENT_ABE_SUCCESS" desc="Success message to be shown once attestation-based enterprise enrollment completes.">
+  <message name="IDS_ENTERPRISE_ENROLLMENT_SUCCESS_ABE_DOMAIN" desc="Success message to be shown once attestation-based enterprise enrollment completes.">
     Your <ph name="DEVICE_TYPE">$1<ex>Chromebook</ex></ph> has successfully been enrolled for enterprise management by <ph name="BEGIN_BOLD">&lt;strong&gt;</ph><ph name="DOMAIN">$2<ex>acmecorp.com</ex></ph><ph name="END_BOLD">&lt;/strong&gt;</ph>.
-    <ph name="LINE_BREAK_AND_EMPTY_LINE">&lt;br&gt;&lt;br&gt;</ph>
+  </message>
+  <message name="IDS_ENTERPRISE_ENROLLMENT_SUCCESS_ABE_SUPPORT" desc="Recommendation to contact support. Shown once attestation-based enterprise enrollment completes.">
     If this is unexpected, please contact support.
   </message>
   <message name="IDS_ENTERPRISE_ENROLLMENT_ASSET_ID_LABEL" desc="Label for asset id text box on the device naming screen in the enterprise enrollment dialog.">
diff --git a/chrome/browser/chromeos/login/enrollment/enrollment_screen_browsertest.cc b/chrome/browser/chromeos/login/enrollment/enrollment_screen_browsertest.cc
index 8591261c8..ceb6381 100644
--- a/chrome/browser/chromeos/login/enrollment/enrollment_screen_browsertest.cc
+++ b/chrome/browser/chromeos/login/enrollment/enrollment_screen_browsertest.cc
@@ -158,7 +158,7 @@
 
   view->ShowAttestationBasedEnrollmentSuccessScreen("fake domain");
   checker.ExpectTrue(
-      "window.getComputedStyle(document.getElementById('oauth-enroll-step-abe-"
+      "window.getComputedStyle(document.getElementById('oauth-enroll-step-"
       "success')).display !== 'none'");
 }
 
diff --git a/chrome/browser/resources/chromeos/login/custom_elements_login.js b/chrome/browser/resources/chromeos/login/custom_elements_login.js
index cd6bba4..b008807 100644
--- a/chrome/browser/resources/chromeos/login/custom_elements_login.js
+++ b/chrome/browser/resources/chromeos/login/custom_elements_login.js
@@ -25,6 +25,7 @@
 // <include src="oobe_buttons.js">
 // <include src="oobe_change_picture.js">
 // <include src="oobe_dialog.js">
+// <include src="oobe_enrollment.js">
 // <include src="arc_terms_of_service.js">
 // <include src="oobe_reset.js">
 // <include src="oobe_reset_confirmation_overlay.js">
diff --git a/chrome/browser/resources/chromeos/login/custom_elements_oobe.js b/chrome/browser/resources/chromeos/login/custom_elements_oobe.js
index fffa637..bf47099e 100644
--- a/chrome/browser/resources/chromeos/login/custom_elements_oobe.js
+++ b/chrome/browser/resources/chromeos/login/custom_elements_oobe.js
@@ -31,6 +31,7 @@
 // <include src="oobe_buttons.js">
 // <include src="oobe_change_picture.js">
 // <include src="oobe_dialog.js">
+// <include src="oobe_enrollment.js">
 // <include src="oobe_eula.js">
 // <include src="oobe_hid_detection.js">
 // <include src="oobe_reset.js">
diff --git a/chrome/browser/resources/chromeos/login/oobe_enrollment.html b/chrome/browser/resources/chromeos/login/oobe_enrollment.html
index c227586..7d8ddbe 100644
--- a/chrome/browser/resources/chromeos/login/oobe_enrollment.html
+++ b/chrome/browser/resources/chromeos/login/oobe_enrollment.html
@@ -2,6 +2,7 @@
      Use of this source code is governed by a BSD-style license that can be
      found in the LICENSE file. -->
 
+<link rel="import" href="chrome://resources/html/i18n_behavior.html">
 <link rel="import" href="chrome://resources/html/polymer.html">
 <link rel="import" href="chrome://resources/polymer/v1_0/iron-iconset-svg/iron-iconset-svg.html">
 
@@ -32,3 +33,17 @@
     </defs>
   </svg>
 </iron-iconset-svg>
+
+<dom-module id="oobe-enrollment-success-with-domain">
+  <template>
+    <div hidden="[[enrollmentDomain]]">
+      [[i18nDynamic(locale,'oauthEnrollSuccessTitle')]]
+    </div>
+    <div hidden="[[!enrollmentDomain]]">
+      <div inner-h-t-m-l="[[localizedText_(locale, deviceName,
+          enrollmentDomain)]]">
+      </div>
+      <div>[[i18nDynamic(locale, 'oauthEnrollAbeSuccessSupport')]]</div>
+    </div>
+  </template>
+</dom-module>
diff --git a/chrome/browser/resources/chromeos/login/oobe_enrollment.js b/chrome/browser/resources/chromeos/login/oobe_enrollment.js
new file mode 100644
index 0000000..409013f
--- /dev/null
+++ b/chrome/browser/resources/chromeos/login/oobe_enrollment.js
@@ -0,0 +1,31 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+Polymer({
+  is: 'oobe-enrollment-success-with-domain',
+  behaviors: [I18nBehavior],
+  properties: {
+    /**
+     * Domain the device was enrolled to.
+     */
+    enrollmentDomain: {
+      type: String,
+      value: '',
+      reflectToAttribute: true,
+    },
+
+    /**
+     * Name of the device that was enrolled.
+     */
+    deviceName: {
+      type: String,
+      value: 'Chromebook',
+    },
+  },
+
+  localizedText_: function(locale, device, domain) {
+    return this.i18nAdvanced(
+        'oauthEnrollAbeSuccessDomain', {substitutions: [device, domain]});
+  }
+});
diff --git a/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.css b/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.css
index 9e052cd..8e2790a 100644
--- a/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.css
+++ b/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.css
@@ -37,7 +37,6 @@
 .oauth-enroll-state-ad-join #oauth-enroll-step-ad-join,
 .oauth-enroll-state-license #oauth-enroll-step-license,
 .oauth-enroll-state-success #oauth-enroll-step-success,
-.oauth-enroll-state-abe-success #oauth-enroll-step-abe-success,
 .oauth-enroll-state-working #oauth-enroll-step-working,
 .oauth-enroll-state-attribute-prompt
     #oauth-enroll-step-attribute-prompt {
diff --git a/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.html b/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.html
index 1079636..9763efb 100644
--- a/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.html
+++ b/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.html
@@ -60,7 +60,9 @@
                       icon1x="oobe-enrollment-32:briefcase"
                       icon2x="oobe-enrollment-64:briefcase"></hd-iron-icon>
         <h1 slot="title" i18n-content="oauthEnrollSuccessTitle"></h1>
-        <div slot="subtitle" i18n-content="oauthEnrollSuccess"></div>
+        <oobe-enrollment-success-with-domain id="oauth-enroll-success-subtitle"
+                                             slot="subtitle">
+        </oobe-enrollment-success-with-domain>
         <div slot="footer" class="flex layout vertical center end-justified">
           <img srcset="images/enrollment_success_illustration_1x.png 1x,
                   images/enrollment_success_illustration_2x.png 2x"
@@ -74,29 +76,6 @@
         </div>
       </oobe-dialog>
     </div>
-      <div id="oauth-enroll-step-abe-success" role="alert">
-        <oobe-dialog id="oauth-enroll-abe-success-card" has-buttons>
-          <hd-iron-icon slot="oobe-icon"
-                        icon1x="oobe-enrollment-32:briefcase"
-                        icon2x="oobe-enrollment-64:briefcase"></hd-iron-icon>
-          <h1 slot="title" i18n-content="oauthEnrollSuccessTitle"></h1>
-          <div slot="subtitle" id="oauth-enroll-abe-success-comment-no-domain"
-               i18n-content="oauthEnrollSuccess"></div>
-          <div slot="subtitle" id="oauth-enroll-abe-success-comment-domain"
-               hidden></div>
-          <div slot="footer" class="flex layout vertical center end-justified">
-            <img srcset="images/enrollment_success_illustration_1x.png 1x,
-                  images/enrollment_success_illustration_2x.png 2x"
-                 i18n-values="alt:enrollmentSuccessIllustrationTitle">
-          </div>
-          <div slot="bottom-buttons" class="layout horizontal end-justified">
-            <oobe-text-button inverse id="enroll-success-abe-done-button"
-                class="focus-on-show">
-              <div i18n-content="oauthEnrollDone"></div>
-            </oobe-text-button>
-          </div>
-        </oobe-dialog>
-    </div>
     <div id="oauth-enroll-step-attribute-prompt">
       <oobe-dialog id="oauth-enroll-attribute-prompt-card" has-buttons>
         <hd-iron-icon slot="oobe-icon"
diff --git a/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.js b/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.js
index aa00b5a..3017995f 100644
--- a/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.js
+++ b/chrome/browser/resources/chromeos/login/oobe_screen_oauth_enrollment.js
@@ -17,7 +17,6 @@
   /** @const */ var STEP_ATTRIBUTE_PROMPT = 'attribute-prompt';
   /** @const */ var STEP_ERROR = 'error';
   /** @const */ var STEP_SUCCESS = 'success';
-  /** @const */ var STEP_ABE_SUCCESS = 'abe-success';
 
   /* TODO(dzhioev): define this step on C++ side.
   /** @const */ var STEP_ATTRIBUTE_PROMPT_ERROR = 'attribute-prompt-error';
@@ -206,8 +205,6 @@
 
       $('enroll-success-done-button')
           .addEventListener('tap', this.onEnrollmentFinished_.bind(this));
-      $('enroll-success-abe-done-button')
-          .addEventListener('tap', this.onEnrollmentFinished_.bind(this));
 
       $('enroll-attributes-skip-button')
           .addEventListener('tap', this.onSkipButtonClicked.bind(this));
@@ -239,7 +236,6 @@
       this.licenseUi_.addEventListener('buttonclick', function() {
         chrome.send('onLicenseTypeSelected', [this.licenseUi_.selected]);
       }.bind(this));
-
     },
 
     /**
@@ -321,12 +317,10 @@
      */
     showAttestationBasedEnrollmentSuccess: function(
         device, enterpriseEnrollmentDomain) {
-      $('oauth-enroll-abe-success-comment-no-domain').hidden = true;
-      $('oauth-enroll-abe-success-comment-domain').hidden = false;
-      $('oauth-enroll-abe-success-comment-domain').innerHTML =
-          loadTimeData.getStringF(
-              'oauthEnrollAbeSuccess', device, enterpriseEnrollmentDomain);
-      this.showStep(STEP_ABE_SUCCESS);
+      $('oauth-enroll-success-subtitle').deviceName = device;
+      $('oauth-enroll-success-subtitle').enrollmentDomain =
+          enterpriseEnrollmentDomain;
+      this.showStep(STEP_SUCCESS);
     },
 
     /**
@@ -393,8 +387,6 @@
         $('oauth-enroll-error-card').submitButton.focus();
       } else if (step == STEP_SUCCESS) {
         $('oauth-enroll-success-card').show();
-      } else if (step == STEP_ABE_SUCCESS) {
-        $('oauth-enroll-abe-success-card').show();
       } else if (step == STEP_ATTRIBUTE_PROMPT) {
         $('oauth-enroll-attribute-prompt-card').show();
       } else if (step == STEP_ATTRIBUTE_PROMPT_ERROR) {
diff --git a/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc
index cec33f5..ed7bcb9 100644
--- a/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.cc
@@ -567,7 +567,10 @@
                IDS_ENTERPRISE_ENROLLMENT_LOCATION_LABEL);
   builder->Add("oauthEnrollWorking", IDS_ENTERPRISE_ENROLLMENT_WORKING_MESSAGE);
   // Do not use AddF for this string as it will be rendered by the JS code.
-  builder->Add("oauthEnrollAbeSuccess", IDS_ENTERPRISE_ENROLLMENT_ABE_SUCCESS);
+  builder->Add("oauthEnrollAbeSuccessDomain",
+               IDS_ENTERPRISE_ENROLLMENT_SUCCESS_ABE_DOMAIN);
+  builder->Add("oauthEnrollAbeSuccessSupport",
+               IDS_ENTERPRISE_ENROLLMENT_SUCCESS_ABE_SUPPORT);
 
   /* Active Directory strings */
   builder->Add("oauthEnrollAdMachineNameInput", IDS_AD_DEVICE_NAME_INPUT_LABEL);