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

Side by Side Diff: ui/base/clipboard/clipboard_test_template.h

Issue 2849603003: Use ScopedTaskEnvironment instead of MessageLoopForUI in ui tests. (Closed)
Patch Set: CR-add-newline-after-include Created 3 years, 7 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
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 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most 5 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most
6 // type-parameterized gtests. There are lot of test cases in here that are only 6 // type-parameterized gtests. There are lot of test cases in here that are only
7 // enabled on certain platforms. However, preprocessor directives in macro 7 // enabled on certain platforms. However, preprocessor directives in macro
8 // arguments result in undefined behavior (and don't work on MSVC). Instead, 8 // arguments result in undefined behavior (and don't work on MSVC). Instead,
9 // 'parameterized' tests should typedef TypesToTest (which is used to 9 // 'parameterized' tests should typedef TypesToTest (which is used to
10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this 10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this
11 // header. 11 // header.
12 // TODO(dcheng): This is really horrible. In general, all tests should run on 12 // TODO(dcheng): This is really horrible. In general, all tests should run on
13 // all platforms, to avoid this mess. 13 // all platforms, to avoid this mess.
14 14
15 #include <stdint.h> 15 #include <stdint.h>
16 16
17 #include <memory> 17 #include <memory>
18 #include <string> 18 #include <string>
19 19
20 #include "base/message_loop/message_loop.h"
21 #include "base/pickle.h" 20 #include "base/pickle.h"
22 #include "base/run_loop.h" 21 #include "base/run_loop.h"
23 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
24 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/test/scoped_task_environment.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "testing/gmock/include/gmock/gmock-matchers.h" 26 #include "testing/gmock/include/gmock/gmock-matchers.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "testing/platform_test.h" 28 #include "testing/platform_test.h"
29 #include "third_party/skia/include/core/SkBitmap.h" 29 #include "third_party/skia/include/core/SkBitmap.h"
30 #include "third_party/skia/include/core/SkColor.h" 30 #include "third_party/skia/include/core/SkColor.h"
31 #include "third_party/skia/include/core/SkScalar.h" 31 #include "third_party/skia/include/core/SkScalar.h"
32 #include "third_party/skia/include/core/SkUnPreMultiply.h" 32 #include "third_party/skia/include/core/SkUnPreMultiply.h"
33 #include "ui/base/clipboard/clipboard.h" 33 #include "ui/base/clipboard/clipboard.h"
34 #include "ui/base/clipboard/scoped_clipboard_writer.h" 34 #include "ui/base/clipboard/scoped_clipboard_writer.h"
(...skipping 14 matching lines...) Expand all
49 49
50 using testing::Contains; 50 using testing::Contains;
51 51
52 namespace ui { 52 namespace ui {
53 53
54 template <typename ClipboardTraits> 54 template <typename ClipboardTraits>
55 class ClipboardTest : public PlatformTest { 55 class ClipboardTest : public PlatformTest {
56 public: 56 public:
57 #if defined(USE_AURA) 57 #if defined(USE_AURA)
58 ClipboardTest() 58 ClipboardTest()
59 : event_source_(ClipboardTraits::GetEventSource()), 59 : scoped_task_environment_(
60 base::test::ScopedTaskEnvironment::MainThreadType::UI),
61 event_source_(ClipboardTraits::GetEventSource()),
60 clipboard_(ClipboardTraits::Create()) {} 62 clipboard_(ClipboardTraits::Create()) {}
61 #else 63 #else
62 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} 64 ClipboardTest()
65 : scoped_task_environment_(
66 base::test::ScopedTaskEnvironment::MainThreadType::UI),
67 clipboard_(ClipboardTraits::Create()) {}
63 #endif 68 #endif
64 69
65 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } 70 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); }
66 71
67 bool IsMusTest() { return ClipboardTraits::IsMusTest(); } 72 bool IsMusTest() { return ClipboardTraits::IsMusTest(); }
68 73
69 protected: 74 protected:
70 Clipboard& clipboard() { return *clipboard_; } 75 Clipboard& clipboard() { return *clipboard_; }
71 76
72 std::vector<base::string16> GetAvailableTypes(ClipboardType type) { 77 std::vector<base::string16> GetAvailableTypes(ClipboardType type) {
73 bool contains_filenames; 78 bool contains_filenames;
74 std::vector<base::string16> types; 79 std::vector<base::string16> types;
75 clipboard().ReadAvailableTypes(type, &types, &contains_filenames); 80 clipboard().ReadAvailableTypes(type, &types, &contains_filenames);
76 return types; 81 return types;
77 } 82 }
78 83
79 private: 84 private:
80 base::MessageLoopForUI message_loop_; 85 base::test::ScopedTaskEnvironment scoped_task_environment_;
81 #if defined(USE_AURA) 86 #if defined(USE_AURA)
82 std::unique_ptr<PlatformEventSource> event_source_; 87 std::unique_ptr<PlatformEventSource> event_source_;
83 #endif 88 #endif
84 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. 89 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here.
85 Clipboard* const clipboard_; 90 Clipboard* const clipboard_;
86 }; 91 };
87 92
88 // Hack for tests that need to call static methods of ClipboardTest. 93 // Hack for tests that need to call static methods of ClipboardTest.
89 struct NullClipboardTraits { 94 struct NullClipboardTraits {
90 static Clipboard* Create() { return nullptr; } 95 static Clipboard* Create() { return nullptr; }
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); 679 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
675 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); 680 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType());
676 } 681 }
677 682
678 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { 683 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) {
679 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); 684 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE);
680 scw.WriteImage(SkBitmap()); 685 scw.WriteImage(SkBitmap());
681 } 686 }
682 687
683 } // namespace ui 688 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698