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

Unified Diff: content/browser/renderer_host/clipboard_browsertest.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Selection clipboard support Created 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/clipboard_browsertest.cc
diff --git a/content/browser/renderer_host/clipboard_browsertest.cc b/content/browser/renderer_host/clipboard_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ccb6aedd694a2b2445d210cc5f82f0e9f9d3531
--- /dev/null
+++ b/content/browser/renderer_host/clipboard_browsertest.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/utf_string_conversions.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/clipboard_write_observer.h"
+#include "content/shell/shell.h"
+#include "content/test/content_browser_test.h"
+#include "content/test/content_browser_test_utils.h"
+#include "ui/base/clipboard/scoped_clipboard_writer.h"
+
+namespace content {
+
+class OffTheRecordClipboardTest : public ContentBrowserTest {
+ protected:
+ ui::Clipboard* clipboard() const {
+ static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
+ return clipboard;
+ }
+ void ExpectStringInClipboard(const string16& pattern) {
+ string16 content;
+ clipboard()->ReadText(ui::Clipboard::BUFFER_STANDARD, &content);
+ EXPECT_EQ(pattern, content);
+ }
+};
+
+// Tests that data copied from content area of OffTheRecord window is destroyed
+// after context destruction.
+IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, PRE_ClearContentData) {
+ Shell* shell_offtherecord = CreateOffTheRecordBrowser();
+ NavigateToURL(shell_offtherecord, GURL("data:text/plain,foo"));
+ // Clear the clipboard. Currently GTK Clipboard::Clear fails to clear
+ // clipboard from external content.
+ {
+ ui::ScopedClipboardWriter clipboard_writer(clipboard(),
+ ui::Clipboard::BUFFER_STANDARD);
+ clipboard_writer.WriteText(ASCIIToUTF16("bar"));
+ }
+ ExpectStringInClipboard(ASCIIToUTF16("bar"));
+ // Select and copy web-page content
battre 2013/02/12 12:50:59 nit: . at end of line. Generally I think it looks
vasilii 2013/02/12 15:58:32 Done.
+ WebContents* web_contents = shell_offtherecord->web_contents();
+ RenderViewHost* view_host = web_contents->GetRenderViewHost();
+ ClipboardWriteObserver clipboard_observer(clipboard(),
+ ui::Clipboard::BUFFER_STANDARD);
+ view_host->SelectAll();
+ view_host->Copy();
+ // Run message loop until data have been copied to the clipboard. This happens
+ // on UI thread.
+ clipboard_observer.Wait();
+ ExpectStringInClipboard(ASCIIToUTF16("foo"));
+}
+
+IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, ClearContentData) {
+ EXPECT_FALSE(clipboard()->IsFormatAvailable(
+ ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698