1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
ash / webui / diagnostics_ui / resources / connectivity_card.ts [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import './diagnostics_card.js';
import './diagnostics_network_icon.js';
import './diagnostics_shared.css.js';
import './ip_config_info_drawer.js';
import './network_info.js';
import './routine_section.js';
import {I18nMixin} from 'chrome://resources/ash/common/cr_elements/i18n_mixin.js';
import {assert} from 'chrome://resources/js/assert.js';
import {PolymerElementProperties} from 'chrome://resources/polymer/v3_0/polymer/interfaces.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {getTemplate} from './connectivity_card.html.js';
import {filterNameServers, formatMacAddress, getNetworkCardTitle, getNetworkState, getNetworkType, getRoutineGroups} from './diagnostics_utils.js';
import {getNetworkHealthProvider} from './mojo_interface_provider.js';
import {Network, NetworkHealthProviderInterface, NetworkStateObserverReceiver} from './network_health_provider.mojom-webui.js';
import {RoutineGroup} from './routine_group.js';
import {TestSuiteStatus} from './routine_list_executor.js';
import {RoutineSectionElement} from './routine_section.js';
/**
* @fileoverview
* 'connectivity-card' runs network routines and displays network health data.
*/
const ConnectivityCardElementBase = I18nMixin(PolymerElement);
export class ConnectivityCardElement extends ConnectivityCardElementBase {
static get is(): 'connectivity-card' {
return 'connectivity-card' as const;
}
static get template(): HTMLTemplateElement {
return getTemplate();
}
static get properties(): PolymerElementProperties {
return {
testSuiteStatus: {
type: Number,
value: TestSuiteStatus.NOT_RUNNING,
notify: true,
},
routineGroups: {
type: Array,
value: () => [],
},
activeGuid: {
type: String,
value: '',
observer: ConnectivityCardElement.prototype.activeGuidChanged,
},
isActive: {
type: Boolean,
observer: ConnectivityCardElement.prototype.isActiveChanged,
},
network: {
type: Object,
},
networkType: {
type: String,
value: '',
},
networkState: {
type: String,
value: '',
},
macAddress: {
type: String,
value: '',
},
};
}
testSuiteStatus: TestSuiteStatus;
activeGuid: string;
isActive: boolean;
network: Network;
protected macAddress: string;
private networkType: string;
private networkState: string;
private routineGroups: RoutineGroup[];
private networkHealthProvider: NetworkHealthProviderInterface =
getNetworkHealthProvider();
private networkStateObserverReceiver: NetworkStateObserverReceiver|null =
null;
private getRoutineSectionElem(): RoutineSectionElement {
const routineSection = this.shadowRoot!.querySelector('routine-section');
assert(routineSection);
return routineSection;
}
override disconnectedCallback(): void {
super.disconnectedCallback();
this.getRoutineSectionElem().stopTests();
}
getRoutineGroupsForTesting(): RoutineGroup[] {
return this.routineGroups;
}
protected hasRoutines(): boolean {
return this.routineGroups && this.routineGroups.length > 0;
}
private observeNetwork(): void {
if (this.networkStateObserverReceiver) {
this.networkStateObserverReceiver.$.close();
this.networkStateObserverReceiver = null;
}
this.networkStateObserverReceiver = new NetworkStateObserverReceiver(this);
this.networkHealthProvider.observeNetwork(
this.networkStateObserverReceiver.$.bindNewPipeAndPassRemote(),
this.activeGuid);
}
/**
* Implements NetworkStateObserver.onNetworkStateChanged
*/
onNetworkStateChanged(network: Network): void {
this.networkType = getNetworkType(network.type);
this.networkState = getNetworkState(network.state);
this.macAddress = network.macAddress || '';
if (this.testSuiteStatus === TestSuiteStatus.NOT_RUNNING) {
this.routineGroups = getRoutineGroups(network.type);
this.getRoutineSectionElem().runTests();
}
// Remove '0.0.0.0' (if present) from list of name servers.
filterNameServers(network);
this.set('network', network);
}
protected getEstimateRuntimeInMinutes(): 1 {
// Connectivity routines will always last <= 1 minute.
return 1;
}
protected getNetworkCardTitle(): string {
return getNetworkCardTitle(this.networkType, this.networkState);
}
protected activeGuidChanged(activeGuid: string): void {
if (this.testSuiteStatus === TestSuiteStatus.COMPLETED) {
this.testSuiteStatus = TestSuiteStatus.NOT_RUNNING;
}
if (!activeGuid) {
return;
}
this.getRoutineSectionElem().stopTests();
this.observeNetwork();
}
protected isActiveChanged(active: boolean): void {
if (!active) {
return;
}
if (this.routineGroups.length > 0) {
this.getRoutineSectionElem().runTests();
}
}
protected getMacAddress(): string {
if (!this.macAddress) {
return '';
}
return formatMacAddress(this.macAddress);
}
getRoutineSectionElemForTesting(): RoutineSectionElement {
return this.getRoutineSectionElem();
}
}
declare global {
interface HTMLElementTagNameMap {
[ConnectivityCardElement.is]: ConnectivityCardElement;
}
}
customElements.define(ConnectivityCardElement.is, ConnectivityCardElement);