I will make my answer, based on the knowledge for security testing, but IMHO this can be generalized.
Black box testing - when the tester know nothing about the system, components, liaisons, connections, etc. This can be helpful more like UI/UX testing, functional testing. Example: you do not work for Microsoft and also you do not have the source code and need to test MS Office
Gray box testing - when the tester have some knowledge about how the system work, some information about internals.
White box testing - when the tester have or can get all the information about internals, connections, principles of work of the tested product. Example: testing Linux kernel.
For reference:
Black box testing (Wikipedia)
White box testing (Wikipedia)
Gray box testing (Wikipedia)