The diagram and photo below show an audio loopback dongle for the headset connector. The Chrome hardware team designed this circuit and plug for functional testing; however it has many other uses too. The Android audio team uses it to measure round-trip audio latency, by sending an encoded signal through the output and then looking for that matching signal on the input. The time between the two is the combined input plus output latency. This technique is used in OboeTester and in CTS Verifier.
A Loopback Dongle based on the circuit below is available from PassMark Software. This isn't a recommendation or an endorsement. Google does not have a business relationship with PassMark.
To ensure that the output signal will not overload the microphone input, we cut it down by about 20dB. The resistor loads tell the microphone polarity switch that the audio loopback dongle is a US/CTIA pinout Tip Ring Ring Shield (TRRS) plug.