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

Side by Side Diff: chrome/browser/clipboard/clipboard_interactive_uitest.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved the feature to 'content' layer 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/04 16:01:59 since this feature is implemented in content, the
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 "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/interactive_test_utils.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "ui/base/clipboard/clipboard.h"
16 #include "ui/base/clipboard/scoped_clipboard_writer.h"
17
18 #if defined(OS_MACOSX)
19 #include "base/mac/scoped_nsautorelease_pool.h"
20 #endif
21
22 namespace {
23 class ClipboardWriteObserver : private ui::Clipboard::ClipboardObserver {
24 public:
25 explicit ClipboardWriteObserver(ui::Clipboard* clipboard)
26 : seen_(false),
27 running_(false),
28 clipboard_(clipboard) {
29 clipboard_->AddObserver(this);
30 }
31
32 virtual ~ClipboardWriteObserver() {
33 clipboard_->RemoveObserver(this);
34 }
35
36 void Wait() {
37 if (seen_) return;
38
39 running_ = true;
40 message_loop_runner_ = new content::MessageLoopRunner;
41 message_loop_runner_->Run();
42 EXPECT_TRUE(seen_);
43 }
44
45 private:
46 virtual void OnWriteObjects(ui::Clipboard::Buffer buffer) OVERRIDE {
47 if (buffer != ui::Clipboard::BUFFER_STANDARD) return;
48 seen_ = true;
49 if (!running_) return;
50
51 message_loop_runner_->Quit();
52 running_ = false;
53 }
54
55 bool seen_;
56 bool running_;
57 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
58 ui::Clipboard* clipboard_;
59
60 DISALLOW_COPY_AND_ASSIGN(ClipboardWriteObserver);
61 };
62
63 } // namespace
64
65 class IncognitoClipboardTest : public InProcessBrowserTest {
66 protected:
67 ui::Clipboard* clipboard() const {
68 static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
69 return clipboard;
70 }
71 void ExpectStringInClipboard(const string16& pattern) {
72 string16 content;
73 clipboard()->ReadText(ui::Clipboard::BUFFER_STANDARD, &content);
74 EXPECT_EQ(pattern, content);
75 }
76 };
77
78 // Tests that data copied from content area of incognito window is destroyed
79 // after profile destruction.
80 // Only Linux GTK supports this feature for now.
81 #if defined(TOOLKIT_GTK) && defined(OS_LINUX)
82 #define MAYBE_ClearContentData ClearContentData
83 #else
84 #define MAYBE_ClearContentData DISABLED_ClearContentData
85 #endif
86 IN_PROC_BROWSER_TEST_F(IncognitoClipboardTest, MAYBE_ClearContentData) {
87 EXPECT_FALSE(browser()->profile()->IsOffTheRecord());
88 Browser* browser_incognito = CreateIncognitoBrowser();
89 ui_test_utils::NavigateToURL(browser_incognito, GURL("data:text/plain,foo"));
90 // Clear the clipboard. Currently GTK Clipboard::Clear fails to clear
91 // clipboard from external content.
92 {
93 ui::ScopedClipboardWriter clipboard_writer(clipboard(),
94 ui::Clipboard::BUFFER_STANDARD);
95 clipboard_writer.WriteText(ASCIIToUTF16("bar"));
96 }
97 ExpectStringInClipboard(ASCIIToUTF16("bar"));
98 // Select and copy web-page content
99 content::WebContents* web_contents =
100 browser_incognito->tab_strip_model()->GetActiveWebContents();
101 content::RenderViewHost* view_host = web_contents->GetRenderViewHost();
102 ClipboardWriteObserver clipboard_observer(clipboard());
103 view_host->SelectAll();
104 view_host->Copy();
105 // Run message loop until data have been copied to the clipboard. This happens
106 // on UI thread.
107 clipboard_observer.Wait();
108 ExpectStringInClipboard(ASCIIToUTF16("foo"));
109
110 content::WindowedNotificationObserver signal(
111 chrome::NOTIFICATION_BROWSER_CLOSED,
112 content::Source<Browser>(browser_incognito));
113 chrome::CloseWindow(browser_incognito);
114
115 #if defined(OS_MACOSX)
116 // BrowserWindowController depends on the auto release pool being recycled
117 // in the message loop to delete itself, which frees the Browser object
118 // which fires this event.
119 AutoreleasePool()->Recycle();
120 #endif
121
122 signal.Wait();
123 EXPECT_FALSE(clipboard()->IsFormatAvailable(
124 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD));
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698