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

Side by Side Diff: content/test/clipboard_browser_test.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved incogito marker to BrowserContext 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.
jam 2013/02/07 21:52:17 move this test to content/browser/renderer_host/ a
vasilii 2013/02/08 09:27:36 Done.
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/clipboard.h"
13 #include "ui/base/clipboard/scoped_clipboard_writer.h"
14
15 namespace content {
16 namespace {
17 class ClipboardWriteObserver :
18 public ui::Clipboard::ClipboardObserverForTesting {
19 public:
20 explicit ClipboardWriteObserver(ui::Clipboard* clipboard)
21 : seen_(false),
22 running_(false),
23 clipboard_(clipboard) {
24 clipboard_->AddObserver(this);
25 }
26
27 virtual ~ClipboardWriteObserver() {
28 clipboard_->RemoveObserver(this);
29 }
30
31 void Wait() {
32 if (seen_) return;
33
34 running_ = true;
35 message_loop_runner_ = new content::MessageLoopRunner;
jam 2013/02/07 21:52:17 nit: no content::
vasilii 2013/02/08 09:27:36 Done.
36 message_loop_runner_->Run();
37 EXPECT_TRUE(seen_);
38 }
39
40 private:
41 virtual void OnWriteObjects(ui::Clipboard::Buffer buffer) OVERRIDE {
42 if (buffer != ui::Clipboard::BUFFER_STANDARD) return;
43 seen_ = true;
44 if (!running_) return;
45
46 message_loop_runner_->Quit();
47 running_ = false;
48 }
49
50 bool seen_;
51 bool running_;
52 scoped_refptr<MessageLoopRunner> message_loop_runner_;
53 ui::Clipboard* clipboard_;
54
55 DISALLOW_COPY_AND_ASSIGN(ClipboardWriteObserver);
56 };
57
58 } // namespace
59
60 class OffTheRecordClipboardTest : public ContentBrowserTest {
61 protected:
62 ui::Clipboard* clipboard() const {
63 static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
64 return clipboard;
65 }
66 void ExpectStringInClipboard(const string16& pattern) {
67 string16 content;
68 clipboard()->ReadText(ui::Clipboard::BUFFER_STANDARD, &content);
69 EXPECT_EQ(pattern, content);
70 }
71 };
72
73 // Tests that data copied from content area of OffTheRecord window is destroyed
74 // after context destruction.
75 IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, PRE_ClearContentData) {
76 Shell* shell_offtherecord = CreateOffTheRecordBrowser();
77 NavigateToURL(shell_offtherecord, GURL("data:text/plain,foo"));
78 // Clear the clipboard. Currently GTK Clipboard::Clear fails to clear
79 // clipboard from external content.
80 {
81 ui::ScopedClipboardWriter clipboard_writer(clipboard(),
82 ui::Clipboard::BUFFER_STANDARD);
83 clipboard_writer.WriteText(ASCIIToUTF16("bar"));
84 }
85 ExpectStringInClipboard(ASCIIToUTF16("bar"));
86 // Select and copy web-page content
87 WebContents* web_contents = shell_offtherecord->web_contents();
88 RenderViewHost* view_host = web_contents->GetRenderViewHost();
89 ClipboardWriteObserver clipboard_observer(clipboard());
90 view_host->SelectAll();
91 view_host->Copy();
92 // Run message loop until data have been copied to the clipboard. This happens
93 // on UI thread.
94 clipboard_observer.Wait();
95 ExpectStringInClipboard(ASCIIToUTF16("foo"));
96 }
97
98 IN_PROC_BROWSER_TEST_F(OffTheRecordClipboardTest, ClearContentData) {
99 EXPECT_FALSE(clipboard()->IsFormatAvailable(
100 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD));
101 }
102 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698