Getting name of frontmost application

I try to test if ScreenSaverEngine is frontmost, but this fails:

tell application "System Events" to set testing to name of first process where it is frontmost

ScreenSaverEngine can never be frontmost, because its background only property is true