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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/utf_string_conversions.h"
6 #include "content/public/browser/render_view_host.h"
7 #include "content/public/browser/web_contents.h"
8 #include "content/public/test/clipboard_write_observer.h"
9 #include "content/shell/shell.h"
10 #include "content/test/content_browser_test.h"
11 #include "content/test/content_browser_test_utils.h"
12 #include "ui/base/clipboard/scoped_clipboard_writer.h"
13
14 namespace content {
15
16 class OffTheRecordClipboardTest : public ContentBrowserTest {
17 protected:
18 ui::Clipboard* clipboard() const {
19 static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
20 return clipboard;
21 }
22 void ExpectStringInClipboard(const string16& pattern) {
23 string16 content;
24 clipboard()->ReadText(ui::Clipboard::BUFFER_STANDARD, &content);
25 EXPECT_EQ(pattern, content);
26 }
27 };
28
29 // Tests that data copied from content area of OffTheRecord window is destroyed
30 // after context destruction.
31 IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, PRE_ClearContentData) {
32 Shell* shell_offtherecord = CreateOffTheRecordBrowser();
33 NavigateToURL(shell_offtherecord, GURL("data:text/plain,foo"));
34 // Clear the clipboard. Currently GTK Clipboard::Clear fails to clear
35 // clipboard from external content.
36 {
37 ui::ScopedClipboardWriter clipboard_writer(clipboard(),
38 ui::Clipboard::BUFFER_STANDARD);
39 clipboard_writer.WriteText(ASCIIToUTF16("bar"));
40 }
41 ExpectStringInClipboard(ASCIIToUTF16("bar"));
42 // 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.
43 WebContents* web_contents = shell_offtherecord->web_contents();
44 RenderViewHost* view_host = web_contents->GetRenderViewHost();
45 ClipboardWriteObserver clipboard_observer(clipboard(),
46 ui::Clipboard::BUFFER_STANDARD);
47 view_host->SelectAll();
48 view_host->Copy();
49 // Run message loop until data have been copied to the clipboard. This happens
50 // on UI thread.
51 clipboard_observer.Wait();
52 ExpectStringInClipboard(ASCIIToUTF16("foo"));
53 }
54
55 IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, ClearContentData) {
56 EXPECT_FALSE(clipboard()->IsFormatAvailable(
57 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD));
58 }
59
60 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698