1 If your window's size is smaller than the content area, it resizes the window so that the content fits
* hitting it again after doing this takes it back to the size it was before.
2 If part of the window is outside of your screens frame, it repositions it so that the entire window is within the screens frame (minus the dock and menu bar), resizing as necessary.
3. If the window is already showing all content and fits between the menubar and the dock, the button does nothing.
This is what I know for sure (tested it on a safari window cause I usually didn't think about it. I think anything else depends on how the developer lays out the UI.
1 is often the case.
2 is almost always the case.
3 should never be the case.
Assuming Cocoa, the default behavior of the zoom button is to toggle the window between two sizes/locations. The first is the last one established by explicit user actions (or as created by the application if the user has done nothing) and the second is essentially the entire area of the screen that contains most of the window when the button was clicked. If a maximize size has been set for the window which is smaller than the screen, the default behavior complies with that. Most developers should (and in my experience most do) override the default behavior at least to make the zooming behavior appropriate for the actual content or nature of the window. A handful go further, with varying success, invoking state changes beyond trivial geometry. (I never did much Carbon GUI programming; I have no idea how automated the behavior of the zoom button was in the Carbon event model. In the pre-Carbon Toolbox, there was no default behavior; the reaction to the zoom button was entirely at the coder's discretion.)
I've been playing with the green button in Lion and I find that it now is more than a simple toggle between two states. With a finder window, it will toggle through four or five different sizes and shapes before returning to the original conformation. Exactly how many states and shapes depends on whether the window is showing icons or is in list view etc. It's kind of a cool upgrade actually – lets the user quickly find a window size/shape he likes. I hadn't noticed that change until I started playing around with it just now.