OLD | NEW |
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 "base/message_loop/message_loop.h" | 5 #include "chrome/browser/ui/omnibox/clipboard_utils.h" |
| 6 |
6 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/scoped_task_environment.h" |
9 #include "build/build_config.h" | 11 #include "build/build_config.h" |
10 #include "chrome/browser/ui/omnibox/clipboard_utils.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
13 #include "ui/base/clipboard/clipboard.h" | 14 #include "ui/base/clipboard/clipboard.h" |
14 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 15 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
15 | 16 |
16 using base::ASCIIToUTF16; | 17 using base::ASCIIToUTF16; |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 class ClipboardUtilsTest : public PlatformTest { | 21 class ClipboardUtilsTest : public PlatformTest { |
21 public: | 22 public: |
| 23 ClipboardUtilsTest() |
| 24 : scoped_task_environment_( |
| 25 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
| 26 |
22 void TearDown() override { | 27 void TearDown() override { |
23 ui::Clipboard::DestroyClipboardForCurrentThread(); | 28 ui::Clipboard::DestroyClipboardForCurrentThread(); |
24 } | 29 } |
25 | 30 |
26 private: | 31 private: |
27 // Windows requires a message loop for clipboard access. | 32 // Windows requires a message loop for clipboard access. |
28 base::MessageLoopForUI message_loop_; | 33 base::test::ScopedTaskEnvironment scoped_task_environment_; |
29 }; | 34 }; |
30 | 35 |
31 TEST_F(ClipboardUtilsTest, GetClipboardText) { | 36 TEST_F(ClipboardUtilsTest, GetClipboardText) { |
32 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 37 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
33 | 38 |
34 const base::string16 kPlainText(ASCIIToUTF16("test text")); | 39 const base::string16 kPlainText(ASCIIToUTF16("test text")); |
35 const std::string kURL("http://www.example.com/"); | 40 const std::string kURL("http://www.example.com/"); |
36 | 41 |
37 // Can we pull straight text off the clipboard? | 42 // Can we pull straight text off the clipboard? |
38 { | 43 { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // Do we get nothing if there is neither text nor a bookmark? | 82 // Do we get nothing if there is neither text nor a bookmark? |
78 { | 83 { |
79 const base::string16 kMarkup(ASCIIToUTF16("<strong>Hi!</string>")); | 84 const base::string16 kMarkup(ASCIIToUTF16("<strong>Hi!</string>")); |
80 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE); | 85 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE); |
81 clipboard_writer.WriteHTML(kMarkup, kURL); | 86 clipboard_writer.WriteHTML(kMarkup, kURL); |
82 } | 87 } |
83 EXPECT_TRUE(GetClipboardText().empty()); | 88 EXPECT_TRUE(GetClipboardText().empty()); |
84 } | 89 } |
85 | 90 |
86 } // namespace | 91 } // namespace |
OLD | NEW |