What you want to do is possible, as the posters above mentioned. In addition, with patch 2.3, the macro can be even simpler (they removed the requirement of /stopcasting):

/cast Elemental Mastery
/cast Chain Lightning

The tooltip is entirely optional and does not affect functionality, but I'd agree with Jusa in that #showtooltip Chain Lightning is probably the one you want to see.

As for why it works, normally, if you write a macro with multiple spells and the first one fails (due to cooldown or whatever other reason), the entire macro will stop. But this has nothing to do with it failing and everything to do with the fact that most spells trigger the global cooldown. With 2.0, blizzard made sure that any spell that would trigger the global cooldown if it succeeded disallows further spells to be cast. Any spell, item, or ability (trinkets, elemental mastery, nature's swiftness, inner focus, etc...) which do not trigger the GCD can all be put before any spell which would trigger it (just like Zoroaster and Jusa mentioned).