We consider a $q$-dimensional Brownian motion $(W_r)_r.$ Let $O \subset \mathbb{R}^q$ be a bounded domain and $f:\overline{O} \to \mathbb{R}$ a continuous function. Let $T:=\inf\{r \geq 0,B_r \notin O\}.$
We suppose that for all $x \in O, f(B_{T \wedge r})_{r \geq 0}$ is a $P_x$-martingale.
Prove that $f$ is harmonic on $O.$
Since $\overline{O}$ is a compact and $f$ is continuous we know that $f$ is bounded on $O$ and that $T$ is finite $P_x$-a.s. Hence $(f(B_{T \wedge r}))_{r \geq 0}$ converges $P_x$-a.s. and in $L^1$ to $B_T$ and for all $r \geq 0, f(B_{T \wedge r})=E_x[f(B_T)|\mathcal{F}_r]$ $P_x$-a.s., in particular $f(x)=E_x[f(B_T)].$
How can we verify that $f$ is harmonic on $O?$
A harmonic function is one for which the mean value property holds; i.e. the value of $f$ at the centre of any ball contained in the domain is the mean of $f$ on its surface. In the language of your problem (and continuing with your initial notation $W_{r}$ for Brownian motion), this is to say that for all $x,\delta$ with $B(x,\delta)\subset O$, where $\tau=\inf\left\{r\ge 0:W_{r}\notin B(x,\delta)\right\}$ we want $f(x)=E_{x}\!\left[f(W_{\tau})\right]$.
Now because $\left(f(W_{T\wedge r})\right)_{r\ge 0}$ is a $P_{x}$-martingale we may apply the optional stopping theorem, with stopping time $\tau$ as above. Immediately this gives us $f(x)=E_{x}\!\left[f(W_{T\wedge \tau})\right]=E_{x}\!\left[f(W_{\tau})\right]$ as desired.