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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/incognito_selection_clipboard_uitest.cc
diff --git a/chrome/browser/profiles/incognito_selection_clipboard_uitest.cc b/chrome/browser/profiles/incognito_selection_clipboard_uitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..36a10749deac6e18c21c434201817552479e5898
--- /dev/null
+++ b/chrome/browser/profiles/incognito_selection_clipboard_uitest.cc
@@ -0,0 +1,132 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/interactive_test_utils.h"
+#include "content/public/test/test_utils.h"
+#include "ui/base/clipboard/scoped_clipboard_writer.h"
+#include "ui/base/events/event_constants.h"
+
+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.
+
+class IncognitoSelectionClipboardTest : public InProcessBrowserTest {
+ protected:
+ static ui::Clipboard* clipboard() {
+ static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
+ return clipboard;
+ }
+
+ static void ExpectStringInClipboard(const string16& pattern,
+ ui::Clipboard::Buffer buffer) {
+ string16 content;
+ clipboard()->ReadText(buffer, &content);
+ EXPECT_EQ(pattern, content);
+ }
+
+ void CloseBrowser(Browser* browser) {
+ content::WindowedNotificationObserver signal(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(browser));
+ chrome::CloseWindow(browser);
+
+ signal.Wait();
+ }
+
+ static void SendKeyForBrowser(const Browser* browser,
+ ui::KeyboardCode key,
+ int modifiers) {
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ browser, key,
+ (modifiers & ui::EF_CONTROL_DOWN) != 0,
+ (modifiers & ui::EF_SHIFT_DOWN) != 0,
+ (modifiers & ui::EF_ALT_DOWN) != 0,
+ (modifiers & ui::EF_COMMAND_DOWN) != 0));
+ }
+
+ static void WriteClipboardCallback(ui::Clipboard::Buffer expected,
+ const base::Closure& closure,
+ ui::Clipboard::Buffer actual) {
+ if (expected == actual)
+ closure.Run();
+ }
+};
+
+// Tests that data selected in content area of incognito window is destroyed in
+// the selection clipboard after profile destruction.
+// The test is executed on Linux only because it's the only OS with the
+// selection clipboard.
+#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.
+#define MAYBE_ClearContentDataOnSelect ClearContentDataOnSelect
+#else
+#define MAYBE_ClearContentDataOnSelect DISABLED_ClearContentDataOnSelect
+#endif
+IN_PROC_BROWSER_TEST_F(IncognitoSelectionClipboardTest,
+ MAYBE_ClearContentDataOnSelect) {
+ EXPECT_FALSE(browser()->profile()->IsOffTheRecord());
+ Browser* browser_incognito = CreateIncognitoBrowser();
+ ui_test_utils::NavigateToURL(browser_incognito, GURL("data:text/plain,foo"));
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser_incognito));
+ // Select web-page content.
+ ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(browser_incognito,
+ ui::VKEY_A,
+ kCtrlOrCmdMask));
+ // Run message loop until data have been written to the selection clipboard.
+ // This happens on UI thread.
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner(
+ new content::MessageLoopRunner);
+ clipboard()->set_write_objects_callback_for_testing(
+ base::Bind(&WriteClipboardCallback,
+ ui::Clipboard::BUFFER_SELECTION,
+ message_loop_runner->QuitClosure()));
+ message_loop_runner->Run();
+ ExpectStringInClipboard(ASCIIToUTF16("foo"), ui::Clipboard::BUFFER_SELECTION);
+
+ CloseBrowser(browser_incognito);
+ ExpectStringInClipboard(string16(), ui::Clipboard::BUFFER_SELECTION);
+}
+
+// Tests that data copied in content area of incognito window is destroyed in
+// the selection clipboard after profile destruction.
+// The test is executed on Linux only because it's the only OS with the
+// selection clipboard.
+#if defined(USE_X11) && !defined(OS_CHROMEOS)
+#define MAYBE_ClearContentDataOnCopy ClearContentDataOnCopy
+#else
+#define MAYBE_ClearContentDataOnCopy DISABLED_ClearContentDataOnCopy
+#endif
+IN_PROC_BROWSER_TEST_F(IncognitoSelectionClipboardTest,
+ MAYBE_ClearContentDataOnCopy) {
+ EXPECT_FALSE(browser()->profile()->IsOffTheRecord());
+ Browser* browser_incognito = CreateIncognitoBrowser();
+ ui_test_utils::NavigateToURL(browser_incognito, GURL("data:text/plain,foo"));
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser_incognito));
+ // Select and copy web-page content.
+ ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(browser_incognito,
+ ui::VKEY_A,
+ kCtrlOrCmdMask));
+ ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(browser_incognito,
+ ui::VKEY_C,
+ kCtrlOrCmdMask));
+ // Run message loop until data have been written to the primary clipboard and
+ // automatically propagated to the selection clipboard by ui::Clipboard.
+ // This happens on UI thread.
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner(
+ new content::MessageLoopRunner);
+ clipboard()->set_write_objects_callback_for_testing(
+ base::Bind(&WriteClipboardCallback,
+ ui::Clipboard::BUFFER_STANDARD,
+ message_loop_runner->QuitClosure()));
+ message_loop_runner->Run();
+ ExpectStringInClipboard(ASCIIToUTF16("foo"), ui::Clipboard::BUFFER_SELECTION);
+ ExpectStringInClipboard(ASCIIToUTF16("foo"), ui::Clipboard::BUFFER_STANDARD);
+
+ CloseBrowser(browser_incognito);
+ ExpectStringInClipboard(string16(), ui::Clipboard::BUFFER_SELECTION);
+ ExpectStringInClipboard(string16(), ui::Clipboard::BUFFER_STANDARD);
+}

Powered by Google App Engine
This is Rietveld 408576698