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

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: Addressing comments 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..ddef3b53a8609ba87cbd73ae15bbd9523f5cd6c5
--- /dev/null
+++ b/content/browser/renderer_host/clipboard_browsertest.cc
@@ -0,0 +1,102 @@
+// 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/test_utils.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/clipboard.h"
+#include "ui/base/clipboard/scoped_clipboard_writer.h"
+
+namespace content {
+namespace {
Jói 2013/02/08 10:37:32 nit: I think we would typically include a blank li
vasilii 2013/02/08 12:37:12 Done.
+class ClipboardWriteObserver :
+ public ui::Clipboard::ClipboardObserverForTesting {
+ public:
+ explicit ClipboardWriteObserver(ui::Clipboard* clipboard)
+ : seen_(false),
+ running_(false),
+ clipboard_(clipboard) {
+ clipboard_->AddObserver(this);
+ }
+
+ virtual ~ClipboardWriteObserver() {
+ clipboard_->RemoveObserver(this);
+ }
+
+ void Wait() {
+ if (seen_) return;
+
+ running_ = true;
+ message_loop_runner_ = new MessageLoopRunner;
+ message_loop_runner_->Run();
+ EXPECT_TRUE(seen_);
+ }
+
+ private:
+ virtual void OnWriteObjects(ui::Clipboard::Buffer buffer) OVERRIDE {
+ if (buffer != ui::Clipboard::BUFFER_STANDARD) return;
+ seen_ = true;
+ if (!running_) return;
+
+ message_loop_runner_->Quit();
+ running_ = false;
+ }
+
+ bool seen_;
+ bool running_;
+ scoped_refptr<MessageLoopRunner> message_loop_runner_;
+ ui::Clipboard* clipboard_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClipboardWriteObserver);
+};
+
+} // namespace
+
+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
+ WebContents* web_contents = shell_offtherecord->web_contents();
+ RenderViewHost* view_host = web_contents->GetRenderViewHost();
+ ClipboardWriteObserver clipboard_observer(clipboard());
+ 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
Jói 2013/02/08 10:37:32 nit: Typically there is a blank line before this.
vasilii 2013/02/08 12:37:12 Done.

Powered by Google App Engine
This is Rietveld 408576698