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"
9 #include "remoting/base/constants.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 // X11 headers must be #included after gtest.h, since the X11 headers define
13 // some macros that cause errors in gtest-type-util.h.
15 #include "remoting/host/linux/x_server_clipboard.h"
21 class ClipboardTestClient
{
23 ClipboardTestClient() : display_(nullptr) {}
24 ~ClipboardTestClient() {}
26 void Init(Display
* display
) {
28 clipboard_
.Init(display
,
29 base::Bind(&ClipboardTestClient::OnClipboardChanged
,
30 base::Unretained(this)));
33 void SetClipboardData(const std::string
& clipboard_data
) {
34 clipboard_data_
= clipboard_data
;
35 clipboard_
.SetClipboard(kMimeTypeTextUtf8
, clipboard_data
);
38 void OnClipboardChanged(const std::string
& mime_type
,
39 const std::string
& data
) {
40 clipboard_data_
= data
;
43 // Process X events on the connection, returning true if any events were
47 while (XPending(display_
)) {
49 XNextEvent(display_
, &event
);
50 clipboard_
.ProcessXEvent(&event
);
56 const std::string
& clipboard_data() const { return clipboard_data_
; }
57 Display
* display() const { return display_
; }
60 std::string clipboard_data_
;
61 XServerClipboard clipboard_
;
64 DISALLOW_COPY_AND_ASSIGN(ClipboardTestClient
);
69 class XServerClipboardTest
: public testing::Test
{
71 void SetUp() override
{
72 // XSynchronize() ensures that PumpXEvents() fully processes all X server
73 // requests and responses before returning to the caller.
74 Display
* display1
= XOpenDisplay(nullptr);
75 XSynchronize(display1
, True
);
76 client1_
.Init(display1
);
77 Display
* display2
= XOpenDisplay(nullptr);
78 XSynchronize(display2
, True
);
79 client2_
.Init(display2
);
82 void TearDown() override
{
83 XCloseDisplay(client1_
.display());
84 XCloseDisplay(client2_
.display());
89 if (!client1_
.PumpXEvents() && !client2_
.PumpXEvents()) {
95 ClipboardTestClient client1_
;
96 ClipboardTestClient client2_
;
99 // http://crbug.com/163428
100 TEST_F(XServerClipboardTest
, DISABLED_CopyPaste
) {
101 // Verify clipboard data can be transferred more than once. Then verify that
102 // the code continues to function in the opposite direction (so client1_ will
103 // send then receive, and client2_ will receive then send).
104 client1_
.SetClipboardData("Text1");
106 EXPECT_EQ("Text1", client2_
.clipboard_data());
108 client1_
.SetClipboardData("Text2");
110 EXPECT_EQ("Text2", client2_
.clipboard_data());
112 client2_
.SetClipboardData("Text3");
114 EXPECT_EQ("Text3", client1_
.clipboard_data());
116 client2_
.SetClipboardData("Text4");
118 EXPECT_EQ("Text4", client1_
.clipboard_data());
121 } // namespace remoting