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

Side by Side Diff: ui/base/clipboard/clipboard_unittest.cc

Issue 136193002: Add Clipboard::GetSequenceNumber test and fix Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trim Android changes Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/pickle.h" 12 #include "base/pickle.h"
13 #include "base/run_loop.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
19 #include "third_party/skia/include/core/SkScalar.h" 20 #include "third_party/skia/include/core/SkScalar.h"
20 #include "third_party/skia/include/core/SkUnPreMultiply.h" 21 #include "third_party/skia/include/core/SkUnPreMultiply.h"
21 #include "ui/base/clipboard/clipboard.h" 22 #include "ui/base/clipboard/clipboard.h"
22 #include "ui/base/clipboard/scoped_clipboard_writer.h" 23 #include "ui/base/clipboard/scoped_clipboard_writer.h"
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 writer.WriteHTML(UTF8ToUTF16("foo"), "bar"); 711 writer.WriteHTML(UTF8ToUTF16("foo"), "bar");
711 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); 712 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar");
712 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); 713 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar");
713 writer.WriteWebSmartPaste(); 714 writer.WriteWebSmartPaste();
714 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. 715 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData.
715 } 716 }
716 717
717 // Passes if we don't crash. 718 // Passes if we don't crash.
718 } 719 }
719 720
721 // TODO(dcheng): Fix this test for Android. It's rather involved, since the
722 // clipboard change listener is posted to the Java message loop, and spinning
723 // that loop from C++ to trigger the callback in the test requires a non-trivial
724 // amount of additional work.
725 #if !defined(OS_ANDROID)
726 // Simple test that the sequence number appears to change when the clipboard is
727 // written to.
728 // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION.
729 TEST_F(ClipboardTest, GetSequenceNumber) {
730 const uint64 first_sequence_number =
731 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE);
732
733 {
734 ScopedClipboardWriter writer(&clipboard(), CLIPBOARD_TYPE_COPY_PASTE);
735 writer.WriteText(UTF8ToUTF16("World"));
736 }
737
738 // On some platforms, the sequence number is updated by a UI callback so pump
739 // the message loop to make sure we get the notification.
740 base::RunLoop().RunUntilIdle();
741
742 const uint64 second_sequence_number =
743 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE);
744
745 EXPECT_NE(first_sequence_number, second_sequence_number);
746 }
747 #endif
748
720 #if defined(OS_ANDROID) 749 #if defined(OS_ANDROID)
721 750
722 // Test that if another application writes some text to the pasteboard the 751 // Test that if another application writes some text to the pasteboard the
723 // clipboard properly invalidates other types. 752 // clipboard properly invalidates other types.
724 TEST_F(ClipboardTest, InternalClipboardInvalidation) { 753 TEST_F(ClipboardTest, InternalClipboardInvalidation) {
725 // Write a Webkit smart paste tag to our clipboard. 754 // Write a Webkit smart paste tag to our clipboard.
726 { 755 {
727 ScopedClipboardWriter clipboard_writer(&clipboard(), 756 ScopedClipboardWriter clipboard_writer(&clipboard(),
728 CLIPBOARD_TYPE_COPY_PASTE); 757 CLIPBOARD_TYPE_COPY_PASTE);
729 clipboard_writer.WriteWebSmartPaste(); 758 clipboard_writer.WriteWebSmartPaste();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 EXPECT_TRUE(clipboard().IsFormatAvailable( 809 EXPECT_TRUE(clipboard().IsFormatAvailable(
781 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); 810 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
782 811
783 // Make sure the text is what we inserted while simulating the other app 812 // Make sure the text is what we inserted while simulating the other app
784 std::string contents; 813 std::string contents;
785 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); 814 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents);
786 EXPECT_EQ(contents, new_value); 815 EXPECT_EQ(contents, new_value);
787 } 816 }
788 #endif 817 #endif
789 } // namespace ui 818 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698