Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / omnibox / clipboard_utils_unittest.cc
blobfd78f7b2da67553dd25f7a08c46bf62f6fbde62f
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
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "base/strings/string16.h"
7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/omnibox/clipboard_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
12 #include "ui/base/clipboard/clipboard.h"
13 #include "ui/base/clipboard/scoped_clipboard_writer.h"
15 using base::ASCIIToUTF16;
17 namespace {
19 class ClipboardUtilsTest : public PlatformTest {
20 public:
21 void TearDown() override {
22 ui::Clipboard::DestroyClipboardForCurrentThread();
25 private:
26 // Windows requires a message loop for clipboard access.
27 base::MessageLoopForUI message_loop_;
30 TEST_F(ClipboardUtilsTest, GetClipboardText) {
31 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
33 const base::string16 kPlainText(ASCIIToUTF16("test text"));
34 const std::string kURL("http://www.example.com/");
36 // Can we pull straight text off the clipboard?
38 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
39 clipboard_writer.WriteText(kPlainText);
41 EXPECT_EQ(kPlainText, GetClipboardText());
43 // Can we pull a string consists of white-space?
44 const base::string16 kSpace6(ASCIIToUTF16(" "));
45 const base::string16 kSpace1(ASCIIToUTF16(" "));
47 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
48 clipboard_writer.WriteText(kSpace6);
50 EXPECT_EQ(kSpace1, GetClipboardText());
52 // Does an empty clipboard get empty text?
53 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
54 EXPECT_EQ(base::string16(), GetClipboardText());
56 // Bookmark clipboard apparently not supported on Linux.
57 // See TODO on ClipboardText.BookmarkTest.
58 #if !defined(OS_POSIX) || defined(OS_MACOSX)
59 const base::string16 kTitle(ASCIIToUTF16("The Example Company"));
60 // Can we pull a bookmark off the clipboard?
62 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
63 clipboard_writer.WriteBookmark(kTitle, kURL);
65 EXPECT_EQ(ASCIIToUTF16(kURL), GetClipboardText());
67 // Do we pull text in preference to a bookmark?
69 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
70 clipboard_writer.WriteText(kPlainText);
71 clipboard_writer.WriteBookmark(kTitle, kURL);
73 EXPECT_EQ(kPlainText, GetClipboardText());
74 #endif
76 // Do we get nothing if there is neither text nor a bookmark?
78 const base::string16 kMarkup(ASCIIToUTF16("<strong>Hi!</string>"));
79 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
80 clipboard_writer.WriteHTML(kMarkup, kURL);
82 EXPECT_TRUE(GetClipboardText().empty());
85 } // namespace