完善惊喜任务逐项执行和存储授权,兼容微信浏览入口及应用推荐下载落点。增加重复运行保护、投影恢复和任务完成复核,并保留原有安装适配。 验证:59项离线回归通过,生成文件一致性、语法及差异空白检查通过。
714 lines
42 KiB
JavaScript
714 lines
42 KiB
JavaScript
const test = require('node:test');
|
||
const assert = require('node:assert/strict');
|
||
const fs = require('node:fs');
|
||
const path = require('node:path');
|
||
const vm = require('node:vm');
|
||
|
||
const source = fs.readFileSync(path.join(__dirname, '../home_yibao/yingyongbao-all.auto.js'), 'utf8');
|
||
const definitions = source.slice(0, source.indexOf('// BEGIN ALL IN ONE ENTRY'));
|
||
const meal = [{text: '领晚餐补贴'}, {text: '01:30:00后领晚餐补贴'}];
|
||
|
||
function load() {
|
||
const c = vm.createContext({device: {width: 1080, height: 2400}, console: {log() {}},
|
||
files: {append() {}, write() {}}, sleep() {}});
|
||
vm.runInContext(definitions, c);
|
||
c.yibaoWorkflowState = {status: 'running', stages: []};
|
||
c.recoverCommonInstaller = () => false;
|
||
c.backToYibao = () => true;
|
||
c.getForegroundApp = () => ({packageName: 'com.tencent.android.qqdownloader'});
|
||
return c;
|
||
}
|
||
|
||
for (const page of [[], meal]) {
|
||
test(`五个启动入口均可执行饭点判断:${page.length ? '恢复晚餐页' : '普通页面'}`, () => {
|
||
const c = load();
|
||
let launched = 0, returned = 0;
|
||
c.recognizeScreenSafe = () => page;
|
||
for (const profile of c.YIBAO_PROFILES) {
|
||
c.activateYibaoFlow(profile);
|
||
c.leaveMealSubsidyPage = () => { returned++; return true; };
|
||
c.businessLaunchYibao = () => launched++;
|
||
c.launchYibao();
|
||
}
|
||
assert.equal(launched, 5);
|
||
assert.equal(returned, page.length ? 4 : 0);
|
||
});
|
||
|
||
test(`五流程调度可越过饭点判断:${page.length ? '恢复晚餐页' : '普通页面'}`, () => {
|
||
const c = load();
|
||
const visited = [];
|
||
let returned = 0;
|
||
const activate = c.activateYibaoFlow;
|
||
c.activateYibaoFlow = profile => {
|
||
activate(profile);
|
||
c.leaveMealSubsidyPage = () => { returned++; return true; };
|
||
c.runHomeYibao = () => { visited.push(profile.id); return true; };
|
||
};
|
||
c.recognizeScreenSafe = () => page;
|
||
c.runYibaoStages(c.YIBAO_WORKFLOW.order);
|
||
assert.deepEqual(visited, ['0_0', '0_1', '1', '2', '3']);
|
||
assert.ok(c.yibaoWorkflowState.stages.every(stage => stage.status === 'success'));
|
||
assert.equal(returned, page.length ? 4 : 0);
|
||
});
|
||
}
|
||
|
||
test('下载入口缺失时结束扫描,空白识别不能当作入口不存在', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '1'));
|
||
c.getAdView1TargetVisibleState = () => ({});
|
||
c.scrollPageUp = () => true;
|
||
c.sleepScan = () => {};
|
||
c.recognizeScreenSafe = () => [{text: '特别任务赚积分', centerY: 1200, bounds: {top: 1180}}];
|
||
assert.equal(c.scrollUntilAdView1TargetsVisible(30), 'absent');
|
||
c.recognizeScreenSafe = () => [];
|
||
assert.equal(c.scrollUntilAdView1TargetsVisible(5), false);
|
||
c.recognizeScreenSafe = () => null;
|
||
assert.equal(c.scrollUntilAdView1TargetsVisible(5), false);
|
||
});
|
||
|
||
test('下载入口不存在时不重试,并继续看视频和惊喜任务', () => {
|
||
const c = load();
|
||
const visited = [];
|
||
const activate = c.activateYibaoFlow;
|
||
c.recognizeScreenSafe = () => [];
|
||
c.activateYibaoFlow = profile => {
|
||
activate(profile);
|
||
c.runHomeYibao = () => {
|
||
visited.push(profile.id);
|
||
if (profile.id === '1') return {status: 'skipped', reason: '入口不存在'};
|
||
};
|
||
};
|
||
c.runYibaoStages(['1', '2', '3']);
|
||
assert.deepEqual(visited, ['1', '2', '3']);
|
||
assert.equal(c.yibaoWorkflowState.stages[0].status, 'skipped');
|
||
assert.equal(c.yibaoWorkflowState.stages[0].attempts, 1);
|
||
});
|
||
|
||
test('OPPO 居中的系统安装弹窗支持安装、完成和打开', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '3'));
|
||
const item = text => ({text, resourceId: 'android:id/button1', enabled: true,
|
||
bounds: {left: 777, top: 1318, right: 969, bottom: 1480}, centerX: 873, centerY: 1399});
|
||
const page = text => ({packageName: 'com.android.packageinstaller', items: [item(text)]});
|
||
assert.equal(c.planCommonInstallAction(page('安装'), 'finish').kind, 'install');
|
||
assert.equal(c.planCommonInstallAction(page('完成'), 'finish').kind, 'finish');
|
||
const success = page('打开');
|
||
success.items.push({text: '安装成功'});
|
||
assert.equal(c.planCommonInstallAction(success, 'open').kind, 'open');
|
||
assert.equal(c.planCommonInstallAction({packageName: c.CONFIG.yibaoPackage, items: [item('安装')]}), null);
|
||
});
|
||
|
||
test('部分原生树只有取消,整屏OCR合并按钮时裁剪右侧并走完安装', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '3'));
|
||
let screen = 'confirm';
|
||
const clicked = [];
|
||
c.getForegroundApp = () => ({packageName: screen === 'returned' ? c.CONFIG.yibaoPackage : 'com.android.packageinstaller'});
|
||
const button = (text, resourceId, left, right) => ({text, resourceId, enabled: true,
|
||
bounds: {left, top: 1318, right, bottom: 1480}, centerX: (left + right) / 2, centerY: 1399});
|
||
c.readCommonInstallPage = () => ({packageName: 'com.android.packageinstaller', items: screen === 'confirm' ?
|
||
[button('取消', 'android:id/button2', 585, 777)] : [button('完成', 'android:id/button1', 777, 969)]});
|
||
c.recognizeScreenSafe = () => [{text: '取消 安装', bounds: {left: 641, top: 1377, right: 912, bottom: 1421}, centerX: 776, centerY: 1399}];
|
||
c.recognizeAdButtonRegion = (targets, region) => {
|
||
assert.equal(region.x, 777 / 1080);
|
||
assert.ok(targets.includes('安裝'));
|
||
return [button('安裝', '', 833, 911)];
|
||
};
|
||
c.clickOcrMatch = match => { clicked.push(match.target); screen = match.target === '安装' ? 'complete' : 'returned'; };
|
||
assert.equal(c.waitCommonInstaller(1000, 'finish'), true);
|
||
assert.deepEqual(clicked, ['安装', '完成']);
|
||
});
|
||
|
||
test('系统不响应安装点击时等待手动确认,之后继续完成安装', () => {
|
||
const c=load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p=>p.id==='3'));
|
||
let clock=0,screen='install',installClicks=0,prompts=0;
|
||
c.Date=class extends Date {static now(){return clock;}};
|
||
c.toast=()=>prompts++;
|
||
c.setStep=()=>{};
|
||
c.sleep=ms=>{clock+=ms;if(c.yibaoWorkflowState.manualInstall)screen=screen==='returned'?'returned':'finish';};
|
||
c.getForegroundApp=()=>({packageName:screen==='returned'?c.CONFIG.yibaoPackage:'com.android.packageinstaller'});
|
||
c.readCommonInstallPage=()=>({packageName:'com.android.packageinstaller',items:[{
|
||
text:screen==='install'?'安装':'完成',bounds:{left:777,top:1318,right:969,bottom:1480},centerX:873,centerY:1399
|
||
}]});
|
||
c.clickOcrMatch=match=>{if(match.target==='安装')installClicks++;else screen='returned';};
|
||
assert.equal(c.waitCommonInstaller(100000,'finish'),true);
|
||
assert.equal(installClicks,c.CONFIG.reliability.clickVerifyRetries);
|
||
assert.equal(prompts,1);
|
||
assert.equal(c.yibaoWorkflowState.manualInstall.status,'confirmed');
|
||
});
|
||
|
||
test('已领奖励落地页复用当前识别结果,静止页截图失败不阻塞原生关闭', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '2'));
|
||
const page = [{text: '恭喜已获得奖励'}];
|
||
c.getForegroundApp = () => ({packageName: 'com.tencent.android.qqdownloader'});
|
||
let visible = true, clicks = 0;
|
||
const node = {bounds: () => ({centerX: () => 980, centerY: () => 270})};
|
||
c.findVisibleCloseNode = c.findAdView1CloseNode = () => visible ? node : null;
|
||
c.recognizeScreenSafe = () => { throw new Error('静止页截图超时'); };
|
||
c.press = () => { clicks++; visible = false; return true; };
|
||
assert.equal(c.closeCompletedAdLanding(page), true);
|
||
assert.equal(clicks, 1);
|
||
});
|
||
|
||
test('限时应用先从列表底部回顶,回顶后才能判定入口缺失', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '1'));
|
||
c.getForegroundApp = () => ({packageName: c.CONFIG.yibaoPackage});
|
||
const page = label => [{text: label, centerY: 600, bounds: {top: 580, bottom: 620}}];
|
||
let swipes = 0;
|
||
c.recognizeScreenSafe = () => page(swipes < 2 ? '列表底部' : '每日福利签到');
|
||
c.swipe = (x1, y1, x2, y2) => { assert.ok(y2 > y1); swipes++; return true; };
|
||
assert.equal(c.rewindAdView1TaskList(), true);
|
||
assert.equal(swipes, 4);
|
||
c.recognizeScreenSafe = () => null;
|
||
assert.equal(c.rewindAdView1TaskList(), false);
|
||
c.recognizeScreenSafe = () => page('列表持续变化' + swipes);
|
||
assert.equal(c.rewindAdView1TaskList(), false);
|
||
});
|
||
|
||
test('仅在带完整导航栏的加载页识别重试,广告重试不点击', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '1'));
|
||
const retry = {text: '刷新重试', bounds: {top: 1100, bottom: 1200}};
|
||
const footer = ['首页', '秒玩', '赚钱', '我的'].map(text => ({text, bounds: {top: 2300, bottom: 2350}}));
|
||
assert.equal(c.findAdView1LoadRetryMatches([retry]).length, 0);
|
||
assert.equal(c.findAdView1LoadRetryMatches(footer.concat(retry)).length, 1);
|
||
retry.text = '点击页面刷新重试';
|
||
assert.equal(c.findAdView1LoadRetryMatches(footer.concat(retry)).length, 1);
|
||
retry.enabled = false;
|
||
assert.equal(c.findAdView1LoadRetryMatches(footer.concat(retry)).length, 0);
|
||
});
|
||
|
||
test('静止广告截图失败后刷新合成帧,成功或熔断都回收窗口', () => {
|
||
for (const recover of [true, false]) {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '1'));
|
||
c.captureBackendState = {mode: 'projection'};
|
||
let captures = 0, stopped = 0, started = 0;
|
||
c.captureScreenOnce = () => { captures++; if (recover && captures === 2) return {frame: true}; throw new Error('静止画面'); };
|
||
c.startYibaoCapturePulse = () => { started++; return {id: 1}; };
|
||
c.stopYibaoCapturePulse = pulse => { assert.equal(pulse.id, 1); stopped++; };
|
||
c.forceScreenRefresh = () => {};
|
||
c.CONFIG.shellCaptureFallback = {enabled: false};
|
||
if (recover) assert.equal(c.captureCurrentScreen().frame, true);
|
||
else assert.throws(() => c.captureCurrentScreen(), error => error.captureBackendFatal === true);
|
||
assert.equal(started, 1);
|
||
assert.equal(stopped, 1);
|
||
assert.equal(captures, recover ? 2 : 3);
|
||
}
|
||
});
|
||
|
||
test('兼容旧额外下载提示及下载井OCR误字,保留任务优先于关闭', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '1'));
|
||
for (const label of ['下载并打开浏览', '下载并浏览', '下载井打开浏览,多得40积分']) {
|
||
const items = [{text: '额外福利 基础奖励已获得'}, {text: label}, {text: '立即下载'}];
|
||
assert.equal(c.isAdView1ExtraDownloadOffer(items), true);
|
||
}
|
||
assert.equal(c.isAdView1ExtraDownloadOffer([{text: '恭喜已获得奖励'}, {text: '下载井打开浏览'}]), false);
|
||
c.waitAndClickAdAction = () => true;
|
||
c.waitThirdPartyForeground = () => null;
|
||
c.backToYibao = () => true;
|
||
c.recognizeScreenSafe = () => [{text: '额外福利 基础奖励已获得'}, {text: '下载井打开浏览'}, {text: '立即下载'}];
|
||
c.runExtraDownloadTask = () => { throw new Error('已进入原额外下载流程'); };
|
||
c.closeCompletedAdLanding = () => { throw new Error('错误地跳过额外任务'); };
|
||
assert.throws(() => c.runMainTaskTail(0), /已进入原额外下载流程/);
|
||
});
|
||
|
||
test('返回应用宝后第三方再次抢前台时重新拉起,持续抢回则失败', () => {
|
||
for (const alwaysBounce of [false, true]) {
|
||
const c = load();
|
||
vm.runInContext(fs.readFileSync(path.join(__dirname, '../unified/workflow.js'), 'utf8'), c);
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '1'));
|
||
c.businessBackToYibao = () => true;
|
||
c.commonInstallBusy = true;
|
||
let relaunched = 0;
|
||
c.getForegroundApp = () => ({packageName: alwaysBounce || relaunched === 0 ? 'com.ss.android.ugc.livelite' : c.CONFIG.yibaoPackage});
|
||
c.recoverYibaoForeground = () => { relaunched++; return true; };
|
||
assert.equal(c.backToYibao(15000), !alwaysBounce);
|
||
assert.equal(relaunched, alwaysBounce ? 2 : 1);
|
||
}
|
||
});
|
||
|
||
test('安装后检查弹窗遇第三方再次打开,停留15秒返回后继续原检查', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '1'));
|
||
let returned = false, waited = false;
|
||
c.getForegroundApp = () => ({packageName: returned ? c.CONFIG.yibaoPackage : 'com.ss.android.ugc.livelite'});
|
||
c.sleep = ms => { if (ms >= 15000) waited = true; };
|
||
c.backToYibao = () => { assert.equal(waited, true); returned = true; return true; };
|
||
c.readAdView1InstallPage = () => null;
|
||
c.recognizeScreenSafe = () => [{text: '任务中心'}];
|
||
assert.equal(c.clickBrowseEntryAfterInstall(30000), 'absent');
|
||
assert.equal(returned, true);
|
||
});
|
||
|
||
test('五流程兼容赚钱页滚到特别任务区域,单个推广文字不算任务中心', () => {
|
||
const c = load();
|
||
const footer = ['首页', '秒玩', '賺钱', '商城'].map(text => ({text, bounds: {top: 2318, bottom: 2351}}));
|
||
const rows = [{text: '特别任务賺积分'}, {text: '浏览「京东」15秒'}, {text: '去快影看视频赚积分'}];
|
||
for (const profile of c.YIBAO_PROFILES) {
|
||
c.activateYibaoFlow(profile);
|
||
assert.equal(c.isYibaoTaskCenter(footer.concat(rows)), true);
|
||
assert.equal(c.isYibaoTaskCenter(footer.concat({text: '去快影看视频赚积分'})), false);
|
||
assert.equal(c.isYibaoTaskCenter(rows), false);
|
||
assert.equal(c.isYibaoTaskCenter([{text: '任务中心'}, {text: '看视频赚积分'}]), true);
|
||
}
|
||
});
|
||
|
||
test('详情页下载进度退回下载按钮时重试,持续失败最多三次', () => {
|
||
for (const recover of [true, false]) {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES.find(p => p.id === '2'));
|
||
let now = 0, clicks = 0;
|
||
c.Date = class extends Date { static now() { return now; } };
|
||
c.sleep = ms => { now += ms; };
|
||
c.getForegroundApp = () => ({packageName: c.CONFIG.yibaoPackage});
|
||
const item = text => ({text, centerX: 540, centerY: 790, bounds: {left: 450, top: 770, right: 630, bottom: 820}});
|
||
c.recognizeScreenSafe = () => recover && clicks ? [item('安装')] :
|
||
[item('应用名称 抖音火山版 应用版本'), item('开发者 权限详情 隐私协议'), item('立即下载')];
|
||
c.clickOcrMatch = c.press = () => { clicks++; return true; };
|
||
assert.equal(c.waitDownloadComplete(300000), recover);
|
||
assert.equal(clicks, recover ? 1 : 3);
|
||
assert.ok(now < 60000);
|
||
}
|
||
});
|
||
|
||
test('点击强停确认后直接打开,即使系统停止标记始终为false', () => {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES[0]);
|
||
let foreground = 'com.android.settings', confirmed = false, launched = false;
|
||
const stop = {enabled: () => true, bounds: () => 'stop bounds'};
|
||
const confirm = {text: () => '强行停止'};
|
||
c.text = () => ({packageName: () => ({exists: () => true})});
|
||
c.textMatches = () => ({packageName: () => ({findOnce: () => stop})});
|
||
c.id = () => ({packageName: () => ({findOnce: () => confirm})});
|
||
c.workflowStartupPackage = () => foreground;
|
||
c.isYibaoPackageStopped = () => { assert.equal(confirmed, false, '确认后不再检查强停结果'); return false; };
|
||
c.clickWorkflowStartupNode = node => { if (node === confirm) confirmed = true; return true; };
|
||
c.app = {getAppName: () => '应用宝', openAppSetting() {}, launchPackage: pkg => {
|
||
assert.equal(confirmed, true); launched = true; foreground = pkg; return true;
|
||
}};
|
||
c.restartYibaoForWorkflow();
|
||
assert.equal(launched, true);
|
||
});
|
||
|
||
test('OPPO重建任务栈直接启动,不进入强停设置;vivo继续使用原分支', () => {
|
||
for (const pendingInstaller of [false, true]) {
|
||
const c = load();
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES[0]);
|
||
c.device.brand = 'OPPO'; c.device.manufacturer = 'OPPO';
|
||
let flags = 0, launched = false, leftHome = false;
|
||
const intent = {addFlags: value => { flags = value; }};
|
||
c.android = {content: {Intent: {FLAG_ACTIVITY_NEW_TASK: 0x10000000, FLAG_ACTIVITY_CLEAR_TASK: 0x8000}}};
|
||
c.context = {getPackageManager: () => ({getLaunchIntentForPackage: pkg => {
|
||
assert.equal(pkg, c.CONFIG.yibaoPackage); return intent;
|
||
}}), startActivity: value => { assert.equal(value, intent); launched = true; }};
|
||
c.home = () => { leftHome = true; };
|
||
c.app = {getAppName: () => '应用宝', openAppSetting: () => { throw new Error('不应进入强停设置'); }};
|
||
c.workflowStartupPackage = () => launched ? c.CONFIG.yibaoPackage : 'com.android.launcher';
|
||
c.getForegroundApp = () => ({packageName: launched && pendingInstaller ? 'com.android.packageinstaller' : c.CONFIG.yibaoPackage});
|
||
c.restartYibaoForWorkflow();
|
||
assert.equal(leftHome, true);
|
||
assert.equal(launched, true);
|
||
assert.equal(flags, 0x10008000);
|
||
c.device.brand = c.device.manufacturer = 'vivo';
|
||
assert.equal(c.usesYibaoTaskStackRestart(), false);
|
||
}
|
||
});
|
||
|
||
|
||
test('常亮通过独立线程续保,退出先停线程后释放且重复清理无副作用', () => {
|
||
const c=load(),calls=[];let worker;
|
||
c.createAndroidScreenAwake=()=>({keep:()=>calls.push('keep'),release:()=>calls.push('release')});
|
||
c.events={on:()=>{}};
|
||
c.threads={start:fn=>{worker=fn;calls.push('thread');return {interrupt:()=>calls.push('interrupt'),join:()=>calls.push('join')};}};
|
||
c.startYibaoScreenAwake();
|
||
let waits=0;const end=new Error('end');
|
||
c.sleep=ms=>{assert.equal(ms,2000);if(++waits===2)throw end;};
|
||
assert.throws(()=>worker(),e=>e===end);
|
||
c.stopYibaoScreenAwake();c.stopYibaoScreenAwake();
|
||
assert.deepEqual(calls,['keep','thread','keep','interrupt','join','release']);
|
||
});
|
||
|
||
test('原返回失败时恢复一次前台,安装器不强行退出', () => {
|
||
for(const installer of [false,true]) {
|
||
const c=load();vm.runInContext(fs.readFileSync(path.join(__dirname,'../unified/workflow.js'),'utf8'),c);
|
||
c.activateYibaoFlow(c.YIBAO_PROFILES[2]);c.commonInstallBusy=true;
|
||
c.businessBackToYibao=()=>false;let recovered=0;
|
||
c.getForegroundApp=()=>({packageName:installer?'com.android.packageinstaller':c.CONFIG.yibaoPackage});
|
||
c.recoverYibaoForeground=()=>{recovered++;return true;};
|
||
assert.equal(c.backToYibao(15000),!installer);assert.equal(recovered,installer?0:1);
|
||
}
|
||
});
|
||
|
||
test('启动Intent返回保留任务栈,不清空待领奖页面', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[2]);let started=false,flags=0;
|
||
const intent={addFlags:v=>{flags=v;}};
|
||
c.android={content:{Intent:{FLAG_ACTIVITY_NEW_TASK:0x10000000,FLAG_ACTIVITY_REORDER_TO_FRONT:0x20000}}};
|
||
c.context={getPackageManager:()=>({getLaunchIntentForPackage:()=>intent}),startActivity:i=>{assert.equal(i,intent);started=true;}};
|
||
c.getForegroundApp=()=>({packageName:started?c.CONFIG.yibaoPackage:'com.ss.android.ugc.live'});
|
||
assert.equal(c.recoverYibaoForeground(),true);assert.equal(flags,0x10020000);
|
||
});
|
||
|
||
test('小游戏首页缺少热门软件标题且OCR为空时仍补充原生赚钱底栏,弹窗不补充', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[2]);
|
||
const items=['首页','秒玩','赚钱','商城','我的'].map((text,i)=>({text,enabled:true,centerX:100+i*200,centerY:2280,bounds:{left:20+i*200,top:2230,right:180+i*200,bottom:2340}}));
|
||
c.readCommonInstallPage=()=>({packageName:c.CONFIG.yibaoPackage,items});
|
||
assert.equal(c.supplementYibaoNavigation([])[0].text,'赚钱');
|
||
items.push({text:'现在退出'});assert.equal(c.supplementYibaoNavigation([]).length,0);
|
||
});
|
||
|
||
test('清理续保线程发生异常时仍释放亮屏租约', () => {
|
||
const c=load();let released=0;
|
||
c.yibaoScreenAwakeWorker={interrupt(){},join(){throw Error('interrupted');}};
|
||
c.yibaoScreenAwakeKeeper={release(){released++;}};
|
||
assert.throws(()=>c.stopYibaoScreenAwake(),/interrupted/);
|
||
assert.equal(released,1);assert.equal(c.yibaoScreenAwakeWorker,null);
|
||
c.stopYibaoScreenAwake();assert.equal(released,1);
|
||
});
|
||
|
||
test('签到直接进入点击后浏览奖励广告时不再等待旧版4/6,普通推广不误判', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[0]);
|
||
const ad=[{text:'点击后,看15秒可获得奖励'},{text:'了解更多'},{text:'进入详情页或第三方应用'},{text:'广告'}];
|
||
assert.equal(c.isDailyCheckinRewardAd(ad),true);
|
||
c.recognizeScreenSafe=()=>ad;
|
||
assert.equal(c.waitForDailyCheckinTask(10000),true);
|
||
assert.equal(c.isDailyCheckinRewardAd([{text:'了解更多'},{text:'广告'}]),false);
|
||
assert.equal(c.isDailyCheckinRewardAd(ad.concat([{text:'任务中心'},{text:'我的积分'}])),false);
|
||
});
|
||
|
||
test('首次运行取得互斥锁,重复启动不运行业务并等待旧任务结束', () => {
|
||
const c=load();const lease={release(){throw Error('首个任务不能提前释放');}};
|
||
assert.equal(c.enterYibaoRunGuard({tryAcquire:()=>lease}),lease);
|
||
const calls=[];let attempts=0;
|
||
const result=c.enterYibaoRunGuard({
|
||
tryAcquire:()=>++attempts<4?null:{release:()=>calls.push('release')},
|
||
notify:()=>calls.push('notify'),wait:()=>calls.push('wait')
|
||
});
|
||
assert.equal(result,null);assert.deepEqual(calls,['notify','wait','wait','release']);
|
||
});
|
||
|
||
test('截图投影失效时只重建一次,成功后继续采样,持续失败仍熔断', () => {
|
||
for(const recovered of [true,false]) {
|
||
const c=load();c.CONFIG={};c.captureBackendState={mode:'projection'};
|
||
c.startYibaoCapturePulse=()=>null;c.stopYibaoCapturePulse=()=>{};
|
||
let calls=0,renewals=0;
|
||
c.captureScreenOnce=()=>{calls++;if(recovered && calls===4)return {image:true};throw Error('projection gone');};
|
||
c.renewYibaoCaptureSession=()=>{renewals++;c.captureBackendState.recoveryUsed=true;return true;};
|
||
if(recovered)assert.equal(c.captureCurrentScreen().image,true);
|
||
else assert.throws(()=>c.captureCurrentScreen(),e=>e.captureBackendFatal===true);
|
||
assert.equal(renewals,1);assert.equal(calls,recovered?4:6);
|
||
}
|
||
});
|
||
|
||
test('锁屏时不申请截图恢复;解锁重建后返回原应用且不清栈', () => {
|
||
for(const locked of [true,false]) {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[0]);c.captureBackendState={};
|
||
c.android={content:{Context:{KEYGUARD_SERVICE:'keyguard'}}};
|
||
c.context={getSystemService:()=>({isKeyguardLocked:()=>locked})};
|
||
let requested=0,stopped=0,launched=0;
|
||
c.images={stopScreenCapture:()=>stopped++};c.requestCapturePermission=()=>{requested++;return true;};
|
||
c.getForegroundApp=()=>({packageName:'com.ss.android.ugc.live'});
|
||
c.app={launchPackage:pkg=>{assert.equal(pkg,'com.ss.android.ugc.live');launched++;return true;}};
|
||
assert.equal(c.renewYibaoCaptureSession(),!locked);
|
||
assert.equal(requested,locked?0:1);assert.equal(stopped,requested);assert.equal(launched,requested);
|
||
}
|
||
});
|
||
|
||
test('首页原生信息完整时直接读控件,不调用截图OCR', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[0]);
|
||
const items=['首页','秒玩','赚钱','商城','我的'].map((text,i)=>({text,enabled:true,centerX:100+i*200,centerY:2280,bounds:{left:20+i*200,top:2230,right:180+i*200,bottom:2340}}));
|
||
items.push({text:'热门软件',centerX:200,centerY:700,bounds:{left:50,top:660,right:350,bottom:740}});
|
||
c.readCommonInstallPage=()=>({packageName:c.CONFIG.yibaoPackage,items});
|
||
c.recognizeScreen=()=>{throw Error('完整原生首页不应截图');};
|
||
const result=c.recognizeScreenSafe();
|
||
assert.equal(result.some(i=>i.text==='赚钱'),true);
|
||
assert.equal(c.yibaoWorkflowState.recognition.nativeFrames,1);
|
||
});
|
||
|
||
test('只读到底栏或被广告覆盖不能视为完整任务正文,仍用OCR补充', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[0]);
|
||
const items=['首页','秒玩','赚钱','商城','我的'].map((text,i)=>({text,enabled:true,centerX:100+i*200,centerY:2280,bounds:{left:20+i*200,top:2230,right:180+i*200,bottom:2340}}));
|
||
const page={packageName:c.CONFIG.yibaoPackage,items};
|
||
assert.equal(c.nativeYibaoRecognition(page),null);
|
||
let calls=0;c.readCommonInstallPage=()=>page;c.recognizeScreen=()=>{calls++;return [{text:'任务中心'},{text:'每日福利签到'}];};
|
||
c.recognizeScreenSafe();assert.equal(calls,1);
|
||
items.push({text:'热门软件',bounds:{left:50,top:660,right:350,bottom:740},centerX:200,centerY:700});
|
||
items.push({text:'现在退出',bounds:{left:50,top:860,right:350,bottom:940},centerX:200,centerY:900});
|
||
assert.equal(c.nativeYibaoRecognition(page),null);
|
||
});
|
||
|
||
test('实机OCR看视频赚积枳分仍识别主视频入口,不混入快影任务', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);
|
||
const anchor={text:'看视频赚积枳分 兑豪礼',centerX:350,centerY:1293,bounds:{left:58,top:1250,right:660,bottom:1330}};
|
||
const button={text:'去观看',centerX:900,centerY:1329,bounds:{left:835,top:1295,right:965,bottom:1360}};
|
||
assert.equal(c.inspectWatchTaskAvailability([anchor,button]).state,'ready');
|
||
assert.equal(c.findWatchTaskAnchors([{...anchor,text:'去快影看视频赚积分'}]).length,0);
|
||
});
|
||
|
||
test('滑动无位移且未核对顶部到底部时不能宣告视频完成', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);c.CONFIG.scrollMaxScans=10;
|
||
const page=[{text:'特别任务赚积分',centerX:200,centerY:1000,bounds:{left:30,top:950,right:400,bottom:1050}}];
|
||
c.recognizeScreenSafe=()=>page;c.isYibaoTaskCenter=()=>true;c.swipe=()=>true;c.scrollPageUp=()=>true;c.sleepScan=()=>{};
|
||
c.failWithCapture=msg=>{throw Error(msg);};
|
||
assert.throws(()=>c.startNextWatchTask(),/未确认位移/);
|
||
});
|
||
|
||
test('惊喜视频0\/10与去观看合并时从右侧局部识别真实按钮', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const anchor={text:'看精彩视频领积分(0/10)去观看',centerX:600,centerY:594,bounds:{left:290,top:560,right:990,bottom:630}};
|
||
const button={text:'去观看',centerX:900,centerY:605,bounds:{left:840,top:575,right:965,bottom:635}};
|
||
c.recognizeYibaoTaskButtonRows=rows=>{assert.equal(rows[0],anchor);return [button];};
|
||
const result=c.supplementYibaoTaskButtons([anchor]);
|
||
assert.equal(result.length,2);assert.equal(result[1],button);
|
||
});
|
||
|
||
test('视频按钮仅禁用而无完成文字时不能算完成,冷却与完成分别记录', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);
|
||
const a={text:'看视频赚积分',centerX:350,centerY:1290,bounds:{left:58,top:1250,right:650,bottom:1330}};
|
||
const b={text:'去观看',enabled:false,centerX:900,centerY:1300,bounds:{left:835,top:1265,right:965,bottom:1335}};
|
||
assert.equal(c.inspectWatchTaskAvailability([a,b]).state,'unknown');
|
||
for(const [label,status] of [['00:30后再来','skipped'],['今日已达上限','success']]) {
|
||
c.recognizeScreenSafe=()=>[a,{...b,text:label}];c.isYibaoTaskCenter=()=>true;
|
||
assert.equal(c.startNextWatchTask().status,status);
|
||
}
|
||
});
|
||
|
||
test('视频和惊喜列表的下滑扫描使用左侧留白', () => {
|
||
const c=load();
|
||
for(const profile of [c.YIBAO_PROFILES[3],c.YIBAO_PROFILES[4]]) {
|
||
c.activateYibaoFlow(profile);let points;
|
||
c.logForegroundApp=()=>({});c.observeAfterAction=()=>{};
|
||
c.gesture=(duration,...p)=>{points=p;return true;};
|
||
assert.equal(c.scrollPageUp(1),true);assert.equal(points[0][0],108);assert.equal(points[2][0],108);
|
||
}
|
||
});
|
||
|
||
test('赚钱页整体识别同样兼容賺积分和赚积枳分', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);
|
||
for(const text of ['看视频賺积分兑豪礼','看视频赚积枳分兑豪礼']) {
|
||
assert.equal(c.isYibaoTaskCenter([{text:'任务中心'},{text}]),true);
|
||
}
|
||
});
|
||
|
||
test('点击后看秒数字漏读仍识别浏览奖励,孤立去浏览不触发', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);
|
||
const button={text:'去浏览',centerX:540,centerY:2062,bounds:{left:456,top:2036,right:625,bottom:2088}};
|
||
for(const prompt of ['点击后看秒,多得20积分','点击后看15秒,多得20积分','点击后看5秒,多得20积枳分','点击后看xx秒,可获得奖励']) {
|
||
const items=[{text:prompt},{text:'广告'},button];
|
||
assert.equal(c.isAdView1BrowseOffer(items),true);assert.equal(c.findAdView1BrowseOfferButton(items).item,button);
|
||
assert.ok(c.adView1BrowseOfferWaitMs(items)>=20000);
|
||
}
|
||
assert.equal(c.isAdView1BrowseOffer([button,{text:'广告'}]),false);
|
||
});
|
||
|
||
test('浏览按钮通过同位置原生控件复核,不接受其他位置的同名按钮', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);
|
||
const item={text:'去浏览',centerX:540,centerY:2062,bounds:{left:456,top:2036,right:625,bottom:2088}};
|
||
c.readCommonInstallPage=()=>({packageName:c.CONFIG.yibaoPackage,items:[item]});
|
||
assert.equal(c.nativeAdView1BrowseOfferButton({item}).item,item);
|
||
c.readCommonInstallPage=()=>({packageName:c.CONFIG.yibaoPackage,items:[{...item,centerY:1000}]});
|
||
assert.equal(c.nativeAdView1BrowseOfferButton({item}),null);
|
||
});
|
||
|
||
test('浏览按钮确认超时属于流程失败,不设置整组中断标记', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);let now=0;
|
||
c.Date=class extends Date{static now(){return now;}};c.sleep=ms=>{now+=ms;};
|
||
const items=[{text:'广告'},{text:'点击后看秒,多得20积分'},{text:'去浏览'}];
|
||
c.recognizeScreenSafe=()=>items;c.getForegroundApp=()=>({packageName:c.CONFIG.yibaoPackage});
|
||
assert.throws(()=>c.handleAdView1BrowseOffer(items),e=>/浏览按钮未稳定/.test(e.message) && !e.taskInterrupted);
|
||
assert.ok(now>=30000);
|
||
});
|
||
|
||
test('横向投影画布中的居中竖屏内容映射回手机按钮坐标', () => {
|
||
const c=load();const a=c.yibaoCaptureGeometry(2400,1080,1080,2400);
|
||
assert.equal(a.left,957);assert.equal(a.top,0);assert.equal(a.width,486);assert.equal(a.height,1080);
|
||
assert.ok(Math.abs((1163-a.left)*1080/a.width-456)<3);
|
||
assert.ok(Math.abs(916*2400/a.height-2036)<3);
|
||
});
|
||
|
||
test('投影图像对齐后返回独立图像,释放原图和临时裁图;原尺寸不重复处理', () => {
|
||
const c=load();c.captureBackendState={};const calls=[];
|
||
const input={getWidth:()=>2400,getHeight:()=>1080,recycle:()=>calls.push('input')};
|
||
const crop={recycle:()=>calls.push('crop')},output={};
|
||
c.images={clip:(im,x,y,w,h)=>{assert.equal(im,input);assert.deepEqual([x,y,w,h],[957,0,486,1080]);return crop;},
|
||
resize:(im,size)=>{assert.equal(im,crop);assert.deepEqual(Array.from(size),[1080,2400]);return output;}};
|
||
assert.equal(c.alignYibaoCaptureFrame(input),output);assert.deepEqual(calls,['crop','input']);
|
||
const normal={getWidth:()=>1080,getHeight:()=>2400};assert.equal(c.alignYibaoCaptureFrame(normal),normal);
|
||
});
|
||
|
||
test('惊喜任务右侧残缺文字只在已知任务行中还原动作', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
assert.equal(c.yibaoTaskColumnAction('10)去看','去观看'),'去观看');
|
||
assert.equal(c.yibaoTaskColumnAction('取福桂下载','去下载'),'去下载');
|
||
assert.equal(c.yibaoTaskColumnAction('刘览','去浏览'),'去浏览');
|
||
assert.equal(c.yibaoTaskColumnAction('去漬理','去清理'),'去清理');
|
||
assert.equal(c.yibaoTaskColumnAction('取福桂下载','去观看'),'');
|
||
});
|
||
|
||
test('列表局部识别单帧耗时超过20秒时仍可完成两帧确认', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);let now=0,frames=0;
|
||
c.Date=class extends Date{static now(){return now;}};c.sleep=ms=>{now+=ms;};
|
||
c.recognizeScreenSafe=()=>{now+=21000;frames++;return [];};c.isAdView3List=()=>true;
|
||
c.makeAdView3Snapshot=()=>({actions:[],ignored:[],claimed:[],hasBottomFeedback:false,hasExecutableTasks:false});
|
||
c.sameAdView3Scan=()=>true;
|
||
assert.ok(c.scanAdView3Page());assert.equal(frames,2);
|
||
});
|
||
|
||
test('存储授权严格核对应用宝身份,不授权其他应用或其他权限', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const sw={text:'',className:'android.widget.Switch',enabled:true,checked:false};
|
||
const page={packageName:'com.android.settings',items:[{text:'应用宝'},{text:'允许管理所有文件'},sw]};
|
||
assert.equal(c.planCleanupStoragePermission(page,'应用宝').kind,'allow');
|
||
sw.checked=true;assert.equal(c.planCleanupStoragePermission(page,'应用宝').kind,'granted');
|
||
page.items[0].text='其他应用';assert.equal(c.planCleanupStoragePermission(page,'应用宝'),null);
|
||
page.items=[{text:'应用宝'},{text:'位置信息'},{text:'允许',enabled:true}];
|
||
assert.equal(c.planCleanupStoragePermission(page,'应用宝'),null);
|
||
});
|
||
|
||
test('单行普通失败后继续其他惊喜任务,并在最后保留未完成记录', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);let browsed=false;
|
||
const watch={target:'去观看',item:{text:'去观看',centerX:900,centerY:400}},browse={target:'去浏览',item:{text:'去浏览',centerX:900,centerY:800}};
|
||
c.scanAdView3Page=()=>({actions:browsed?[watch]:[watch,browse],ignored:[],claimed:[],elements:[],items:[],hasBottomFeedback:browsed,hasExecutableTasks:true});
|
||
c.adView3TaskKey=match=>match.target;c.clickOcrMatch=()=>{};
|
||
c.runMainTaskTail=()=>{throw Error('本行广告未完成');};c.runAdView3BrowseTask=()=>{browsed=true;};
|
||
c.restoreAdView3List=()=>{};c.rewindAdView3Page=()=>{};c.sameAdView3Page=()=>false;c.scrollPageUp=()=>true;c.sleepScan=()=>{};
|
||
const result=c.runAdView3Tasks();assert.equal(browsed,true);assert.equal(result.status,'failed');
|
||
assert.match(result.remainingTasks['去观看'],/本行广告未完成/);
|
||
});
|
||
|
||
test('运行中异常熄屏会唤亮,只临时禁用无密码锁屏,退出恢复', () => {
|
||
for(const secure of [false,true]) {
|
||
const c=load(),calls=[];
|
||
c.context={getSystemService:()=>({isKeyguardSecure:()=>secure,newKeyguardLock:()=>({disableKeyguard:()=>calls.push('disable'),reenableKeyguard:()=>calls.push('restore')})})};
|
||
c.android={content:{Context:{KEYGUARD_SERVICE:'keyguard'}}};
|
||
c.device.isScreenOn=()=>false;c.device.wakeUp=()=>calls.push('wake');
|
||
c.yibaoScreenAwakeKeeper={keep:()=>calls.push('keep'),release:()=>calls.push('release')};
|
||
c.maintainYibaoScreenAwake();c.stopYibaoScreenAwake();
|
||
assert.deepEqual(calls,secure?['wake','keep','release']:['disable','wake','keep','release','restore']);
|
||
}
|
||
});
|
||
|
||
test('精彩视频按页面实际总次数判断完成,完成后同名按钮不再重复点', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const button={text:'去观看',centerX:930,centerY:420,bounds:{left:865,top:390,right:995,bottom:450}};
|
||
for(const [progress,done] of [['1/10',false],['10/10',true],['11/12',false],['12/12',true]]) {
|
||
const row={text:'看精彩视频领积分('+progress+')去观看',centerX:620,centerY:400,bounds:{left:280,top:370,right:995,bottom:430}};
|
||
assert.equal(!!c.completedAdView3VideoButton(button,[row,button]),done);
|
||
assert.equal(c.adView3Buttons([row,button],null).length,done?0:1);
|
||
}
|
||
});
|
||
|
||
test('广告页单独有去浏览或去观看不能冒充惊喜列表', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const item={text:'去浏览',centerX:900,centerY:1200,bounds:{left:835,top:1170,right:965,bottom:1230}};
|
||
assert.equal(c.isAdView3List([item,{text:'点击后看15秒可获得奖励'}]),false);
|
||
assert.equal(c.isAdView3List([item]),false);
|
||
});
|
||
|
||
test('vivo照片与音视频存储授权文案可自动允许', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const page={packageName:'com.android.permissioncontroller',items:[{text:'“应用宝”请求访问您的照片与音视频'},
|
||
{text:'允许',enabled:true},{text:'禁止',enabled:true}]};
|
||
assert.equal(c.planCleanupStoragePermission(page,'应用宝').kind,'allow');
|
||
});
|
||
|
||
test('去浏览可识别同包内嵌淘宝登录页,只浏览不等待第三方包名', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
assert.equal(c.isAdView3InternalBrowsePage([{text:'淘宝 登录'},{text:'请重新登录'},{text:'隐私政策'}]),true);
|
||
assert.equal(c.isAdView3InternalBrowsePage([{text:'淘宝'},{text:'点击后看15秒可获得奖励'}]),false);
|
||
});
|
||
|
||
test('领取后同一清理任务行已领取则完成领奖,不误当下载任务', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const title={text:'每日完成手机垃圾清理',centerX:500,centerY:1300},button={text:'领积分',centerX:930,centerY:1320};
|
||
const context={choice:{item:button},items:[title,button]};
|
||
assert.equal(c.adView3ClaimApplied(context,[title,{...button,text:'已领取'}]),true);
|
||
assert.equal(c.adView3ClaimApplied(context,[title,button]),false);
|
||
});
|
||
|
||
test('每日下载推荐页只选热门软件区的下载目标,排除游戏和预约', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const page={packageName:c.CONFIG.yibaoPackage,items:[
|
||
{text:'热门软件',centerX:150,centerY:740},{text:'元宝-腾讯旗下AI助手',centerX:172,centerY:1092},
|
||
{text:'下载',enabled:true,resourceId:c.CONFIG.yibaoPackage+':id/wt',centerX:172,centerY:1198},
|
||
{text:'热门游戏',centerX:150,centerY:1363},{text:'预约',centerX:172,centerY:1810}
|
||
]};
|
||
assert.equal(c.findAdView3CatalogSoftware(page).target,'元宝-腾讯旗下AI助手');
|
||
page.items[2].text='打开';assert.equal(c.findAdView3CatalogSoftware(page),null);
|
||
});
|
||
|
||
test('推荐流详情下载条可位于77%高度,必须同时匹配应用名、原生ID及宽按钮', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const button={text:'下载',resourceId:c.CONFIG.yibaoPackage+':id/wt',enabled:true,centerY:1938,bounds:{left:58,top:1852,right:1023,bottom:2025}};
|
||
const page={packageName:c.CONFIG.yibaoPackage,items:[{text:'元宝-腾讯旗下AI助手'},button]};
|
||
assert.equal(c.adView3CatalogDetailButtons(page,{name:'元宝-腾讯旗下AI助手'}).length,1);
|
||
assert.equal(c.adView3CatalogDetailButtons(page,{name:'其他软件'}).length,0);
|
||
page.items.push({...button,bounds:{left:58,top:1800,right:220,bottom:1900}});
|
||
assert.equal(c.adView3CatalogDetailButtons(page,{name:'元宝-腾讯旗下AI助手'}).length,1);
|
||
page.items.push({...button});
|
||
assert.equal(c.adView3CatalogDetailButtons(page,{name:'元宝-腾讯旗下AI助手'}).length,0);
|
||
});
|
||
|
||
test('回查到顶部以三个业务锚点确认,不被动态横幅OCR拖住,也不当作惊喜已完成', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[4]);
|
||
const items=[{text:'吃饭补贴积分'},{text:'限时应用专区 大额奖励'},{text:'看视频赚积分 兑豪礼'}];
|
||
assert.equal(c.adView3MainTopSeen(items),true);
|
||
assert.equal(c.adView3MainTopSeen(items.slice(1)),false);
|
||
assert.equal(c.adView3MainTopSeen(items.concat({text:'任务未完成'})),false);
|
||
});
|
||
|
||
test('微信入口兼容不同按钮文案,排除上方试玩说明、禁用和越界候选', () => {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);
|
||
const button={text:'去微信畅玩小游戏',centerX:540,centerY:1414,bounds:{left:288,top:1382,right:792,bottom:1446}};
|
||
for(const text of ['去微信畅玩小游戏','去微信观看全集','点击去微信浏览','去微信']) {
|
||
const items=[{...button,text},{text:'去微信玩15秒小游戏即可获得奖励'}];
|
||
assert.equal(c.isAdView1BrowseOffer(items),true);
|
||
assert.equal(c.findAdView1BrowseOfferButton(items).target,'去微信');
|
||
}
|
||
assert.equal(c.isYibaoWechatBrowseText('去微信玩15秒小游戏即可获得奖励'),false);
|
||
assert.equal(c.findYibaoWechatBrowseButton([{...button,enabled:false}]),null);
|
||
assert.equal(c.findYibaoWechatBrowseButton([{...button,bounds:{...button.bounds,right:1300}}]),null);
|
||
});
|
||
|
||
test('五流程微信入口均走微信前台浏览,返回常驻CTA不重复打开', () => {
|
||
const button={text:'去微信畅玩小游戏',centerX:540,centerY:1414,bounds:{left:288,top:1382,right:792,bottom:1446}};
|
||
for(let i=0;i<5;i++) {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[i]);let now=0,clicked=0,browsed=0;
|
||
c.Date=class extends Date{static now(){return now;}};c.sleep=ms=>{now+=ms;};
|
||
const items=[{text:'打开试玩15秒可得奖励'},button];
|
||
c.recognizeScreenSafe=()=>items;c.nativeAdView1BrowseOfferButton=()=>null;c.getForegroundApp=()=>({packageName:c.CONFIG.yibaoPackage});
|
||
c.clickOcrMatch=()=>clicked++;
|
||
c.browseThirdPartyThenReturn=(ms,options)=>{browsed++;assert.ok(ms>=20000);assert.equal(options.expectedPackage,'com.tencent.mm');return true;};
|
||
assert.equal(c.handleAdView1BrowseOffer(items,false),true);
|
||
assert.equal(clicked,1);assert.equal(browsed,1);assert.equal(c.yibaoWechatBrowseBusy,false);
|
||
}
|
||
});
|
||
|
||
test('微信浏览须等微信实际前台,其他应用及应用宝页面不能充当微信', () => {
|
||
for(const opens of [false,true]) {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[3]);let now=0,returned=0;
|
||
c.Date=class extends Date{static now(){return now;}};c.sleep=ms=>{now+=ms;};
|
||
c.getForegroundApp=()=>({packageName:opens&&now>=2000?'com.tencent.mm':'com.other.app'});
|
||
c.isInstallerForeground=()=>false;c.backToYibao=()=>{returned++;assert.ok(now>=22000);return true;};
|
||
assert.equal(c.browseThirdPartyThenReturn(20000,{expectedPackage:'com.tencent.mm'}),opens);
|
||
assert.equal(returned,opens?1:0);
|
||
}
|
||
});
|
||
|
||
test('五个任务入口遇到残留微信弹窗先浏览,再重置导航等待预算', () => {
|
||
for(let i=0;i<5;i++) {
|
||
const c=load();c.activateYibaoFlow(c.YIBAO_PROFILES[i]);let now=0,handled=0;
|
||
const button={text:'去微信畅玩小游戏',centerX:540,centerY:1414,bounds:{left:288,top:1382,right:792,bottom:1446}};
|
||
c.Date=class extends Date{static now(){return now;}};c.sleep=ms=>{now+=ms;};
|
||
c.recognizeScreenSafe=()=>handled?[{text:'任务中心'}]:[button];
|
||
c.getForegroundApp=()=>({packageName:c.CONFIG.yibaoPackage});
|
||
c.handleAdView1BrowseOffer=()=>{handled++;now+=90000;return true;};
|
||
c.isYibaoTaskCenter=items=>items.some(item=>item.text==='任务中心');
|
||
assert.equal(c.enterYibaoTaskCenter(),true);assert.equal(handled,1);
|
||
}
|
||
});
|