288 lines
12 KiB
Lua
288 lines
12 KiB
Lua
-- Drive the selected Character Select, Account Login, realm picker and GlueParent.
|
|
-- Inputs are read-only Lua files. Engine calls use local synthetic state.
|
|
local selected = assert(arg[1], "selected FrameXML directory required")
|
|
local glue = assert(arg[2], "GlueParent file under test required")
|
|
local function noop() end
|
|
local function no() return false end
|
|
-- Unrelated FrameXML mixins and render-only APIs are out of scope in this fixture.
|
|
local inert = setmetatable({}, {__call=noop})
|
|
getmetatable(inert).__index = function() return inert end
|
|
setmetatable(_G, {__index=function() return inert end})
|
|
function CreateFromMixins() return {} end
|
|
local polls = {}
|
|
function CreateFrame()
|
|
return {SetScript=function(_, event, fn)
|
|
if event == "OnUpdate" then polls[#polls+1] = fn end
|
|
end}
|
|
end
|
|
|
|
local function widget()
|
|
local w = {text = "", shown = true}
|
|
function w:SetText(value) self.text = value end
|
|
function w:GetText() return self.text end
|
|
function w:SetShown(value) self.shown = value end
|
|
function w:Hide() self:SetShown(false) end
|
|
function w:IsShown() return self.shown end
|
|
function w:SetEnabled(value) self.enabled = value end
|
|
return setmetatable(w,{__index=function() return noop end})
|
|
end
|
|
|
|
local time, generation, disconnects = 10, 0, 0
|
|
local connected, accountReady = false, true
|
|
local snapshot, requests = nil, {}
|
|
local cancels = 0
|
|
local accountBox, passwordBox = widget(), widget()
|
|
local expectedAccount, expectedPassword = "ACCOUNT_TEST", "PASSWORD_TEST"
|
|
local switch = (arg[3] or ""):match("^switch") ~= nil
|
|
local submissions, roster = {}, {}
|
|
local activeDialog, dialogText, onHide
|
|
local networkState = 0
|
|
local function pending(loginGeneration)
|
|
return {
|
|
abi = 1, size = 64, generation = loginGeneration, endpoint_kind = 1,
|
|
state = 5, error = 0, auth_result = 0, discovery_result = 0,
|
|
server_proof_verified = 1, realm_count = 1, selected_index = -1,
|
|
transport_prepared = 0, cancel = 0, genuine_discovery = 1,
|
|
auth_port = 3724, copied_realms = 1,
|
|
r0 = {
|
|
name = "Fixture " .. tostring(loginGeneration), address = "127.0.0.1:8085", type = 1, flags = 0,
|
|
characters = 1, category = 1, wire_id = 1, population_text = "0.5",
|
|
},
|
|
}
|
|
end
|
|
LE_AURORA_STATE_NONE, LE_AURORA_STATE_CONNECTING = 0, 2
|
|
GetTime=function() return time end
|
|
C_Login={
|
|
GetSubRegions=function() return {}; end,
|
|
GetState=function()
|
|
return {connectedToWoW=connected,auroraState=networkState,hasSelectedExperiencePreset=true}
|
|
end,
|
|
GetTurtleRealmSnapshot=function(query)
|
|
if query == 4 then
|
|
assert(snapshot and snapshot.state == 5, "only a pending login may be cancelled")
|
|
cancels = cancels + 1
|
|
snapshot.state, snapshot.cancel = 3, 1
|
|
return 0
|
|
end
|
|
return snapshot or -1
|
|
end,
|
|
DisconnectFromServer=function()
|
|
disconnects=disconnects+1
|
|
connected,accountReady=false,true
|
|
networkState = LE_AURORA_STATE_NONE
|
|
-- The selected snapshot outlives the native disconnect.
|
|
end,
|
|
Login=function(account,passwordWidget)
|
|
assert(accountReady and not connected and account==expectedAccount)
|
|
assert(passwordWidget==passwordBox and passwordWidget:GetText()==expectedPassword)
|
|
submissions[#submissions+1] = account
|
|
generation=generation+1
|
|
snapshot=pending(generation)
|
|
accountReady=false
|
|
networkState = LE_AURORA_STATE_CONNECTING
|
|
end,
|
|
RequestTurtleRealm=function(index,g)
|
|
assert(index==0 and g==generation and snapshot.state==5)
|
|
requests[#requests+1]=g
|
|
snapshot.state,snapshot.selected_index,snapshot.transport_prepared=2,index,1
|
|
return 0
|
|
end,
|
|
IsLoginReady=function() return accountReady end,
|
|
GetLastError=noop, GetLogonQueueInfo=no, ClearLastError=noop, IsLauncherLogin=no, IsReconnectLoginPossible=no,
|
|
}
|
|
KoreanRatings = {TryShow = no}
|
|
ChinaAgeAppropriatenessWarning = KoreanRatings
|
|
TaiwanFraudWarning = KoreanRatings
|
|
GetSavedAccountName=function() return "" end
|
|
GetSavedAccountList=GetSavedAccountName
|
|
IsKioskGlueEnabled=no
|
|
C_GameRules={GetGameModeGlueScreenName=noop}
|
|
StaticPopup_Show=function(which, message, _, _, _, callback)
|
|
assert(switch, "Unexpected popup "..tostring(which))
|
|
activeDialog, dialogText, onHide = which, message, callback
|
|
end
|
|
StaticPopup_Hide=function(which)
|
|
if activeDialog == which then activeDialog, dialogText, onHide = nil, nil, nil end
|
|
end
|
|
StaticPopup_HideAllExcept=function() activeDialog, dialogText, onHide = nil, nil, nil end
|
|
GlueParent={currentScreen="login"}
|
|
assert(loadfile(glue))()
|
|
assert(#polls>0, "GlueParent polling is installed")
|
|
local poll=polls[#polls]
|
|
assert(loadfile(selected.."/accountlogin.lua"))()
|
|
assert(loadfile(selected.."/characterselect.lua"))()
|
|
assert(loadfile(selected.."/superdistrict.lua"))()
|
|
-- The poll calls these entry points to request a redraw. Sample the actual
|
|
-- routing and screen validity directly below; this test has no display.
|
|
GlueParent_EnsureValidScreen=noop
|
|
if not switch then GlueParent_UpdateDialogs=noop end
|
|
|
|
local loginButton, reconnect, save, dropdown = widget(), widget(), widget(), widget()
|
|
AccountLogin={UI={AccountEditBox=accountBox,PasswordEditBox=passwordBox,
|
|
NormalLoginRegions={},ManualLoginRegions={accountBox,passwordBox,loginButton},
|
|
ReconnectLoginRegions={reconnect}, SaveAccountNameCheckButton=save,AccountsDropdown=dropdown}}
|
|
save.IsControlChecked=no
|
|
local picker=setmetatable({Title=widget(),Description=widget(),SelectButton=widget(),
|
|
districtButtons = {}, ButtonLayout = widget(), SubRegionDropdown = widget(), districtButtonPool = {
|
|
ReleaseAll=noop,Acquire=function()
|
|
local b=widget()
|
|
b.Title,b.Description,b.Icon=widget(),widget(),widget()
|
|
return b
|
|
end
|
|
}},{__index=SuperDistrictMixin})
|
|
|
|
local function screen(expected)
|
|
time=time+1
|
|
poll(nil,1)
|
|
local actual=GlueParent_GetBestScreen()
|
|
assert(actual==expected, "Expected "..expected..", got "..tostring(actual))
|
|
if expected=="login" then assert(GlueParent_IsScreenValid("login")) end
|
|
GlueParent.currentScreen=actual
|
|
end
|
|
|
|
local function signIn(afterSubmit)
|
|
AccountLogin_Update()
|
|
assert(loginButton.shown and accountBox.shown and passwordBox.shown and not reconnect.shown)
|
|
accountBox:SetText(expectedAccount)
|
|
passwordBox:SetText(expectedPassword)
|
|
AccountLogin_OnEnterPressed()
|
|
assert(passwordBox:GetText()=="", "The selected login page must clear its password field")
|
|
if afterSubmit then afterSubmit() else screen("superdistrict") end
|
|
end
|
|
|
|
local function selectRealm()
|
|
picker:RefreshSuperDistrictButtons()
|
|
assert(#picker.districtButtons==1)
|
|
picker:UpdateSelection(picker.districtButtons[1].superDistrictID)
|
|
assert(picker.SelectButton.enabled)
|
|
picker:ConfirmSuperDistrict()
|
|
assert(snapshot.state==2 and snapshot.transport_prepared==1)
|
|
screen("superdistrict")
|
|
connected=true
|
|
networkState = LE_AURORA_STATE_NONE
|
|
screen("charselect")
|
|
roster[#roster+1] = generation
|
|
end
|
|
|
|
local xml = assert(io.open(selected.."/accountlogin.xml", "rb"))
|
|
local bindings = xml:read("*a")
|
|
xml:close()
|
|
assert(bindings:find('<OnEnterPressed function="AccountLogin_OnEnterPressed"/>', 1, true))
|
|
assert(bindings:find('<OnClick function="AccountLogin_Login"/>', 1, true))
|
|
|
|
screen("login")
|
|
signIn()
|
|
if arg[3] == "cancel" then
|
|
picker:RefreshSuperDistrictButtons()
|
|
picker:OnCancel()
|
|
screen("login")
|
|
assert(cancels == 1 and disconnects == 1 and #requests == 0)
|
|
signIn()
|
|
selectRealm()
|
|
assert(generation == 2 and #requests == 1 and requests[1] == 2)
|
|
print("PASS intentional realm-picker Cancel, return to Account and same-account retry")
|
|
return
|
|
end
|
|
selectRealm()
|
|
if arg[3]=="switch-active-first-failure" or arg[3]=="switch-delayed-active-failure" then
|
|
-- A genuine terminal for A, while its roster is still active and before
|
|
-- any account Back, must still perform the normal cleanup and show an error.
|
|
if arg[3]=="switch-delayed-active-failure" then
|
|
connected=false
|
|
screen("login")
|
|
end
|
|
snapshot.state, snapshot.error, snapshot.auth_result = 3, 1, -2
|
|
connected = false
|
|
screen("login")
|
|
assert(activeDialog=="OKAY" and disconnects==1 and #submissions==1 and type(onHide)=="function")
|
|
print("PASS genuine current-account terminal before Back remains visible")
|
|
return
|
|
end
|
|
local firstSelected = snapshot
|
|
if arg[3] == "switch-back-gap" then snapshot = nil end
|
|
CharacterSelectBackButtonMixin:OnClick()
|
|
assert(disconnects==1 and not connected)
|
|
screen("login")
|
|
if switch then
|
|
expectedAccount, expectedPassword = "SECOND_TEST", "SECOND_PASSWORD_TEST"
|
|
local oldFailure = pending(1)
|
|
oldFailure.state, oldFailure.error, oldFailure.auth_result = 3, 1, -2
|
|
if arg[3] == "switch-late-before-snapshot" or arg[3] == "switch-back-gap" then
|
|
-- A backend that has not published B's generation yet can still return
|
|
-- A's terminal header after the form submitted B.
|
|
signIn(function()
|
|
snapshot = oldFailure
|
|
screen("login")
|
|
assert(disconnects==1 and not accountReady and activeDialog~="OKAY",
|
|
"Retired A's late failure disconnected or interrupted B before B published")
|
|
snapshot = pending(generation)
|
|
screen("superdistrict")
|
|
end)
|
|
else
|
|
signIn(function()
|
|
local current = snapshot
|
|
snapshot = pending(generation)
|
|
snapshot.state, snapshot.realm_count, snapshot.copied_realms = 1, 0, 0
|
|
snapshot.server_proof_verified, snapshot.genuine_discovery = 0, 0
|
|
screen("login")
|
|
GlueParent_UpdateDialogs()
|
|
assert(activeDialog=="CANCEL", "In-progress B should display the ordinary connection dialog")
|
|
snapshot = oldFailure
|
|
screen("login")
|
|
GlueParent_UpdateDialogs()
|
|
assert(disconnects==1 and activeDialog=="CANCEL", "A's delayed failure interrupted the new account")
|
|
snapshot = current
|
|
screen("superdistrict")
|
|
assert(activeDialog~="CANCEL")
|
|
end)
|
|
end
|
|
local current = snapshot
|
|
picker:RefreshSuperDistrictButtons()
|
|
assert(picker.districtButtons[1].Title:GetText()=="Fixture 2")
|
|
if arg[3] == "switch-failure" then
|
|
current.state, current.error, current.auth_result = 3, 1, -2
|
|
screen("login")
|
|
assert(disconnects==2 and activeDialog=="OKAY" and type(onHide)=="function")
|
|
local acknowledge=onHide
|
|
StaticPopup_Hide("OKAY")
|
|
acknowledge()
|
|
screen("login")
|
|
assert(accountReady and #submissions==2 and #requests==1 and not activeDialog)
|
|
signIn()
|
|
elseif arg[3] == "switch-cancel" then
|
|
picker:OnCancel()
|
|
screen("login")
|
|
assert(cancels==1 and disconnects==2 and accountReady and #submissions==2 and #requests==1)
|
|
signIn()
|
|
else
|
|
-- A user clicking B's visible card while a late A snapshot is returned
|
|
-- must not forward that cached realm to the current backend.
|
|
picker:UpdateSelection(picker.districtButtons[1].superDistrictID)
|
|
snapshot = firstSelected
|
|
picker:ConfirmSuperDistrict()
|
|
assert(activeDialog=="OKAY" and dialogText:find("selection%-stale") and #requests==1)
|
|
StaticPopup_Hide("OKAY")
|
|
snapshot = current
|
|
end
|
|
local expectedCount = (arg[3]=="switch-failure" or arg[3]=="switch-cancel") and 3 or 2
|
|
selectRealm()
|
|
assert(#submissions==expectedCount and submissions[1]=="ACCOUNT_TEST" and submissions[2]=="SECOND_TEST")
|
|
if expectedCount==3 then assert(submissions[3]=="SECOND_TEST") end
|
|
assert(#requests==2 and requests[1]==1 and requests[2]==expectedCount)
|
|
assert(#roster==2 and roster[1]==1 and roster[2]==expectedCount)
|
|
print("PASS "..arg[3].." with selected Account Login, realm picker, Character Select Back and source dialogs")
|
|
print("#submissions="..#submissions..", admitted generations=1,"..requests[2]..", two roster states")
|
|
return
|
|
end
|
|
signIn()
|
|
local secondPending = snapshot
|
|
snapshot = firstSelected
|
|
screen("superdistrict")
|
|
assert(not connected and generation==2)
|
|
snapshot = secondPending
|
|
selectRealm()
|
|
assert(generation==2 and disconnects==1)
|
|
assert(#requests==2 and requests[1]==1 and requests[2]==2 and cancels==0)
|
|
print("PASS same account twice through selected account submit, realm selection, Character Select Back and candidate Glue routing")
|
|
print("2 synthetic sign-ins, 1 Back, 2 realm requests and 2 character-select states in the same Lua instance")
|