--[[----------------------------------------------------------------------------

KSLuaGlobalsProtectionTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2010 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]

local KSLuaGlobalsProtectionTest = {}
local WFPlatformInfo = require 'WFPlatformInfo'
local WFCapabilities = require 'WFCapabilities'

--------------------------------------------------------------------------------

function KSLuaGlobalsProtectionTest.testReadDisallowed()

	local success, message = pcall( function()
	
		local x = _G.xyz -- should fail
		return x
	
	end )

	assert( not success )
	assert( message:find( "attempt to read undefined global variable xyz disallowed" ) )

end

--------------------------------------------------------------------------------

function KSLuaGlobalsProtectionTest.testWriteDisallowed()

	local success, message = pcall( function()
	
		_G.abc = "abc" -- should fail
	
	end )

	assert( not success )
	assert( message:find( "attempt to write undefined global variable abc disallowed" ) )

end

--------------------------------------------------------------------------------

-- SPAM [jandrew 3/2/2015]: Lua gobals aren't protected in Lr, and so we can't expect
-- this test suite to pass across all WF clients.

if WFCapabilities.getCapability "LuaGlobalsProtection" and not WFPlatformInfo.isAndroid then
	return KSLuaGlobalsProtectionTest
else
	return {}
end
