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

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: 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
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 // Simple test that the sequence number appears to change when the clipboard is
722 // written to.
723 // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION.
724 TEST_F(ClipboardTest, GetSequenceNumber) {
725 const uint64 first_sequence_number =
726 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE);
727
728 {
729 ScopedClipboardWriter writer(&clipboard(), CLIPBOARD_TYPE_COPY_PASTE);
730 writer.WriteText(UTF8ToUTF16("World"));
731 }
732
733 // On some platforms, the sequence number is updated by a UI callback so pump
734 // the message loop to make sure we get the notification.
735 base::RunLoop().RunUntilIdle();
736
737 const uint64 second_sequence_number =
738 clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE);
739
740 EXPECT_NE(first_sequence_number, second_sequence_number);
raymes 2014/01/14 02:55:47 It might be worth checking the case that I fixed (
741 }
742
720 #if defined(OS_ANDROID) 743 #if defined(OS_ANDROID)
721 744
722 // Test that if another application writes some text to the pasteboard the 745 // Test that if another application writes some text to the pasteboard the
723 // clipboard properly invalidates other types. 746 // clipboard properly invalidates other types.
724 TEST_F(ClipboardTest, InternalClipboardInvalidation) { 747 TEST_F(ClipboardTest, InternalClipboardInvalidation) {
725 // Write a Webkit smart paste tag to our clipboard. 748 // Write a Webkit smart paste tag to our clipboard.
726 { 749 {
727 ScopedClipboardWriter clipboard_writer(&clipboard(), 750 ScopedClipboardWriter clipboard_writer(&clipboard(),
728 CLIPBOARD_TYPE_COPY_PASTE); 751 CLIPBOARD_TYPE_COPY_PASTE);
729 clipboard_writer.WriteWebSmartPaste(); 752 clipboard_writer.WriteWebSmartPaste();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 EXPECT_TRUE(clipboard().IsFormatAvailable( 803 EXPECT_TRUE(clipboard().IsFormatAvailable(
781 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); 804 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE));
782 805
783 // Make sure the text is what we inserted while simulating the other app 806 // Make sure the text is what we inserted while simulating the other app
784 std::string contents; 807 std::string contents;
785 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents); 808 clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &contents);
786 EXPECT_EQ(contents, new_value); 809 EXPECT_EQ(contents, new_value);
787 } 810 }
788 #endif 811 #endif
789 } // namespace ui 812 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698