@@ -13,6 +13,8 @@ import {chunkInstanceForTesting} from '../../src/chunk';
1313import {
1414 createAmpElementForTesting ,
1515 getImplSyncForTesting ,
16+ markUnresolvedElements ,
17+ resetUnresolvedElementsForTesting ,
1618} from '../../src/custom-element' ;
1719import { ElementStub } from '../../src/element-stub' ;
1820
@@ -153,6 +155,7 @@ describes.realWin('CustomElement', {amp: true}, (env) => {
153155 afterEach ( ( ) => {
154156 clock . uninstall ( ) ;
155157 resourcesMock . verify ( ) ;
158+ resetUnresolvedElementsForTesting ( ) ;
156159 } ) ;
157160
158161 function skipMicroTask ( ) {
@@ -948,9 +951,9 @@ describes.realWin('CustomElement', {amp: true}, (env) => {
948951
949952 expect ( element . everAttached ) . to . equal ( true ) ;
950953 expect ( element . getLayout ( ) ) . to . equal ( Layout . FILL ) ;
951- // Not upgraded yet!
952- expect ( element ) . to . have . class ( 'amp-unresolved' ) ;
953- expect ( element ) . to . have . class ( 'i-amphtml-unresolved' ) ;
954+ // Not upgraded yet, but extension hasn't failed.
955+ expect ( element ) . not . to . have . class ( 'amp-unresolved' ) ;
956+ expect ( element ) . not . to . have . class ( 'i-amphtml-unresolved' ) ;
954957
955958 // Upgrade
956959 resourcesMock . expects ( 'upgraded' ) . withExactArgs ( element ) . once ( ) ;
@@ -967,6 +970,44 @@ describes.realWin('CustomElement', {amp: true}, (env) => {
967970 expect ( element ) . to . not . have . class ( 'i-amphtml-unresolved' ) ;
968971 } ) ;
969972
973+ it ( 'StubElement - attachedCallback after failed to load' , ( ) => {
974+ const element = new StubElementClass ( ) ;
975+ markUnresolvedElements ( 'amp-stub' ) ;
976+ element . setAttribute ( 'layout' , 'fill' ) ;
977+ expect ( element . everAttached ) . to . equal ( false ) ;
978+ expect ( element . getLayout ( ) ) . to . equal ( Layout . NODISPLAY ) ;
979+
980+ resourcesMock . expects ( 'add' ) . withExactArgs ( element ) . atLeast ( 1 ) ;
981+ container . appendChild ( element ) ;
982+
983+ expect ( element . everAttached ) . to . equal ( true ) ;
984+ expect ( element . getLayout ( ) ) . to . equal ( Layout . FILL ) ;
985+ // Extension already failed before attachedCallback
986+ expect ( element ) . to . have . class ( 'amp-unresolved' ) ;
987+ expect ( element ) . to . have . class ( 'i-amphtml-unresolved' ) ;
988+ } ) ;
989+
990+ it ( 'StubElement - attachedCallback before failed to load' , ( ) => {
991+ const element = new StubElementClass ( ) ;
992+ element . setAttribute ( 'layout' , 'fill' ) ;
993+ expect ( element . everAttached ) . to . equal ( false ) ;
994+ expect ( element . getLayout ( ) ) . to . equal ( Layout . NODISPLAY ) ;
995+
996+ resourcesMock . expects ( 'add' ) . withExactArgs ( element ) . atLeast ( 1 ) ;
997+ container . appendChild ( element ) ;
998+
999+ expect ( element . everAttached ) . to . equal ( true ) ;
1000+ expect ( element . getLayout ( ) ) . to . equal ( Layout . FILL ) ;
1001+ // Not upgraded yet, but extension hasn't failed.
1002+ expect ( element ) . not . to . have . class ( 'amp-unresolved' ) ;
1003+ expect ( element ) . not . to . have . class ( 'i-amphtml-unresolved' ) ;
1004+
1005+ // Now it's called.
1006+ markUnresolvedElements ( 'amp-stub' ) ;
1007+ expect ( element ) . to . have . class ( 'amp-unresolved' ) ;
1008+ expect ( element ) . to . have . class ( 'i-amphtml-unresolved' ) ;
1009+ } ) ;
1010+
9701011 it ( 'Element - detachedCallback' , ( ) => {
9711012 const element = new ElementClass ( ) ;
9721013 element . setAttribute ( 'layout' , 'fill' ) ;
0 commit comments