OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/aura/mus/os_exchange_data_provider_mus.h" | 5 #include "ui/aura/mus/os_exchange_data_provider_mus.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/pickle.h" | 11 #include "base/pickle.h" |
13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/scoped_task_environment.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "net/base/filename_util.h" | 15 #include "net/base/filename_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
18 #include "ui/base/dragdrop/os_exchange_data.h" | 18 #include "ui/base/dragdrop/os_exchange_data.h" |
19 #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" | 19 #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" |
20 #include "ui/events/platform/platform_event_source.h" | 20 #include "ui/events/platform/platform_event_source.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 using ui::Clipboard; | 23 using ui::Clipboard; |
24 using ui::OSExchangeData; | 24 using ui::OSExchangeData; |
25 | 25 |
26 namespace aura { | 26 namespace aura { |
27 | 27 |
28 // This file is a copy/paste of the unit tests in os_exchange_data_unittest.cc, | 28 // This file is a copy/paste of the unit tests in os_exchange_data_unittest.cc, |
29 // with additional SetUp() to force the mus override. I thought about changeing | 29 // with additional SetUp() to force the mus override. I thought about changeing |
30 // the OSExchangeData test suite to a parameterized test suite, but I've | 30 // the OSExchangeData test suite to a parameterized test suite, but I've |
31 // previously had problems with that feature of gtest. | 31 // previously had problems with that feature of gtest. |
32 | 32 |
33 class OSExchangeDataProviderMusTest | 33 class OSExchangeDataProviderMusTest |
34 : public PlatformTest, | 34 : public PlatformTest, |
35 public ui::OSExchangeDataProviderFactory::Factory { | 35 public ui::OSExchangeDataProviderFactory::Factory { |
36 public: | 36 public: |
37 OSExchangeDataProviderMusTest() {} | 37 OSExchangeDataProviderMusTest() |
| 38 : scoped_task_environment_( |
| 39 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
38 | 40 |
39 // Overridden from PlatformTest: | 41 // Overridden from PlatformTest: |
40 void SetUp() override { | 42 void SetUp() override { |
41 PlatformTest::SetUp(); | 43 PlatformTest::SetUp(); |
42 old_factory_ = ui::OSExchangeDataProviderFactory::TakeFactory(); | 44 old_factory_ = ui::OSExchangeDataProviderFactory::TakeFactory(); |
43 ui::OSExchangeDataProviderFactory::SetFactory(this); | 45 ui::OSExchangeDataProviderFactory::SetFactory(this); |
44 } | 46 } |
45 | 47 |
46 void TearDown() override { | 48 void TearDown() override { |
47 ui::OSExchangeDataProviderFactory::TakeFactory(); | 49 ui::OSExchangeDataProviderFactory::TakeFactory(); |
48 ui::OSExchangeDataProviderFactory::SetFactory(old_factory_); | 50 ui::OSExchangeDataProviderFactory::SetFactory(old_factory_); |
49 PlatformTest::TearDown(); | 51 PlatformTest::TearDown(); |
50 } | 52 } |
51 | 53 |
52 // Overridden from ui::OSExchangeDataProviderFactory::Factory: | 54 // Overridden from ui::OSExchangeDataProviderFactory::Factory: |
53 std::unique_ptr<OSExchangeData::Provider> BuildProvider() override { | 55 std::unique_ptr<OSExchangeData::Provider> BuildProvider() override { |
54 return base::MakeUnique<OSExchangeDataProviderMus>(); | 56 return base::MakeUnique<OSExchangeDataProviderMus>(); |
55 } | 57 } |
56 | 58 |
57 private: | 59 private: |
58 ui::OSExchangeDataProviderFactory::Factory* old_factory_ = nullptr; | 60 ui::OSExchangeDataProviderFactory::Factory* old_factory_ = nullptr; |
59 base::MessageLoopForUI message_loop_; | 61 base::test::ScopedTaskEnvironment scoped_task_environment_; |
60 }; | 62 }; |
61 | 63 |
62 TEST_F(OSExchangeDataProviderMusTest, StringDataGetAndSet) { | 64 TEST_F(OSExchangeDataProviderMusTest, StringDataGetAndSet) { |
63 OSExchangeData data; | 65 OSExchangeData data; |
64 base::string16 input = base::ASCIIToUTF16("I can has cheezburger?"); | 66 base::string16 input = base::ASCIIToUTF16("I can has cheezburger?"); |
65 EXPECT_FALSE(data.HasString()); | 67 EXPECT_FALSE(data.HasString()); |
66 data.SetString(input); | 68 data.SetString(input); |
67 EXPECT_TRUE(data.HasString()); | 69 EXPECT_TRUE(data.HasString()); |
68 | 70 |
69 OSExchangeData data2( | 71 OSExchangeData data2( |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 data.SetHtml(html, url); | 205 data.SetHtml(html, url); |
204 | 206 |
205 OSExchangeData copy( | 207 OSExchangeData copy( |
206 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); | 208 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); |
207 base::string16 read_html; | 209 base::string16 read_html; |
208 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); | 210 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); |
209 EXPECT_EQ(html, read_html); | 211 EXPECT_EQ(html, read_html); |
210 } | 212 } |
211 | 213 |
212 } // namespace aura | 214 } // namespace aura |
OLD | NEW |