-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathandroid-device-debug-service.ts
175 lines (162 loc) · 6.53 KB
/
android-device-debug-service.ts
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
import { AndroidDeviceDebugService } from "../../lib/services/android-device-debug-service";
import { Yok } from "../../lib/common/yok";
import * as stubs from "../stubs";
import { assert } from "chai";
const expectedDevToolsCommitSha = "02e6bde1bbe34e43b309d4ef774b1168d25fd024";
class AndroidDeviceDebugServiceInheritor extends AndroidDeviceDebugService {
constructor(protected $devicesService: Mobile.IDevicesService,
$cleanupService: ICleanupService,
$errors: IErrors,
$logger: ILogger,
$androidProcessService: Mobile.IAndroidProcessService,
$staticConfig: IStaticConfig,
$net: INet,
$deviceLogProvider: Mobile.IDeviceLogProvider) {
super(<any>{ deviceInfo: { identifier: "123" } }, $devicesService, $cleanupService, $errors, $logger, $androidProcessService, $staticConfig, $net, $deviceLogProvider);
}
public getChromeDebugUrl(debugOptions: IDebugOptions, port: number, legacy?: boolean): string {
return super.getChromeDebugUrl(debugOptions, port, legacy);
}
}
const createTestInjector = (): IInjector => {
const testInjector = new Yok();
testInjector.register("devicesService", {});
testInjector.register("errors", stubs.ErrorsStub);
testInjector.register("logger", stubs.LoggerStub);
testInjector.register("npm", stubs.NodePackageManagerStub);
testInjector.register("androidDeviceDiscovery", {});
testInjector.register("androidProcessService", {});
testInjector.register("net", {});
testInjector.register("projectDataService", {});
testInjector.register("deviceLogProvider", {});
testInjector.register("cleanupService", {});
testInjector.register("staticConfig", {});
return testInjector;
};
interface IChromeUrlTestCase {
debugOptions: IDebugOptions;
expectedChromeUrl: string;
scenarioName: string;
legacy?: boolean;
}
describe("androidDeviceDebugService", () => {
describe("getChromeDebugUrl", () => {
const expectedPort = 12345;
const customDevToolsCommit = "customDevToolsCommit";
const chromUrlTestCases: IChromeUrlTestCase[] = [
// Default CLI behavior:
{
scenarioName: "useBundledDevTools and useHttpUrl are not passed",
debugOptions: {},
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
},
// legacy chrome debug url
{
scenarioName: "useBundledDevTools and useHttpUrl are not passed and using legacy chrome debug url",
debugOptions: {},
expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}&experiments=true`,
legacy: true
},
// When useBundledDevTools is true
{
scenarioName: "useBundledDevTools is true and useHttpUrl is not passed",
debugOptions: {
useBundledDevTools: true
},
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "useBundledDevTools is true and useHttpUrl is false",
debugOptions: {
useBundledDevTools: true,
useHttpUrl: false
},
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "useBundledDevTools is true and useHttpUrl is true",
debugOptions: {
useBundledDevTools: true,
useHttpUrl: true
},
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
},
// When useBundledDevTools is false
{
scenarioName: "useBundledDevTools is false and useHttpUrl is not passed",
debugOptions: {
useBundledDevTools: false
},
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "useBundledDevTools is false and useHttpUrl is false",
debugOptions: {
useBundledDevTools: false,
useHttpUrl: false
},
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "useBundledDevTools is false and useHttpUrl is true",
debugOptions: {
useBundledDevTools: false,
useHttpUrl: true
},
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
},
// When useBundledDevTools is not passed
{
scenarioName: "useBundledDevTools is not passed and useHttpUrl is false",
debugOptions: {
useHttpUrl: false
},
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "useBundledDevTools is not passed and useHttpUrl is true",
debugOptions: {
useHttpUrl: true
},
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
},
// devToolsCommit tests
{
scenarioName: "devToolsCommit defaults to ${expectedDevToolsCommitSha} when useBundledDevTools is set to false",
debugOptions: {
useBundledDevTools: false
},
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "devToolsCommit is disregarded when useBundledDevTools is not passed",
debugOptions: {},
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "devToolsCommit is set to passed value when useBundledDevTools is set to false",
debugOptions: {
useBundledDevTools: false,
devToolsCommit: customDevToolsCommit
},
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${customDevToolsCommit}/inspector.html?ws=localhost:${expectedPort}`,
},
{
scenarioName: "devToolsCommit is set to passed value when useHttpUrl is set to true",
debugOptions: {
useHttpUrl: true,
devToolsCommit: customDevToolsCommit
},
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${customDevToolsCommit}/inspector.html?ws=localhost:${expectedPort}`,
}
];
for (const testCase of chromUrlTestCases) {
it(`returns correct url when ${testCase.scenarioName}`, () => {
const testInjector = createTestInjector();
const androidDeviceDebugService = testInjector.resolve<AndroidDeviceDebugServiceInheritor>(AndroidDeviceDebugServiceInheritor);
const actualChromeUrl = androidDeviceDebugService.getChromeDebugUrl(testCase.debugOptions, expectedPort, testCase.legacy);
assert.equal(actualChromeUrl, testCase.expectedChromeUrl);
});
}
});
});