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

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

Issue 929493002: 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_;
59 ClientClipboard* client_clipboard_; 58 ClientClipboard* client_clipboard_;
60 scoped_ptr<ClipboardAura> clipboard_; 59 scoped_ptr<ClipboardAura> clipboard_;
61 }; 60 };
62 61
63 void ClipboardAuraTest::SetUp() { 62 void ClipboardAuraTest::SetUp() {
64 // Alert the clipboard class to which threads are allowed to access the 63 // Alert the clipboard class to which threads are allowed to access the
65 // clipboard. 64 // clipboard.
66 std::vector<base::PlatformThreadId> allowed_clipboard_threads; 65 std::vector<base::PlatformThreadId> allowed_clipboard_threads;
67 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId()); 66 allowed_clipboard_threads.push_back(base::PlatformThread::CurrentId());
68 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads); 67 ui::Clipboard::SetAllowedThreads(allowed_clipboard_threads);
69 68
70 // Setup the clipboard. 69 // Setup the clipboard.
71 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 70 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
72 message_loop_.message_loop_proxy(); 71 message_loop_.message_loop_proxy();
73 client_clipboard_ = new ClientClipboard(); 72 client_clipboard_ = new ClientClipboard();
74 clipboard_.reset(new ClipboardAura(task_runner)); 73 clipboard_.reset(new ClipboardAura());
75 clipboard_->Start(make_scoped_ptr(client_clipboard_));
76 74
77 EXPECT_GT(TestTimeouts::tiny_timeout(), kTestOverridePollingInterval * 10) 75 EXPECT_GT(TestTimeouts::tiny_timeout(), kTestOverridePollingInterval * 10)
78 << "The test timeout should be greater than the polling interval"; 76 << "The test timeout should be greater than the polling interval";
79 clipboard_->SetPollingIntervalForTesting(kTestOverridePollingInterval); 77 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 run_loop_.RunUntilIdle(); 98 base::RunLoop().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
109 { 111 {
110 // |clipboard_writer| will write to the clipboard when it goes out of scope. 112 // |clipboard_writer| will write to the clipboard when it goes out of scope.
111 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE); 113 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
112 clipboard_writer.WriteText(base::UTF8ToUTF16("Test data.")); 114 clipboard_writer.WriteText(base::UTF8ToUTF16("Test data."));
113 } 115 }
114 116
115 EXPECT_CALL(*client_clipboard_, 117 EXPECT_CALL(*client_clipboard_,
116 InjectClipboardEvent(Property(&protocol::ClipboardEvent::data, 118 InjectClipboardEvent(Property(&protocol::ClipboardEvent::data,
117 Eq("Test data.")))).Times(1); 119 Eq("Test data.")))).Times(1);
118 120
121 base::RunLoop run_loop;
119 message_loop_.PostDelayedTask( 122 message_loop_.PostDelayedTask(
120 FROM_HERE, base::Bind(&ClipboardAuraTest_MonitorClipboardChanges_Test:: 123 FROM_HERE, base::Bind(&ClipboardAuraTest_MonitorClipboardChanges_Test::
121 StopAndResetClipboard, 124 StopAndResetClipboard,
122 base::Unretained(this)), 125 base::Unretained(this)),
123 TestTimeouts::tiny_timeout()); 126 TestTimeouts::tiny_timeout());
124 message_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), 127 message_loop_.PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
125 TestTimeouts::tiny_timeout()); 128 TestTimeouts::tiny_timeout());
126 message_loop_.Run(); 129 run_loop.Run();
127 } 130 }
128 131
129 } // namespace remoting 132 } // 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