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