6
6
// #import 'chrome://os-settings/strings.m.js';
7
7
// #import 'chrome://resources/cr_components/chromeos/cellular_setup/psim_flow_ui.m.js';
8
8
9
- // #import {PSimUIState, PSimPageName} from 'chrome://resources/cr_components/chromeos/cellular_setup/psim_flow_ui.m.js';
9
+ // #import {PSimUIState, PSimPageName, PSimSetupFlowResult } from 'chrome://resources/cr_components/chromeos/cellular_setup/psim_flow_ui.m.js';
10
10
// #import {setCellularSetupRemoteForTesting} from 'chrome://resources/cr_components/chromeos/cellular_setup/mojo_interface_provider.m.js';
11
11
// #import {flush, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
12
12
// #import {assertTrue} from '../../../chai_assert.js';
16
16
// clang-format on
17
17
18
18
suite ( 'CrComponentsPsimFlowUiTest' , function ( ) {
19
+ class MockMetricsPrivate {
20
+ constructor ( ) {
21
+ this . cellularSetupResultDict = { } ;
22
+ }
23
+
24
+ recordEnumerationValue ( histogramName , pSimSetupFlowResult , enumSize ) {
25
+ assertEquals ( histogramName , 'Network.Cellular.PSim.CellularSetupResult' ) ;
26
+ if ( pSimSetupFlowResult in this . cellularSetupResultDict ) {
27
+ this . cellularSetupResultDict [ pSimSetupFlowResult ] ++ ;
28
+ return ;
29
+ }
30
+ this . cellularSetupResultDict [ pSimSetupFlowResult ] = 1 ;
31
+ }
32
+
33
+ getSetupResultMetricCount ( metricEnum ) {
34
+ if ( metricEnum in this . cellularSetupResultDict ) {
35
+ return this . cellularSetupResultDict [ metricEnum ] ;
36
+ }
37
+ return 0 ;
38
+ }
39
+ }
40
+
19
41
let pSimPage ;
20
42
21
43
/** @type {?chromeos.cellularSetup.mojom.CellularSetupRemote } */
@@ -33,12 +55,24 @@ suite('CrComponentsPsimFlowUiTest', function() {
33
55
return new Promise ( resolve => setTimeout ( resolve ) ) ;
34
56
}
35
57
58
+ /** @param {PSimSetupFlowResult } pSimSetupFlowResult */
59
+ function endFlowAndVerifyResult ( pSimSetupFlowResult ) {
60
+ const resultCount =
61
+ chrome . metricsPrivate . getSetupResultMetricCount ( pSimSetupFlowResult ) ;
62
+ pSimPage . remove ( ) ;
63
+ Polymer . dom . flush ( ) ;
64
+ assertEquals (
65
+ chrome . metricsPrivate . getSetupResultMetricCount ( pSimSetupFlowResult ) ,
66
+ resultCount + 1 ) ;
67
+ }
68
+
36
69
setup ( function ( ) {
37
70
cellularCarrierHandler =
38
71
new cellular_setup . FakeCarrierPortalHandlerRemote ( ) ;
39
72
cellularSetupRemote =
40
73
new cellular_setup . FakeCellularSetupRemote ( cellularCarrierHandler ) ;
41
74
cellular_setup . setCellularSetupRemoteForTesting ( cellularSetupRemote ) ;
75
+ chrome . metricsPrivate = new MockMetricsPrivate ( ) ;
42
76
43
77
pSimPage = document . createElement ( 'psim-flow-ui' ) ;
44
78
pSimPage . delegate = new cellular_setup . FakeCellularSetupDelegate ( ) ;
@@ -66,6 +100,8 @@ suite('CrComponentsPsimFlowUiTest', function() {
66
100
assertTrue (
67
101
pSimPage . selectedPSimPageName_ ===
68
102
cellularSetup . PSimPageName . PROVISIONING ) ;
103
+
104
+ endFlowAndVerifyResult ( PSimSetupFlowResult . SUCCESS ) ;
69
105
} ) ;
70
106
71
107
test ( 'Sim detection failure with retries' , async function ( ) {
@@ -136,8 +172,9 @@ suite('CrComponentsPsimFlowUiTest', function() {
136
172
. kPortalLoadedWithoutPaidUser ) ;
137
173
138
174
await flushAsync ( ) ;
139
-
140
175
assertTrue ( pSimPage . nameOfCarrierPendingSetup === 'Verizon wireless' ) ;
176
+
177
+ endFlowAndVerifyResult ( PSimSetupFlowResult . CANCELLED ) ;
141
178
} ) ;
142
179
143
180
test ( 'forward navigation and finish cellular setup test' , async function ( ) {
@@ -159,5 +196,31 @@ suite('CrComponentsPsimFlowUiTest', function() {
159
196
160
197
await flushAsync ( ) ;
161
198
assertTrue ( exitCellularSetupEventFired ) ;
199
+
200
+ endFlowAndVerifyResult ( PSimSetupFlowResult . SUCCESS ) ;
201
+ } ) ;
202
+
203
+ test ( 'Activation failure metric logged' , async ( ) => {
204
+ cellularActivationDelegate =
205
+ cellularSetupRemote . getLastActivationDelegate ( ) ;
206
+
207
+ let provisioningPage = pSimPage . $$ ( '#provisioningPage' ) ;
208
+ assertTrue ( ! ! provisioningPage ) ;
209
+ assertFalse (
210
+ pSimPage . selectedPSimPageName_ ===
211
+ cellularSetup . PSimPageName . provisioningPage ) ;
212
+
213
+ cellularActivationDelegate . onActivationFinished (
214
+ chromeos . cellularSetup . mojom . ActivationResult . kFailedToActivate ) ;
215
+
216
+ await flushAsync ( ) ;
217
+ endFlowAndVerifyResult ( PSimSetupFlowResult . NETWORK_ERROR ) ;
218
+ } ) ;
219
+
220
+ test ( 'Portal error metric logged' , ( ) => {
221
+ let provisioningPage = pSimPage . $$ ( '#provisioningPage' ) ;
222
+ provisioningPage . fire ( 'carrier-portal-result' , false ) ;
223
+
224
+ endFlowAndVerifyResult ( PSimSetupFlowResult . CANCELLED_PORTAL_ERROR ) ;
162
225
} ) ;
163
226
} ) ;
0 commit comments