Files
pfQuest/tests/native_chat_ownership.lua

80 lines
4.9 KiB
Lua

-- Load the actual compatibility files with missing legacy globals, without client actions.
local count=0
local function check(value,why) count=count+1;assert(value,why) end
local function frame()
return {Hide=function(self)self.hidden=true end,IsShown=function(self)return not self.hidden end,
RegisterEvent=function()end,SetScript=function(self,k,v)self[k]=v end,
UnregisterAllEvents=function()end,GetChildren=function()end}
end
local function scenario(bad_hook)
local g={}
setmetatable(g,{__index=_G})
g._G=g
g.CreateFrame=frame
g.StaticPopupDialogs={}
g.GetBuildInfo=function()return '1.60.1','70334','date',16001 end
g.GetCVar=function()return '0' end
g.GetPlayerFacing=function()return 0 end
g.Minimap=frame();g.NUM_CHAT_WINDOWS=2
local native_calls=0
local original=function(self,text,...) native_calls=native_calls+1;return text,... end
g.ChatFrame1={AddMessage=original};g.ChatFrame2={AddMessage=original}
g.C_ChatInfo={SendChatMessage=function()end}
local native_send=g.C_ChatInfo.SendChatMessage
g.ChatEdit_ParseText=function()end;local parse=g.ChatEdit_ParseText
g.QUIT_NOW='Quit';g.CANCEL='Cancel'
g.geterrorhandler=function()return function(err)error(err)end end
g.SetAbandonQuest=bad_hook and true or nil
local rejected_hook=0
g.hooksecurefunc=function(a,b)
local fn=type(a)=='table' and a[b] or g[a]
if type(fn)~='function' then rejected_hook=rejected_hook+1;error('not a function') end
end
g.C_QuestLog={}
g.C_Map={GetBestMapForUnit=function()return 1453 end,
GetMapInfo=function(id)
if id==1453 then return {mapID=id,parentMapID=1415,name='Stormwind City'} end
if id==1415 then return {mapID=id,parentMapID=947,name='Eastern Kingdoms'} end
end,
GetMapChildrenInfo=function(id)if id==1415 then return {{mapID=1453,name='Stormwind City'}} else return {} end end}
g.Enum={UIMapType={Zone=3}}
local function load(path)
local fn=assert(loadfile(path));setfenv(fn,g);fn()
end
load('compat/forever.lua')
local env=g.pfQuestEnv
check(type(env)=='table','compat environment created')
check(type(env.GetCurrentMapContinent)=='function','map continent provider initialized')
check(type(env.GetCurrentMapZone)=='function','map zone provider initialized')
check(env.GetCurrentMapContinent()==2 and env.GetCurrentMapZone()==1,'providers consume native map data')
check(env.QuestWatchFrame and not env.QuestWatchFrame:IsShown(),'private quest-watch frame initialized hidden')
check(g.QuestWatchFrame==nil and g.GetCurrentMapContinent==nil,'legacy names not published globally')
load('compat/client.lua')
check(g.ChatFrame1.AddMessage==original and g.ChatFrame2.AddMessage==original,'native chat AddMessage overwritten by compatibility layer')
check(g.ChatFrame1.pfQuestHookAddMessage==nil and g.ChatFrame2.pfQuestHookAddMessage==nil,'native frame contaminated with addon hook fields')
check(g.C_ChatInfo.SendChatMessage==native_send and g.ChatEdit_ParseText==parse,'native chat send/parser changed')
local opaque=setmetatable({}, {__tostring=function()error('opaque text interpreted')end})
check(g.ChatFrame1:AddMessage(opaque)==opaque,'opaque native message not forwarded intact')
check(native_calls==1,'native message called more than once')
-- Execute the authored first-run Save & Close handler with its own config closure.
local file=assert(io.open('config.lua'));local src=file:read('*a');file:close()
local body=assert(src:match('pfQuestInit%.save:SetScript%("OnClick", function%(%)\n(.-)\n end%)'))
local reset,hidden=0,0
env.pfQuest_config={};env.pfQuest={ResetAll=function()reset=reset+1 end};env.pfQuestInit={Hide=function()hidden=hidden+1 end}
for mode=1,3 do
local fn=assert(loadstring('local config_stage={mode='..mode..',arrow=true};return function()\n'..body..'\nend'))
setfenv(fn,env);fn()()
check(env.pfQuest_config.welcome=='1' and env.pfQuest_config.arrow=='1','actual first-run save lost choices')
check(g.ChatFrame1.AddMessage==original and g.ChatFrame2.AddMessage==original,'first-run save changed native message methods')
check(g.C_ChatInfo.SendChatMessage==native_send and g.ChatEdit_ParseText==parse,'first-run save changed native send/parser')
end
check(reset==3 and hidden==3,'actual save did not reset/hide once per mode')
check(env.pfQuestCompat.QuestWatchFrame==env.QuestWatchFrame,'tracker receives private stand-in')
check(not env.pfQuestCompat.QuestWatchFrame:IsShown(),'reported tracker expression succeeds')
check(type(env.TEXT)=='function','TEXT initialized before client.lua')
if bad_hook then check(rejected_hook==1,'guarded hook rejection did not abort remaining initialization') end
end
scenario(false)
scenario(true)
print(count..' native chat ownership and authored first-run callback checks PASS (not a native taint-engine simulation)')