Files
WoW-Hybrid-gateway/tests/remember_password_test.lua

99 lines
7.8 KiB
Lua

local path=assert(arg[1])
local frames,notes,timers={}, {}, {}
local function widget(kind)
local w={kind=kind,scripts={},shown=true,enabled=true,text=''};frames[#frames+1]=w
function w:SetScript(k,v)self.scripts[k]=v end
function w:GetScript(k)return self.scripts[k]end
function w:HookScript(k,v)local old=self.scripts[k];self.scripts[k]=function(...)if old then old(...)end;v(...)end end
function w:SetText(t)self.text=t end
function w:GetText()return self.text end
function w:SetEnabled(v)self.enabled=v end
function w:SetPassword(v)self.masked=v end
function w:Show()self.shown=true end
function w:Hide()self.shown=false end
function w:SetShown(v)self.shown=v end
function w:IsShown()return self.shown end
function w:SetPoint(_,_,_,x,y)self.x=x;self.y=y end
function w:CreateFontString()return widget('FontString')end
function w:RegisterEvent(e)self.events=self.events or {};self.events[e]=true end
function w:Click()if self.enabled and self.shown and self.scripts.OnClick then self.scripts.OnClick(self)end end
for _,n in ipairs({'SetSize','SetNormalFontObject','SetHighlightFontObject','SetFontObject','SetAutoFocus','SetMaxLetters','SetFocus'})do w[n]=function()end end
return w
end
function CreateFrame(kind,_,parent,template)
assert(template==nil or template=='GlueButtonBigTemplate' or template=='AccountLoginBackdropTemplate')
local w=widget(kind);w.parent=parent;return w
end
function StaticPopup_Show(_,text)notes[#notes+1]=text end
local time=10
function GetTime()return time end
C_Timer={After=function(_,fn)timers[#timers+1]=fn end}
local function drain()local q=timers;timers={};for _,fn in ipairs(q)do fn()end end
local function emit(e)for _,f in ipairs(frames)do if f.events and f.events[e] then f.scripts.OnEvent(f,e)end end;drain()end
function hooksecurefunc(t,name,fn)if type(t)~='table' then t,name,fn=_G,t,name end;local original=t[name];t[name]=function(...)local r=original(...);fn(...);return r end end
local function record(a,p,l,c,i)return string.char(#a,#p,#l,#c,i%256,math.floor(i/256))..a..p..l..c end
local stored='GWC2'..string.char(2,0)..record('FIRST','synthetic-one','Main','Hero',1)..record('SECOND','synthetic-two','','Other',2)
local reading,staging,expected
C_Login={GetTurtleRealmSnapshot=function(op,row,chunk)
if op==16 then reading=stored;return stored and #stored or 0 end
if op==17 then if not reading then return -1 end;local a,b,c=reading:byte(row+1,row+3);return a+(b or 0)*256+(c or 0)*65536 end
if op==18 then assert(chunk==2);expected=row;staging='';return 0 end
if op==19 then assert(#staging==row);for _=1,math.min(3,expected-row)do staging=staging..string.char(chunk%256);chunk=math.floor(chunk/256)end;return 0 end
if op==20 then assert(#staging==expected);stored=staging;return 0 end
if op==21 then stored=nil;return 0 end
return -1
end}
C_Login.DisconnectFromServer=function()end
AccountLogin=widget('Frame');AccountLogin.UI={AccountEditBox=widget('EditBox'),PasswordEditBox=widget('EditBox'),LoginButton=widget('Button')}
CharacterSelect=widget('Frame');CharacterSelect.shown=false
local characters,order,current = {[101]='Hero',[202]='Other'}, {202,101}, 202
CharacterSelectUtil={GetCharacterInfoTable=function(id)return characters[id] and {characterName=characters[id]}end}
CharacterSelectListUtil={GetCharIDFromIndex=function(i)return order[i] or 0 end,GetIndexFromCharID=function(id)for i,v in ipairs(order)do if v==id then return i end end end}
function GetCharacterSelection()return current end
function GetNumCharacters()return #order end
function CharacterSelect_SelectCharacter(i,noCreate)assert(noCreate);current=order[i]end
local entries=0
function CharacterSelect_EnterWorld()entries=entries+1 end
function CharacterSelect_AllowedToEnterWorld()return true end
local api,gate,logins=nil,true,0
function AccountLogin_Login()if gate then assert(api.BeforeLogin(AccountLogin.UI.AccountEditBox:GetText(),AccountLogin.UI.PasswordEditBox));logins=logins+1 end end
AccountLogin.UI.LoginButton:SetScript('OnClick',AccountLogin_Login)
api=assert(loadfile(path))();api.Setup(AccountLogin)
local function button(text)
for _,f in ipairs(frames)do if f.kind=='Button' and f.text==text and f.shown then return f end end
error('button missing: '..text)
end
-- Account button logs in and stays at character select.
button('Main'):Click();assert(logins==1 and AccountLogin.UI.AccountEditBox.text=='FIRST')
CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==0)
-- Last-character button enters its named character even after the displayed order changed.
CharacterSelect.shown=false;api.Setup(AccountLogin);button('Hero'):Click();assert(logins==2)
CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==1 and current==101)
emit('CHARACTER_LIST_UPDATE');assert(entries==1)
-- The normal login button cancels saved-character auto-entry and remains at selection.
CharacterSelect.shown=false;api.Setup(AccountLogin);gate=false;button('Hero'):Click();gate=true
AccountLogin.UI.LoginButton:Click();CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==1)
current=202;CharacterSelect_EnterWorld();assert(entries==2)
-- Last played character was stored (button renamed), and the priority-gate delay preserves the click intent.
CharacterSelect.shown=false;api.Setup(AccountLogin);gate=false;button('Other'):Click();assert(logins==3)
gate=true;AccountLogin_Login();CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==3 and current==202)
-- Streamer mode hides labels and character names and masks account input; lock blocks edits, not login.
CharacterSelect.shown=false;api.Setup(AccountLogin);button('Streamer mode'):Click();assert(AccountLogin.UI.AccountEditBox.masked);assert(button('Account 1') and button('Last char'))
button('Lock'):Click();assert(not button('X').enabled and not button('Save typed account').enabled)
api.Setup(AccountLogin);assert(button('Unlock') and button('Show names'));button('Unlock'):Click();button('Show names'):Click();assert(not AccountLogin.UI.AccountEditBox.masked)
-- Rename label, reorder and remove independently of authentication.
button('Label'):Click();local edit
for _,f in ipairs(frames)do if f.kind=='EditBox' and f.parent and f.parent~=AccountLogin and f.shown then edit=f end end
assert(edit);edit:SetText('Renamed');button('Save label'):Click();assert(button('Renamed'))
button('Dn'):Click();assert(button('SECOND').y==-28);button('X'):Click();assert(not stored:find('synthetic-two',1,true))
-- Missing saved character does not fall back to a different character.
characters[202]=nil;CharacterSelect.shown=false;api.Setup(AccountLogin);button('Other'):Click();CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==3 and #notes>0)
-- Cancellation cancels automatic entry; typed login adds an account without a character button.
characters[202]='Other';CharacterSelect.shown=false;api.Setup(AccountLogin);button('Other'):Click();C_Login.DisconnectFromServer();CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==3)
CharacterSelect.shown=false;api.Setup(AccountLogin);AccountLogin.UI.AccountEditBox:SetText('THIRD');AccountLogin.UI.PasswordEditBox:SetText('synthetic-three');AccountLogin.UI.LoginButton:Click();CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==3 and stored:find('synthetic-three',1,true))
CharacterSelect.shown=false;api.Setup(AccountLogin);button('THIRD'):Click();CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==3)
current=101;CharacterSelect_EnterWorld();assert(entries==4)
CharacterSelect.shown=false;api.Setup(AccountLogin);current=202;button('Hero'):Click();CharacterSelect.shown=true;emit('CHARACTER_LIST_UPDATE');assert(entries==5 and current==101)
assert(not _G.ForeverRememberPassword and not _G.LoginManager)
print('PASS saved-account glue: account stops at selection, last-character button enters, normal login, delayed gate, cancel, lock, streamer, labels, reorder, removal and new account')