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

Unified Diff: content/public/test/browser_test_utils.cc

Issue 2146323002: Expose RTF content on the clipboard as strings to pages when pasting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: BrowserTestClipboardScope. Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/renderer/webclipboard_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/browser_test_utils.cc
diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc
index ca51b0575028171c30990b686532a6c518739d2a..857542c67d9b670ea2e3512568ec42dbc0abe9dc 100644
--- a/content/public/test/browser_test_utils.cc
+++ b/content/public/test/browser_test_utils.cc
@@ -41,6 +41,7 @@
#include "content/common/view_messages.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_plugin_guest_manager.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/histogram_fetcher.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
@@ -62,7 +63,10 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/clipboard/clipboard.h"
+#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/test/test_clipboard.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/keycodes/dom/dom_code.h"
@@ -1431,4 +1435,76 @@ uint32_t InputMsgWatcher::WaitForAck() {
return ack_result_;
}
+#if defined(OS_WIN)
+static void RunTaskAndSignalCompletion(const base::Closure& task,
+ base::WaitableEvent* completion) {
+ task.Run();
+ completion->Signal();
+}
+
+static void RunTaskOnIOThreadAndWait(const base::Closure& task) {
+ base::WaitableEvent completion(
+ base::WaitableEvent::ResetPolicy::AUTOMATIC,
+ base::WaitableEvent::InitialState::NOT_SIGNALED);
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&RunTaskAndSignalCompletion, task, &completion));
+ completion.Wait();
+}
+#endif
+
+static void SetUpTestClipboard() {
+#if defined(OS_WIN)
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ RunTaskOnIOThreadAndWait(base::Bind(&SetUpTestClipboard));
+ return;
+ }
+#endif
+ ui::TestClipboard::CreateForCurrentThread();
+}
+
+// TODO(dcheng): Make the test clipboard on different threads share the
+// same backing store. crbug.com/629765
+BrowserTestClipboardScope::BrowserTestClipboardScope() {
+ SetUpTestClipboard();
+}
+
+static void TearDownTestClipboard() {
+#if defined(OS_WIN)
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ RunTaskOnIOThreadAndWait(base::Bind(&TearDownTestClipboard));
+ return;
+ }
+#endif
+ ui::Clipboard::DestroyClipboardForCurrentThread();
+}
+
+BrowserTestClipboardScope::~BrowserTestClipboardScope() {
+ TearDownTestClipboard();
+}
+
+void BrowserTestClipboardScope::SetRtf(const std::string& rtf) {
+#if defined(OS_WIN)
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ RunTaskOnIOThreadAndWait(base::Bind(&BrowserTestClipboardScope::SetRtf,
+ base::Unretained(this), rtf));
+ return;
+ }
+#endif
+ ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
+ clipboard_writer.WriteRTF(rtf);
+}
+
+void BrowserTestClipboardScope::SetText(const std::string& text) {
+#if defined(OS_WIN)
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ RunTaskOnIOThreadAndWait(base::Bind(&BrowserTestClipboardScope::SetText,
+ base::Unretained(this), text));
+ return;
+ }
+#endif
+ ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
+ clipboard_writer.WriteText(base::ASCIIToUTF16(text));
+}
+
} // namespace content
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/renderer/webclipboard_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698