Confronting the Chaplygin gas with data: background and perturbed cosmic dynamics