Skip to content

Commit

Permalink
fix(adb): force page scale factor update on connection (#4755)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Dec 18, 2020
1 parent a721ba5 commit 774eb53
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android-types-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface AndroidDevice<BrowserContextOptions, BrowserContext, Page> exte
open(command: string): Promise<AndroidSocket>;
installApk(file: string | Buffer, options?: { args?: string[] }): Promise<void>;
push(file: string | Buffer, path: string, options?: { mode?: number }): Promise<void>;
launchBrowser(options?: BrowserContextOptions & { packageName?: string }): Promise<BrowserContext>;
launchBrowser(options?: BrowserContextOptions & { pkg?: string }): Promise<BrowserContext>;
close(): Promise<void>;

wait(selector: AndroidSelector, options?: { state?: 'gone' } & { timeout?: number }): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c
});
}

async launchBrowser(options: types.BrowserContextOptions & { packageName?: string } = {}): Promise<BrowserContext> {
async launchBrowser(options: types.BrowserContextOptions & { pkg?: string } = {}): Promise<BrowserContext> {
return this._wrapApiCall('androidDevice.launchBrowser', async () => {
const contextOptions = await prepareBrowserContextOptions(options);
const { context } = await this._channel.launchBrowser(contextOptions);
Expand Down
2 changes: 1 addition & 1 deletion src/dispatchers/androidDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class AndroidDeviceDispatcher extends Dispatcher<AndroidDevice, channels.
}

async launchBrowser(params: channels.AndroidDeviceLaunchBrowserParams): Promise<channels.AndroidDeviceLaunchBrowserResult> {
const context = await this._object.launchBrowser(params.packageName, params);
const context = await this._object.launchBrowser(params.pkg, params);
return { context: new BrowserContextDispatcher(this._scope, context) };
}

Expand Down
4 changes: 2 additions & 2 deletions src/protocol/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2648,7 +2648,7 @@ export type AndroidDeviceInputDragOptions = {
};
export type AndroidDeviceInputDragResult = void;
export type AndroidDeviceLaunchBrowserParams = {
packageName?: string,
pkg?: string,
ignoreHTTPSErrors?: boolean,
javaScriptEnabled?: boolean,
bypassCSP?: boolean,
Expand Down Expand Up @@ -2693,7 +2693,7 @@ export type AndroidDeviceLaunchBrowserParams = {
},
};
export type AndroidDeviceLaunchBrowserOptions = {
packageName?: string,
pkg?: string,
ignoreHTTPSErrors?: boolean,
javaScriptEnabled?: boolean,
bypassCSP?: boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ AndroidDevice:

launchBrowser:
parameters:
packageName: string?
pkg: string?
ignoreHTTPSErrors: boolean?
javaScriptEnabled: boolean?
bypassCSP: boolean?
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
steps: tNumber,
});
scheme.AndroidDeviceLaunchBrowserParams = tObject({
packageName: tOptional(tString),
pkg: tOptional(tString),
ignoreHTTPSErrors: tOptional(tBoolean),
javaScriptEnabled: tOptional(tBoolean),
bypassCSP: tOptional(tBoolean),
Expand Down
14 changes: 12 additions & 2 deletions src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Transport } from '../../protocol/transport';
import { RecentLogsCollector } from '../../utils/debugLogger';
import { TimeoutSettings } from '../../utils/timeoutSettings';
import { AndroidWebView } from '../../protocol/channels';
import { CRPage } from '../chromium/crPage';

const readFileAsync = util.promisify(fs.readFile);

Expand Down Expand Up @@ -267,10 +268,19 @@ export class AndroidDevice extends EventEmitter {

const browser = await CRBrowser.connect(androidBrowser, browserOptions);
const controller = new ProgressController();
const defaultContext = browser._defaultContext!;
await controller.run(async progress => {
await browser._defaultContext!._loadDefaultContextAsIs(progress);
await defaultContext._loadDefaultContextAsIs(progress);
});
return browser._defaultContext!;
{
// TODO: remove after rolling to r838157
// Force page scale factor update.
const page = defaultContext.pages()[0];
const crPage = page._delegate as CRPage;
await crPage._mainFrameSession._client.send('Emulation.setDeviceMetricsOverride', { mobile: false, width: 0, height: 0, deviceScaleFactor: 0 });
await crPage._mainFrameSession._client.send('Emulation.clearDeviceMetricsOverride', {});
}
return defaultContext;
}

webViews(): AndroidWebView[] {
Expand Down
10 changes: 10 additions & 0 deletions test/android/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ if (process.env.PW_ANDROID_TESTS) {
await page.close();
await context.close();
});

it('should check', async function({ device }) {
const context = await device.launchBrowser();
const [page] = context.pages();
await page.setContent(`<input id='checkbox' type='checkbox'></input>`);
await page.check('input');
expect(await page.evaluate(() => window['checkbox'].checked)).toBe(true);
await page.close();
await context.close();
});
}
2 changes: 1 addition & 1 deletion utils/avd_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ echo "Killing previous emulators"
${ANDROID_HOME}/platform-tools/adb devices | grep emulator | cut -f1 | while read line; do ${ANDROID_HOME}/platform-tools/adb -s $line emu kill; done

echo "Starting emulator"
nohup ${ANDROID_HOME}/emulator/emulator -avd android30 -no-audio -no-snapshot &
nohup ${ANDROID_HOME}/emulator/emulator -avd android30 -no-audio -gpu swiftshader &
${ANDROID_HOME}/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
${ANDROID_HOME}/platform-tools/adb devices
echo "Emulator started"

0 comments on commit 774eb53

Please sign in to comment.