diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim
index be3e52deb..d38e4db49 100644
--- a/src/testdir/test_gui.vim
+++ b/src/testdir/test_gui.vim
@@ -72,6 +72,28 @@ func Test_getfontname_without_arg()
   endif
 endfunc
 
+func s:SetStringToQuoteplus(str)
+  let @+ = a:str
+  let cnt = 5
+  while cnt > 0
+    " To make sure if the clipboard has already had a:str, ask it for the
+    " content.
+    new
+    norm "+p
+    let result = getline(1)
+    bwipe!
+    if result == a:str
+      return 'OK'
+    else
+      " Try again.
+      sleep 200m
+      let @+ = a:str
+    endif
+    let cnt -= 1
+  endwhile
+  return 'FAIL'
+endfunc
+
 func Test_quoteplus()
   let skipped = ''
 
@@ -95,18 +117,22 @@ func Test_quoteplus()
           \ . ':q!\<CR>", "tx")'
     let run_vimtest = printf(testee, cmd1, cmd2)
 
-    " Set the quoteplus register to test_call, and another gvim will launched.
-    " Then, it first tries to paste the content of its own quotedplus register
-    " onto it.  Second, it tries to substitute test_responce for the pasted
-    " sentence.  If the sentence is identical to test_call, the substitution
-    " should succeed.  Third, it tries to yank the result of the substitution
-    " to its own quoteplus register, and last it quits.  When system()
-    " returns, the content of the quoteplus register should be identical to
-    " test_response if those quoteplus registers are synchronized properly
-    " with/through the X11 clipboard.
-    let @+ = test_call
-    call system(run_vimtest)
-    call assert_equal(test_response, @+)
+    " Set the quoteplus register to test_call, and another gvim will be
+    " launched.  Then, it first tries to paste the content of its own
+    " quotedplus register onto it.  Second, it tries to substitute
+    " test_responce for the pasted sentence.  If the sentence is identical to
+    " test_call, the substitution should succeed.  Third, it tries to yank the
+    " result of the substitution to its own quoteplus register, and last it
+    " quits.  When system() returns, the content of the quoteplus register
+    " should be identical to test_response if those quoteplus registers are
+    " synchronized properly with/through the X11 clipboard.
+    let ret = <SID>SetStringToQuoteplus(test_call)
+    if ret == 'FAIL'
+      let skipped = g:not_hosted
+    else
+      call system(run_vimtest)
+      call assert_equal(test_response, @+)
+    endif
 
     let @+ = quoteplus_saved
   endif
