@@ -43,6 +43,7 @@ import org.robolectric.Robolectric
43
43
import org.robolectric.RobolectricTestRunner
44
44
import org.robolectric.Shadows.shadowOf
45
45
import org.robolectric.shadows.ShadowLooper
46
+ import java.util.regex.Pattern
46
47
47
48
@RunWith(RobolectricTestRunner ::class )
48
49
class CheckoutWebViewTest {
@@ -140,6 +141,40 @@ class CheckoutWebViewTest {
140
141
}
141
142
}
142
143
144
+ @Test
145
+ fun `records checkout_finished_loading instrumentation event on page finished - preloading` () {
146
+ withPreloadingEnabled {
147
+ val isPreload = true
148
+ val view = CheckoutWebView .cacheableCheckoutView(URL , activity, isPreload)
149
+ val shadow = shadowOf(view)
150
+ shadow.webViewClient.onPageFinished(view, URL )
151
+
152
+ val regex = Pattern .compile(
153
+ @Suppress(" MaxLineLength" )
154
+ """ .*\.dispatchMessage\('instrumentation', \{"detail":\{"name":"checkout_finished_loading","value":\d*,"type":"histogram","tags":\{"preloading":"true"}}}\).*""" ,
155
+ Pattern .DOTALL
156
+ )
157
+ assertThat(shadow.lastEvaluatedJavascript).matches(regex)
158
+ }
159
+ }
160
+
161
+ @Test
162
+ fun `records checkout_finished_loading instrumentation event on page finished - presenting` () {
163
+ withPreloadingEnabled {
164
+ val isPreload = false
165
+ val view = CheckoutWebView .cacheableCheckoutView(URL , activity, isPreload)
166
+ val shadow = shadowOf(view)
167
+ shadow.webViewClient.onPageFinished(view, URL )
168
+
169
+ val regex = Pattern .compile(
170
+ @Suppress(" MaxLineLength" )
171
+ """ .*\.dispatchMessage\('instrumentation', \{"detail":\{"name":"checkout_finished_loading","value":\d*,"type":"histogram","tags":\{"preloading":"false"}}}\).*""" ,
172
+ Pattern .DOTALL
173
+ )
174
+ assertThat(shadow.lastEvaluatedJavascript).matches(regex)
175
+ }
176
+ }
177
+
143
178
@Test
144
179
fun `does not send prefetch header for preloads` () {
145
180
val isPreload = false
0 commit comments