I flew the A330/340 many years ago and remember this issue.
This type of problem can't happen on the 747 classic as pack 1 provides the air to the cockpit and it's fresh with no interference from recirculated air. The 747-400 however does receive recirculated air and on some occasions gets some odd smells usually from fwd cargo I believe. It's interesting that the 747-8 has returned to the pack 1 fresh air system like the classic.
So yes I believe it's a design issue on the A330/340 and some combination of pressure differentials ends up forcing toilet air into the cockpit.
I believe the 777 has a positive pressure cockpit designed to prevent smoke entering from the outside, however I don't know if the 777 cockpit receives recirculated air or not. Perhaps to trouble shoot flood the A330/340 toilet with smoke of some kind and you may see where it enters the cockpit the problem is the problem may not be repeatable on the ground?
Good luck.