|
| 1 | +import { AndroidDebugService } from "../../lib/services/android-debug-service"; |
| 2 | +import { Yok } from "../../lib/common/yok"; |
| 3 | +import * as stubs from "../stubs"; |
| 4 | +import { assert } from "chai"; |
| 5 | + |
| 6 | +class AndroidDebugServiceInheritor extends AndroidDebugService { |
| 7 | + constructor(protected $devicesService: Mobile.IDevicesService, |
| 8 | + $errors: IErrors, |
| 9 | + $logger: ILogger, |
| 10 | + $config: IConfiguration, |
| 11 | + $androidDeviceDiscovery: Mobile.IDeviceDiscovery, |
| 12 | + $androidProcessService: Mobile.IAndroidProcessService, |
| 13 | + $net: INet) { |
| 14 | + super($devicesService, $errors, $logger, $config, $androidDeviceDiscovery, $androidProcessService, $net); |
| 15 | + } |
| 16 | + |
| 17 | + public getChromeDebugUrl(debugOptions: IDebugOptions, port: number): string { |
| 18 | + return super.getChromeDebugUrl(debugOptions, port); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +const createTestInjector = (): IInjector => { |
| 23 | + const testInjector = new Yok(); |
| 24 | + testInjector.register("devicesService", {}); |
| 25 | + testInjector.register("errors", stubs.ErrorsStub); |
| 26 | + testInjector.register("logger", stubs.LoggerStub); |
| 27 | + testInjector.register("config", {}); |
| 28 | + testInjector.register("androidDeviceDiscovery", {}); |
| 29 | + testInjector.register("androidProcessService", {}); |
| 30 | + testInjector.register("net", {}); |
| 31 | + |
| 32 | + return testInjector; |
| 33 | +}; |
| 34 | + |
| 35 | +interface IChromeUrlTestCase { |
| 36 | + debugOptions: IDebugOptions; |
| 37 | + expectedChromeUrl: string; |
| 38 | + scenarioName: string; |
| 39 | +} |
| 40 | + |
| 41 | +describe("androidDebugService", () => { |
| 42 | + describe("getChromeDebugUrl", () => { |
| 43 | + const expectedPort = 12345; |
| 44 | + const chromUrlTestCases: IChromeUrlTestCase[] = [ |
| 45 | + // Default CLI behavior: |
| 46 | + { |
| 47 | + scenarioName: "useBundledDevTools and useHttpUrl are not passed", |
| 48 | + debugOptions: {}, |
| 49 | + expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 50 | + }, |
| 51 | + |
| 52 | + // When useBundledDevTools is true |
| 53 | + { |
| 54 | + scenarioName: "useBundledDevTools is true and useHttpUrl is not passed", |
| 55 | + debugOptions: { |
| 56 | + useBundledDevTools: true |
| 57 | + }, |
| 58 | + expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 59 | + }, |
| 60 | + { |
| 61 | + scenarioName: "useBundledDevTools is true and useHttpUrl is false", |
| 62 | + debugOptions: { |
| 63 | + useBundledDevTools: true, |
| 64 | + useHttpUrl: false |
| 65 | + }, |
| 66 | + expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 67 | + }, |
| 68 | + { |
| 69 | + scenarioName: "useBundledDevTools is true and useHttpUrl is true", |
| 70 | + debugOptions: { |
| 71 | + useBundledDevTools: true, |
| 72 | + useHttpUrl: true |
| 73 | + }, |
| 74 | + expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@02e6bde1bbe34e43b309d4ef774b1168d25fd024/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 75 | + }, |
| 76 | + |
| 77 | + // When useBundledDevTools is false |
| 78 | + { |
| 79 | + scenarioName: "useBundledDevTools is false and useHttpUrl is not passed", |
| 80 | + debugOptions: { |
| 81 | + useBundledDevTools: false |
| 82 | + }, |
| 83 | + expectedChromeUrl: `chrome-devtools://devtools/remote/serve_file/@02e6bde1bbe34e43b309d4ef774b1168d25fd024/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 84 | + }, |
| 85 | + { |
| 86 | + scenarioName: "useBundledDevTools is false and useHttpUrl is false", |
| 87 | + debugOptions: { |
| 88 | + useBundledDevTools: false, |
| 89 | + useHttpUrl: false |
| 90 | + }, |
| 91 | + expectedChromeUrl: `chrome-devtools://devtools/remote/serve_file/@02e6bde1bbe34e43b309d4ef774b1168d25fd024/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 92 | + }, |
| 93 | + { |
| 94 | + scenarioName: "useBundledDevTools is false and useHttpUrl is true", |
| 95 | + debugOptions: { |
| 96 | + useBundledDevTools: false, |
| 97 | + useHttpUrl: true |
| 98 | + }, |
| 99 | + expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@02e6bde1bbe34e43b309d4ef774b1168d25fd024/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 100 | + }, |
| 101 | + |
| 102 | + // When useBundledDevTools is not passed |
| 103 | + { |
| 104 | + scenarioName: "useBundledDevTools is not passed and useHttpUrl is false", |
| 105 | + debugOptions: { |
| 106 | + useHttpUrl: false |
| 107 | + }, |
| 108 | + expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 109 | + }, |
| 110 | + { |
| 111 | + scenarioName: "useBundledDevTools is not passed and useHttpUrl is true", |
| 112 | + debugOptions: { |
| 113 | + useHttpUrl: true |
| 114 | + }, |
| 115 | + expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@02e6bde1bbe34e43b309d4ef774b1168d25fd024/inspector.html?experiments=true&ws=localhost:${expectedPort}`, |
| 116 | + } |
| 117 | + |
| 118 | + ]; |
| 119 | + |
| 120 | + for (const testCase of chromUrlTestCases) { |
| 121 | + it(`returns correct url when ${testCase.scenarioName}`, () => { |
| 122 | + const testInjector = createTestInjector(); |
| 123 | + const androidDebugService = testInjector.resolve<AndroidDebugServiceInheritor>(AndroidDebugServiceInheritor); |
| 124 | + const actualChromeUrl = androidDebugService.getChromeDebugUrl(testCase.debugOptions, expectedPort); |
| 125 | + assert.equal(actualChromeUrl, testCase.expectedChromeUrl); |
| 126 | + }); |
| 127 | + } |
| 128 | + }); |
| 129 | +}); |
0 commit comments