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

Side by Side Diff: chrome/browser/profiles/incognito_selection_clipboard_uitest.cc

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Renamed set_write_objects_callback() 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 "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/interactive_test_utils.h"
12 #include "content/public/test/test_utils.h"
13 #include "ui/base/clipboard/scoped_clipboard_writer.h"
14 #include "ui/base/events/event_constants.h"
15
16 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN;
dcheng 2013/02/15 07:29:23 Nit: we can just use this directly now.
vasilii 2013/02/15 10:37:39 Done.
17
18 class IncognitoSelectionClipboardTest : public InProcessBrowserTest {
19 protected:
20 static ui::Clipboard* clipboard() {
21 static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
22 return clipboard;
23 }
24
25 static void ExpectStringInClipboard(const string16& pattern,
26 ui::Clipboard::Buffer buffer) {
27 string16 content;
28 clipboard()->ReadText(buffer, &content);
29 EXPECT_EQ(pattern, content);
30 }
31
32 void CloseBrowser(Browser* browser) {
33 content::WindowedNotificationObserver signal(
34 chrome::NOTIFICATION_BROWSER_CLOSED,
35 content::Source<Browser>(browser));
36 chrome::CloseWindow(browser);
37
38 signal.Wait();
39 }
40
41 static void SendKeyForBrowser(const Browser* browser,
42 ui::KeyboardCode key,
43 int modifiers) {
44 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
45 browser, key,
46 (modifiers & ui::EF_CONTROL_DOWN) != 0,
47 (modifiers & ui::EF_SHIFT_DOWN) != 0,
48 (modifiers & ui::EF_ALT_DOWN) != 0,
49 (modifiers & ui::EF_COMMAND_DOWN) != 0));
50 }
51
52 static void WriteClipboardCallback(ui::Clipboard::Buffer expected,
53 const base::Closure& closure,
54 ui::Clipboard::Buffer actual) {
55 if (expected == actual)
56 closure.Run();
57 }
58 };
59
60 // Tests that data selected in content area of incognito window is destroyed in
61 // the selection clipboard after profile destruction.
62 // The test is executed on Linux only because it's the only OS with the
63 // selection clipboard.
64 #if defined(USE_X11) && !defined(OS_CHROMEOS)
dcheng 2013/02/15 07:29:23 I would just wrap the entire test implementation i
vasilii 2013/02/15 10:37:39 Done.
65 #define MAYBE_ClearContentDataOnSelect ClearContentDataOnSelect
66 #else
67 #define MAYBE_ClearContentDataOnSelect DISABLED_ClearContentDataOnSelect
68 #endif
69 IN_PROC_BROWSER_TEST_F(IncognitoSelectionClipboardTest,
70 MAYBE_ClearContentDataOnSelect) {
71 EXPECT_FALSE(browser()->profile()->IsOffTheRecord());
72 Browser* browser_incognito = CreateIncognitoBrowser();
73 ui_test_utils::NavigateToURL(browser_incognito, GURL("data:text/plain,foo"));
74 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser_incognito));
75 // Select web-page content.
76 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(browser_incognito,
77 ui::VKEY_A,
78 kCtrlOrCmdMask));
79 // Run message loop until data have been written to the selection clipboard.
80 // This happens on UI thread.
81 scoped_refptr<content::MessageLoopRunner> message_loop_runner(
82 new content::MessageLoopRunner);
83 clipboard()->set_write_objects_callback_for_testing(
84 base::Bind(&WriteClipboardCallback,
85 ui::Clipboard::BUFFER_SELECTION,
86 message_loop_runner->QuitClosure()));
87 message_loop_runner->Run();
88 ExpectStringInClipboard(ASCIIToUTF16("foo"), ui::Clipboard::BUFFER_SELECTION);
89
90 CloseBrowser(browser_incognito);
91 ExpectStringInClipboard(string16(), ui::Clipboard::BUFFER_SELECTION);
92 }
93
94 // Tests that data copied in content area of incognito window is destroyed in
95 // the selection clipboard after profile destruction.
96 // The test is executed on Linux only because it's the only OS with the
97 // selection clipboard.
98 #if defined(USE_X11) && !defined(OS_CHROMEOS)
99 #define MAYBE_ClearContentDataOnCopy ClearContentDataOnCopy
100 #else
101 #define MAYBE_ClearContentDataOnCopy DISABLED_ClearContentDataOnCopy
102 #endif
103 IN_PROC_BROWSER_TEST_F(IncognitoSelectionClipboardTest,
104 MAYBE_ClearContentDataOnCopy) {
105 EXPECT_FALSE(browser()->profile()->IsOffTheRecord());
106 Browser* browser_incognito = CreateIncognitoBrowser();
107 ui_test_utils::NavigateToURL(browser_incognito, GURL("data:text/plain,foo"));
108 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser_incognito));
109 // Select and copy web-page content.
110 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(browser_incognito,
111 ui::VKEY_A,
112 kCtrlOrCmdMask));
113 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(browser_incognito,
114 ui::VKEY_C,
115 kCtrlOrCmdMask));
116 // Run message loop until data have been written to the primary clipboard and
117 // automatically propagated to the selection clipboard by ui::Clipboard.
118 // This happens on UI thread.
119 scoped_refptr<content::MessageLoopRunner> message_loop_runner(
120 new content::MessageLoopRunner);
121 clipboard()->set_write_objects_callback_for_testing(
122 base::Bind(&WriteClipboardCallback,
123 ui::Clipboard::BUFFER_STANDARD,
124 message_loop_runner->QuitClosure()));
125 message_loop_runner->Run();
126 ExpectStringInClipboard(ASCIIToUTF16("foo"), ui::Clipboard::BUFFER_SELECTION);
127 ExpectStringInClipboard(ASCIIToUTF16("foo"), ui::Clipboard::BUFFER_STANDARD);
128
129 CloseBrowser(browser_incognito);
130 ExpectStringInClipboard(string16(), ui::Clipboard::BUFFER_SELECTION);
131 ExpectStringInClipboard(string16(), ui::Clipboard::BUFFER_STANDARD);
132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698