Files
ucvl-home-vision/android-display/tests/phone-preview/HomePanelChecks.java
T

58 lines
5.9 KiB
Java

package cn.ucvl.zhaodisplay;
import android.app.AlertDialog;
import android.os.Handler;
import android.view.*;
import android.widget.*;
/** Exercises production navigation and native power cards through isolated API responses. */
final class HomePanelChecks {
static Button button(View root,String text){if(root instanceof Button&&((Button)root).getText().toString().equals(text))return (Button)root;if(root instanceof ViewGroup){ViewGroup group=(ViewGroup)root;for(int i=0;i<group.getChildCount();i++){Button b=button(group.getChildAt(i),text);if(b!=null)return b;}}return null;}
static boolean text(View root,String value){if(root instanceof TextView&&((TextView)root).getText().toString().contains(value))return true;if(root instanceof ViewGroup){ViewGroup group=(ViewGroup)root;for(int i=0;i<group.getChildCount();i++)if(text(group.getChildAt(i),value))return true;}return false;}
static void later(Runnable action){new Handler().postDelayed(action,500);}
static void run(PhonePreviewActivity a,Runnable done){
a.selectTab(PhoneLayout.HOUSEHOLDS);
later(()->{
PhoneHomePanel panel=a.phoneHome;
if(a.mode.equals("devices-denied")){a.check(panel.devices.getChildCount()==0,"denied grant clears device cards");a.selectTab(PhoneLayout.DEVICES);later(()->{a.check(text(a.phone.pages[PhoneLayout.DEVICES],"授权"),"denied access is explicit");done.run();});return;}
a.check(text(panel.households,"演示家庭"),"paired household remains visible");
if(a.mode.equals("devices-empty")){a.check(panel.devices.getChildCount()==0,"pairing alone grants no devices");a.selectTab(PhoneLayout.DEVICES);later(()->{a.check(text(a.phone.pages[PhoneLayout.DEVICES],"管理员"),"empty grant tells user to contact administrator");done.run();});return;}
a.check(panel.households.getChildCount()==2,"only API-authorized households shown");
if(a.mode.startsWith("households")){done.run();return;}
button(panel.households,"查看设备").performClick();
later(()->{
a.check(a.phone.tab==PhoneLayout.DEVICES,"household selection opens device page");
a.check(panel.devices.getChildCount()==1&&text(panel.devices,"演示笔记本")&&!text(panel.devices,"演示工作电脑"),"family selection scopes visible devices");
a.check(text(panel.devices,"演示书房")&&text(panel.devices,"RUN")&&text(panel.devices,"OP")&&text(panel.devices,"检查时间")&&text(panel.devices,"最近结果"),"managed card exposes location and measured state details");
Button start=button(panel.devices,"开机"),stop=button(panel.devices,"关机");
a.check(!start.isEnabled(),"online device start disabled");
boolean blocked=a.mode.equals("devices-stale")||a.mode.equals("devices-unknown")||a.mode.equals("devices-pending")||a.mode.equals("devices-view-only");
a.check(stop.isEnabled()!=blocked,"shutdown follows freshness, pending OP and explicit grant");
if(a.mode.equals("devices-stale")||a.mode.equals("devices-unknown"))a.check(text(panel.devices,"未知"),"stale/unknown RUN never presented as online");
a.check(start.getHeight()>=a.style.dp(48)&&stop.getHeight()>=a.style.dp(48),"power controls preserve touch targets on narrow/large text views");
a.check(stop.getWidth()>a.style.dp(150),"stacked controls retain usable width");
if(a.mode.equals("devices-token")||a.mode.equals("devices-lifecycle")){
HomeFixture.release=false;HomeFixture.holdNextCatalog=true;panel.deviceRefresh.performClick();
later(()->{a.check(HomeFixture.held,"catalog response is delayed at the network boundary");
if(a.mode.equals("devices-token")){a.prefs.edit().putString("token","rebound-token").commit();panel.contextChanged();}else panel.active(false);
HomeFixture.release=true;later(()->{a.check(panel.devices.getChildCount()==0,"old identity/lifecycle callback cannot restore device grants");
if(a.mode.equals("devices-lifecycle")){panel.active(true);later(()->{a.check(panel.devices.getChildCount()==1,"resume reloads authorized current catalog");done.run();});}else done.run();
});
});return;
}
if(a.mode.equals("devices-revoked")){
HomeFixture.mode="devices-denied";panel.deviceRefresh.performClick();later(()->{a.check(panel.devices.getChildCount()==0&&text(a.phone.pages[PhoneLayout.DEVICES],"授权"),"revocation clears previously visible controls");done.run();});return;
}
if(a.mode.equals("devices-command")){
int before=HomeFixture.commands;stop.performClick();a.check(panel.confirmation!=null&&panel.confirmation.isShowing(),"shutdown has native confirmation");a.check(HomeFixture.commands==before,"opening confirmation never dispatches");panel.confirmation.getButton(AlertDialog.BUTTON_NEGATIVE).performClick();a.check(HomeFixture.commands==before,"cancel leaves machine untouched");stop.performClick();panel.confirmation.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
later(()->{a.check(HomeFixture.commands==before+1&&HomeFixture.lastCommand.optInt("op")==2,"confirmed shutdown dispatches exactly once");a.check(!button(panel.devices,"关机").isEnabled(),"pending command disables repeat");done.run();});return;
}
if(a.mode.equals("devices-offline")){
a.selectTab(PhoneLayout.HOUSEHOLDS);later(()->{button((ViewGroup)panel.households.getChildAt(1),"查看设备").performClick();later(()->{a.check(text(panel.devices,"RUN 0")&&button(panel.devices,"开机").isEnabled()&&!button(panel.devices,"关机").isEnabled(),"offline explicit control grant enables only start");done.run();});});return;
}
done.run();
});
});
}
}