1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/basictypes.h"
8 #include "remoting/base/constants.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 // X11 headers must be #included after gtest.h, since the X11 headers define
12 // some macros that cause errors in gtest-type-util.h.
14 #include "remoting/host/linux/x_server_clipboard.h"
20 class ClipboardTestClient
{
22 ClipboardTestClient() : display_(NULL
) {}
23 ~ClipboardTestClient() {}
25 void Init(Display
* display
) {
27 clipboard_
.Init(display
,
28 base::Bind(&ClipboardTestClient::OnClipboardChanged
,
29 base::Unretained(this)));
32 void SetClipboardData(const std::string
& clipboard_data
) {
33 clipboard_data_
= clipboard_data
;
34 clipboard_
.SetClipboard(kMimeTypeTextUtf8
, clipboard_data
);
37 void OnClipboardChanged(const std::string
& mime_type
,
38 const std::string
& data
) {
39 clipboard_data_
= data
;
42 // Process X events on the connection, returning true if any events were
46 while (XPending(display_
)) {
48 XNextEvent(display_
, &event
);
49 clipboard_
.ProcessXEvent(&event
);
55 const std::string
& clipboard_data() const { return clipboard_data_
; }
56 Display
* display() const { return display_
; }
59 std::string clipboard_data_
;
60 XServerClipboard clipboard_
;
63 DISALLOW_COPY_AND_ASSIGN(ClipboardTestClient
);
68 class XServerClipboardTest
: public testing::Test
{
70 virtual void SetUp() OVERRIDE
{
71 // XSynchronize() ensures that PumpXEvents() fully processes all X server
72 // requests and responses before returning to the caller.
73 Display
* display1
= XOpenDisplay(NULL
);
74 XSynchronize(display1
, True
);
75 client1_
.Init(display1
);
76 Display
* display2
= XOpenDisplay(NULL
);
77 XSynchronize(display2
, True
);
78 client2_
.Init(display2
);
81 virtual void TearDown() OVERRIDE
{
82 XCloseDisplay(client1_
.display());
83 XCloseDisplay(client2_
.display());
88 if (!client1_
.PumpXEvents() && !client2_
.PumpXEvents()) {
94 ClipboardTestClient client1_
;
95 ClipboardTestClient client2_
;
98 // http://crbug.com/163428
99 TEST_F(XServerClipboardTest
, DISABLED_CopyPaste
) {
100 // Verify clipboard data can be transferred more than once. Then verify that
101 // the code continues to function in the opposite direction (so client1_ will
102 // send then receive, and client2_ will receive then send).
103 client1_
.SetClipboardData("Text1");
105 EXPECT_EQ("Text1", client2_
.clipboard_data());
107 client1_
.SetClipboardData("Text2");
109 EXPECT_EQ("Text2", client2_
.clipboard_data());
111 client2_
.SetClipboardData("Text3");
113 EXPECT_EQ("Text3", client1_
.clipboard_data());
115 client2_
.SetClipboardData("Text4");
117 EXPECT_EQ("Text4", client1_
.clipboard_data());
120 } // namespace remoting