OLD | NEW |
| (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/test_utils.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 | |
23 void ExpectStringInClipboard(const string16& pattern) { | |
24 string16 content; | |
25 clipboard()->ReadText(ui::Clipboard::BUFFER_STANDARD, &content); | |
26 EXPECT_EQ(pattern, content); | |
27 } | |
28 | |
29 static void WriteClipboardCallback(ui::Clipboard::Buffer expected, | |
30 const base::Closure& closure, | |
31 ui::Clipboard::Buffer actual) { | |
32 if (expected == actual) | |
33 closure.Run(); | |
34 } | |
35 }; | |
36 | |
37 // Tests that data copied from content area of OffTheRecord window is destroyed | |
38 // after context destruction. | |
39 IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, PRE_ClearContentData) { | |
40 Shell* shell_offtherecord = CreateOffTheRecordBrowser(); | |
41 NavigateToURL(shell_offtherecord, GURL("data:text/plain,foo")); | |
42 // Clear the clipboard. Currently GTK Clipboard::Clear fails to clear | |
43 // clipboard from external content. | |
44 { | |
45 ui::ScopedClipboardWriter clipboard_writer(clipboard(), | |
46 ui::Clipboard::BUFFER_STANDARD); | |
47 clipboard_writer.WriteText(ASCIIToUTF16("bar")); | |
48 } | |
49 ExpectStringInClipboard(ASCIIToUTF16("bar")); | |
50 | |
51 // Select and copy web-page content. | |
52 WebContents* web_contents = shell_offtherecord->web_contents(); | |
53 RenderViewHost* view_host = web_contents->GetRenderViewHost(); | |
54 view_host->SelectAll(); | |
55 view_host->Copy(); | |
56 | |
57 // Run message loop until data have been copied to the clipboard. This happens | |
58 // on UI thread. | |
59 scoped_refptr<MessageLoopRunner> message_loop_runner(new MessageLoopRunner); | |
60 clipboard()->set_write_objects_callback_for_testing( | |
61 base::Bind(&WriteClipboardCallback, | |
62 ui::Clipboard::BUFFER_STANDARD, | |
63 message_loop_runner->QuitClosure())); | |
64 message_loop_runner->Run(); | |
65 ExpectStringInClipboard(ASCIIToUTF16("foo")); | |
66 } | |
67 | |
68 IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, ClearContentData) { | |
69 EXPECT_FALSE(clipboard()->IsFormatAvailable( | |
70 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD)); | |
71 } | |
72 | |
73 } // namespace content | |
OLD | NEW |