1)
の is considered a pronoun for location/place here.
e.g.
彼女が生まれたのは日本です。
私が行きたいのは東京です。
In the examples above, の doesn't nominalize the action and is not interchangeable with こと.
When the target is the thing they sleep on, e.g. 布団, ベッド or 床, both で and に can be used. If it refers to location such like 部屋, 家 or 公園, で is used. Although I think で is not a particle but the -te form of copula here.
2)
どの呪文が試験に出るんだろう is not what she actually murmured, as I wrote. It's her voice in mind if the narration is written on the point of view of third-person, as Morphling-san wrote, or the description of her appearance if it's written on the point of view of Harry or someone other than Hermione. (とでもいうような様子で is the one for the latter case.)