If a door is closed to a space that may be occupied, always knock before entering. This includes, but is not limited to, offices, bedrooms, dressing/fitting rooms, lavatory stalls, hotel rooms and hospital rooms.
Yesterday, I was trying on clothing in a department store fitting room and 3 women opened my fitting room door in separate attempts. There wasn’t a lock on the door, but it would have been most polite if any of these women gently knocked on the door before swinging it wide open. The knock would have saved embarrassment for all of us.
On the flip side, if you are in a room when someone knocks to check on the availability, respond appropriately and be polite in your response. Be appreciative someone bothered to check before barging in.