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