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

Side by Side Diff: content/test/blink_test_environment.cc

Issue 2852373004: Use ScopedTaskEnvironment instead of MessageLoop in tests that use v8. (Closed)
Patch Set: fix-hang 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/test/blink_test_environment.h" 5 #include "content/test/blink_test_environment.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
12 #include "base/strings/string_tokenizer.h" 11 #include "base/strings/string_tokenizer.h"
12 #include "base/test/scoped_task_environment.h"
13 #include "base/test/test_discardable_memory_allocator.h" 13 #include "base/test/test_discardable_memory_allocator.h"
14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
17 #include "content/public/common/user_agent.h" 17 #include "content/public/common/user_agent.h"
18 #include "content/public/test/test_content_client_initializer.h" 18 #include "content/public/test/test_content_client_initializer.h"
19 #include "content/test/test_blink_web_unit_test_support.h" 19 #include "content/test/test_blink_web_unit_test_support.h"
20 #include "third_party/WebKit/public/platform/WebCache.h" 20 #include "third_party/WebKit/public/platform/WebCache.h"
21 #include "third_party/WebKit/public/web/WebKit.h" 21 #include "third_party/WebKit/public/web/WebKit.h"
22 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 22 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
23 #include "url/url_util.h" 23 #include "url/url_util.h"
24 24
25 #if defined(OS_WIN) 25 #if defined(OS_WIN)
26 #include "ui/display/win/dpi.h" 26 #include "ui/display/win/dpi.h"
27 #endif 27 #endif
28 28
29 #if defined(OS_MACOSX) 29 #if defined(OS_MACOSX)
30 #include "base/test/mock_chrome_application_mac.h" 30 #include "base/test/mock_chrome_application_mac.h"
31 #endif 31 #endif
32 32
33 namespace content { 33 namespace content {
34 34
35 namespace { 35 namespace {
36 36
37 class TestEnvironment { 37 class TestEnvironment {
38 public: 38 public:
39 #if defined(OS_ANDROID) 39 TestEnvironment()
40 // Android UI message loop goes through Java, so don't use it in tests. 40 #if !defined(OS_ANDROID)
41 typedef base::MessageLoop MessageLoopType; 41 // On Android, do not pump UI messages on the main thread because that
42 #else 42 // would go through Java.
gab 2017/05/03 17:38:36 // On Android, Java pumps UI messages.
fdoray 2017/05/03 20:48:44 Done.
43 typedef base::MessageLoopForUI MessageLoopType; 43 : scoped_task_environment_(
44 base::test::ScopedTaskEnvironment::MainThreadType::UI)
44 #endif 45 #endif
45 46 {
46 TestEnvironment() { 47 // TestBlinkWebUnitTestSupport must be instantiated after
47 main_message_loop_.reset(new MessageLoopType); 48 // ScopedTaskEnvironment.
gab 2017/05/03 17:38:36 Move this comment to the member and make both of t
fdoray 2017/05/03 20:48:44 Done.
48
49 // TestBlinkWebUnitTestSupport must be instantiated after MessageLoopType.
50 blink_test_support_.reset(new TestBlinkWebUnitTestSupport); 49 blink_test_support_.reset(new TestBlinkWebUnitTestSupport);
51 content_initializer_.reset(new content::TestContentClientInitializer()); 50 content_initializer_.reset(new content::TestContentClientInitializer());
52 51
53 base::DiscardableMemoryAllocator::SetInstance( 52 base::DiscardableMemoryAllocator::SetInstance(
54 &discardable_memory_allocator_); 53 &discardable_memory_allocator_);
55 } 54 }
56 55
57 ~TestEnvironment() { 56 ~TestEnvironment() {
58 } 57 }
59 58
60 TestBlinkWebUnitTestSupport* blink_platform_impl() const { 59 TestBlinkWebUnitTestSupport* blink_platform_impl() const {
61 return blink_test_support_.get(); 60 return blink_test_support_.get();
62 } 61 }
63 62
64 private: 63 private:
65 std::unique_ptr<MessageLoopType> main_message_loop_; 64 base::test::ScopedTaskEnvironment scoped_task_environment_;
65
66 std::unique_ptr<TestBlinkWebUnitTestSupport> blink_test_support_; 66 std::unique_ptr<TestBlinkWebUnitTestSupport> blink_test_support_;
67 std::unique_ptr<TestContentClientInitializer> content_initializer_; 67 std::unique_ptr<TestContentClientInitializer> content_initializer_;
68 base::TestDiscardableMemoryAllocator discardable_memory_allocator_; 68 base::TestDiscardableMemoryAllocator discardable_memory_allocator_;
69 }; 69 };
70 70
71 TestEnvironment* test_environment; 71 TestEnvironment* test_environment;
72 72
73 } // namespace 73 } // namespace
74 74
75 void SetUpBlinkTestEnvironment() { 75 void SetUpBlinkTestEnvironment() {
(...skipping 20 matching lines...) Expand all
96 // http://code.google.com/p/chromium/issues/detail?id=9500 96 // http://code.google.com/p/chromium/issues/detail?id=9500
97 base::RunLoop().RunUntilIdle(); 97 base::RunLoop().RunUntilIdle();
98 98
99 if (RunningOnValgrind()) 99 if (RunningOnValgrind())
100 blink::WebCache::Clear(); 100 blink::WebCache::Clear();
101 delete test_environment; 101 delete test_environment;
102 test_environment = NULL; 102 test_environment = NULL;
103 } 103 }
104 104
105 } // namespace content 105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698