There isn't a single definition of what foreground means and typically usage of something like that would be a signal of poor design leading you to the point of wanting such a thing.
If someone wants to know the real definition they need to read the AOSP code. The code is the source of truth and it could potentially change in a future versions if a new security concern came in.
Whether a toast is successfully toasted is reported back to the app's process, but the android framework doesn't expose this result to the app which implies that one shouldn't need to rely on the toast being shown or not.