Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: remoting/host/chromeos/clipboard_aura_unittest.cc

Issue 923773003: Revert of Remove dependency on content from remoting_host. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/chromeos/clipboard_aura.cc ('k') | remoting/host/chromoting_host_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/chromeos/clipboard_aura.h" 5 #include "remoting/host/chromeos/clipboard_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 class ClipboardAuraTest : public testing::Test { 48 class ClipboardAuraTest : public testing::Test {
49 public: 49 public:
50 ClipboardAuraTest() {} 50 ClipboardAuraTest() {}
51 void SetUp() override; 51 void SetUp() override;
52 void TearDown() override; 52 void TearDown() override;
53 53
54 protected: 54 protected:
55 void StopAndResetClipboard(); 55 void StopAndResetClipboard();
56 56
57 base::MessageLoopForUI message_loop_; 57 base::MessageLoopForUI message_loop_;
58 base::RunLoop run_loop_;
58 ClientClipboard* client_clipboard_; 59 ClientClipboard* client_clipboard_;
59 scoped_ptr<ClipboardAura> clipboard_; 60 scoped_ptr<ClipboardAura> clipboard_;
60 }; 61 };
61 62
62 void ClipboardAuraTest::SetUp() { 63 void ClipboardAuraTest::SetUp() {
63 // Alert the clipboard class to which threads are allowed to access the 64 // Alert the clipboard class to which threads are allowed to access the
64 // clipboard. 65 // clipboard.
65 std::vector<base::PlatformThreadId> allowed_clipboard_threads; 66 std::vector<base::PlatformThreadId> allowed_clipboard_threads;
66 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); 67 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId());
67 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); 68 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads);
68 69
69 // Setup the clipboard. 70 // Setup the clipboard.
70 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 71 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
71 message_loop_.message_loop_proxy(); 72 message_loop_.message_loop_proxy();
72 client_clipboard_ = new ClientClipboard(); 73 client_clipboard_ = new ClientClipboard();
73 clipboard_.reset(new ClipboardAura()); 74 clipboard_.reset(new ClipboardAura(task_runner));
75 clipboard_->Start(make_scoped_ptr(client_clipboard_));
74 76
75 EXPECT_GT(TestTimeouts::tiny_timeout(), kTestOverridePollingInterval * 10) 77 EXPECT_GT(TestTimeouts::tiny_timeout(), kTestOverridePollingInterval * 10)
76 << "The test timeout should be greater than the polling interval"; 78 << "The test timeout should be greater than the polling interval";
77 clipboard_->SetPollingIntervalForTesting(kTestOverridePollingInterval); 79 clipboard_->SetPollingIntervalForTesting(kTestOverridePollingInterval);
78
79 clipboard_->Start(make_scoped_ptr(client_clipboard_));
80 } 80 }
81 81
82 void ClipboardAuraTest::TearDown() { 82 void ClipboardAuraTest::TearDown() {
83 ui::Clipboard::DestroyClipboardForCurrentThread(); 83 ui::Clipboard::DestroyClipboardForCurrentThread();
84 } 84 }
85 85
86 void ClipboardAuraTest::StopAndResetClipboard() { 86 void ClipboardAuraTest::StopAndResetClipboard() {
87 clipboard_->Stop(); 87 clipboard_->Stop();
88 clipboard_.reset(); 88 clipboard_.reset();
89 } 89 }
90 90
91 TEST_F(ClipboardAuraTest, WriteToClipboard) { 91 TEST_F(ClipboardAuraTest, WriteToClipboard) {
92 protocol::ClipboardEvent event; 92 protocol::ClipboardEvent event;
93 event.set_mime_type(kMimeTypeTextUtf8); 93 event.set_mime_type(kMimeTypeTextUtf8);
94 event.set_data("Test data."); 94 event.set_data("Test data.");
95 95
96 clipboard_->InjectClipboardEvent(event); 96 clipboard_->InjectClipboardEvent(event);
97 StopAndResetClipboard(); 97 StopAndResetClipboard();
98 base::RunLoop().RunUntilIdle(); 98 run_loop_.RunUntilIdle();
99 99
100 std::string clipboard_data; 100 std::string clipboard_data;
101 ui::Clipboard* aura_clipboard = ui::Clipboard::GetForCurrentThread(); 101 ui::Clipboard* aura_clipboard = ui::Clipboard::GetForCurrentThread();
102 aura_clipboard->ReadAsciiText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_data); 102 aura_clipboard->ReadAsciiText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_data);
103 103
104 EXPECT_EQ(clipboard_data, "Test data.") 104 EXPECT_EQ(clipboard_data, "Test data.")
105 << "InjectClipboardEvent should write to aura clipboard"; 105 << "InjectClipboardEvent should write to aura clipboard";
106 } 106 }
107 107
108 TEST_F(ClipboardAuraTest, MonitorClipboardChanges) { 108 TEST_F(ClipboardAuraTest, MonitorClipboardChanges) {
109 base::RunLoop().RunUntilIdle();
110
111 { 109 {
112 // |clipboard_writer| will write to the clipboard when it goes out of scope. 110 // |clipboard_writer| will write to the clipboard when it goes out of scope.
113 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE); 111 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
114 clipboard_writer.WriteText(base::UTF8ToUTF16("Test data.")); 112 clipboard_writer.WriteText(base::UTF8ToUTF16("Test data."));
115 } 113 }
116 114
117 EXPECT_CALL(*client_clipboard_, 115 EXPECT_CALL(*client_clipboard_,
118 InjectClipboardEvent(Property(&protocol::ClipboardEvent::data, 116 InjectClipboardEvent(Property(&protocol::ClipboardEvent::data,
119 Eq("Test data.")))).Times(1); 117 Eq("Test data.")))).Times(1);
120 118
121 base::RunLoop run_loop;
122 message_loop_.PostDelayedTask( 119 message_loop_.PostDelayedTask(
123 FROM_HERE, base::Bind(&ClipboardAuraTest_MonitorClipboardChanges_Test:: 120 FROM_HERE, base::Bind(&ClipboardAuraTest_MonitorClipboardChanges_Test::
124 StopAndResetClipboard, 121 StopAndResetClipboard,
125 base::Unretained(this)), 122 base::Unretained(this)),
126 TestTimeouts::tiny_timeout()); 123 TestTimeouts::tiny_timeout());
127 message_loop_.PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), 124 message_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(),
128 TestTimeouts::tiny_timeout()); 125 TestTimeouts::tiny_timeout());
129 run_loop.Run(); 126 message_loop_.Run();
130 } 127 }
131 128
132 } // namespace remoting 129 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/chromeos/clipboard_aura.cc ('k') | remoting/host/chromoting_host_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698