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 "core/inspector/ConsoleMessageStorage.h" | 5 #include "core/inspector/ConsoleMessageStorage.h" |
6 #include "core/testing/DummyPageHolder.h" | 6 #include "core/testing/DummyPageHolder.h" |
7 #include "core/workers/ThreadedWorkletGlobalScope.h" | 7 #include "core/workers/ThreadedWorkletGlobalScope.h" |
8 #include "core/workers/ThreadedWorkletMessagingProxy.h" | 8 #include "core/workers/ThreadedWorkletMessagingProxy.h" |
9 #include "core/workers/ThreadedWorkletObjectProxy.h" | 9 #include "core/workers/ThreadedWorkletObjectProxy.h" |
10 #include "core/workers/WorkerInspectorProxy.h" | 10 #include "core/workers/WorkerInspectorProxy.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 static void clearSharedBackingThread() { | 57 static void clearSharedBackingThread() { |
58 DCHECK(isMainThread()); | 58 DCHECK(isMainThread()); |
59 WorkletThreadHolder<ThreadedWorkletThreadForTest>::clearInstance(); | 59 WorkletThreadHolder<ThreadedWorkletThreadForTest>::clearInstance(); |
60 } | 60 } |
61 | 61 |
62 // Emulates API use on ThreadedWorkletGlobalScope. | 62 // Emulates API use on ThreadedWorkletGlobalScope. |
63 void countFeature(UseCounter::Feature feature) { | 63 void countFeature(UseCounter::Feature feature) { |
64 EXPECT_TRUE(isCurrentThread()); | 64 EXPECT_TRUE(isCurrentThread()); |
65 globalScope()->countFeature(feature); | 65 globalScope()->countFeature(feature); |
66 getParentFrameTaskRunners() | 66 FrameTaskRunnerHelper::get(TaskType::UnspecedTimer, globalScope()) |
67 ->get(TaskType::UnspecedTimer) | |
68 ->postTask(BLINK_FROM_HERE, crossThreadBind(&testing::exitRunLoop)); | 67 ->postTask(BLINK_FROM_HERE, crossThreadBind(&testing::exitRunLoop)); |
69 } | 68 } |
70 | 69 |
71 // Emulates deprecated API use on ThreadedWorkletGlobalScope. | 70 // Emulates deprecated API use on ThreadedWorkletGlobalScope. |
72 void countDeprecation(UseCounter::Feature feature) { | 71 void countDeprecation(UseCounter::Feature feature) { |
73 EXPECT_TRUE(isCurrentThread()); | 72 EXPECT_TRUE(isCurrentThread()); |
74 EXPECT_EQ(0u, consoleMessageStorage()->size()); | 73 EXPECT_EQ(0u, consoleMessageStorage()->size()); |
75 globalScope()->countDeprecation(feature); | 74 globalScope()->countDeprecation(feature); |
76 | 75 |
77 // countDeprecation() should add a warning message. | 76 // countDeprecation() should add a warning message. |
78 EXPECT_EQ(1u, consoleMessageStorage()->size()); | 77 EXPECT_EQ(1u, consoleMessageStorage()->size()); |
79 String consoleMessage = consoleMessageStorage()->at(0)->message(); | 78 String consoleMessage = consoleMessageStorage()->at(0)->message(); |
80 EXPECT_TRUE(consoleMessage.contains("deprecated")); | 79 EXPECT_TRUE(consoleMessage.contains("deprecated")); |
81 | 80 |
82 getParentFrameTaskRunners() | 81 FrameTaskRunnerHelper::get(TaskType::UnspecedTimer, globalScope()) |
83 ->get(TaskType::UnspecedTimer) | |
84 ->postTask(BLINK_FROM_HERE, crossThreadBind(&testing::exitRunLoop)); | 82 ->postTask(BLINK_FROM_HERE, crossThreadBind(&testing::exitRunLoop)); |
85 } | 83 } |
86 }; | 84 }; |
87 | 85 |
88 class ThreadedWorkletMessagingProxyForTest | 86 class ThreadedWorkletMessagingProxyForTest |
89 : public ThreadedWorkletMessagingProxy { | 87 : public ThreadedWorkletMessagingProxy { |
90 public: | 88 public: |
91 ThreadedWorkletMessagingProxyForTest(ExecutionContext* executionContext) | 89 ThreadedWorkletMessagingProxyForTest(ExecutionContext* executionContext) |
92 : ThreadedWorkletMessagingProxy(executionContext) { | 90 : ThreadedWorkletMessagingProxy(executionContext) { |
93 m_mockWorkerLoaderProxyProvider = | 91 m_mockWorkerLoaderProxyProvider = |
94 WTF::makeUnique<MockWorkerLoaderProxyProvider>(); | 92 WTF::makeUnique<MockWorkerLoaderProxyProvider>(); |
95 m_workerThread = WTF::makeUnique<ThreadedWorkletThreadForTest>( | 93 m_workerThread = WTF::makeUnique<ThreadedWorkletThreadForTest>( |
96 m_mockWorkerLoaderProxyProvider.get(), workletObjectProxy()); | 94 m_mockWorkerLoaderProxyProvider.get(), workletObjectProxy()); |
97 ThreadedWorkletThreadForTest::ensureSharedBackingThread(); | 95 ThreadedWorkletThreadForTest::ensureSharedBackingThread(); |
98 } | 96 } |
99 | 97 |
100 ~ThreadedWorkletMessagingProxyForTest() override { | 98 ~ThreadedWorkletMessagingProxyForTest() override { |
101 m_workerThread->workerLoaderProxy()->detachProvider( | 99 m_workerThread->workerLoaderProxy()->detachProvider( |
102 m_mockWorkerLoaderProxyProvider.get()); | 100 m_mockWorkerLoaderProxyProvider.get()); |
103 m_workerThread->terminateAndWait(); | 101 m_workerThread->terminateAndWait(); |
104 ThreadedWorkletThreadForTest::clearSharedBackingThread(); | 102 ThreadedWorkletThreadForTest::clearSharedBackingThread(); |
105 }; | 103 }; |
106 | 104 |
107 void start() { | 105 void start(Document& document) { |
108 KURL scriptURL(ParsedURLString, "http://fake.url/"); | 106 KURL scriptURL(ParsedURLString, "http://fake.url/"); |
109 std::unique_ptr<Vector<char>> cachedMetaData = nullptr; | 107 std::unique_ptr<Vector<char>> cachedMetaData = nullptr; |
110 Vector<CSPHeaderAndType> contentSecurityPolicyHeaders; | 108 Vector<CSPHeaderAndType> contentSecurityPolicyHeaders; |
111 String referrerPolicy = ""; | 109 String referrerPolicy = ""; |
112 m_securityOrigin = SecurityOrigin::create(scriptURL); | 110 m_securityOrigin = SecurityOrigin::create(scriptURL); |
113 WorkerClients* workerClients = nullptr; | 111 WorkerClients* workerClients = nullptr; |
114 Vector<String> originTrialTokens; | 112 Vector<String> originTrialTokens; |
115 std::unique_ptr<WorkerSettings> workerSettings = nullptr; | 113 std::unique_ptr<WorkerSettings> workerSettings = nullptr; |
116 m_workerThread->start( | 114 m_workerThread->start( |
117 WorkerThreadStartupData::create( | 115 WorkerThreadStartupData::create( |
118 scriptURL, "fake user agent", "// fake source code", | 116 scriptURL, "fake user agent", "// fake source code", |
119 std::move(cachedMetaData), DontPauseWorkerGlobalScopeOnStart, | 117 std::move(cachedMetaData), DontPauseWorkerGlobalScopeOnStart, |
120 &contentSecurityPolicyHeaders, referrerPolicy, | 118 &contentSecurityPolicyHeaders, referrerPolicy, |
121 m_securityOrigin.get(), workerClients, WebAddressSpaceLocal, | 119 m_securityOrigin.get(), workerClients, WebAddressSpaceLocal, |
122 &originTrialTokens, std::move(workerSettings), | 120 &originTrialTokens, std::move(workerSettings), |
123 WorkerV8Settings::Default()), | 121 WorkerV8Settings::Default()), |
124 getParentFrameTaskRunners()); | 122 FrameTaskRunnersHolder::create(document.frame())); |
125 workerInspectorProxy()->workerThreadCreated( | 123 workerInspectorProxy()->workerThreadCreated( |
126 toDocument(getExecutionContext()), m_workerThread.get(), scriptURL); | 124 toDocument(getExecutionContext()), m_workerThread.get(), scriptURL); |
127 } | 125 } |
128 | 126 |
129 protected: | 127 protected: |
130 std::unique_ptr<WorkerThread> createWorkerThread(double originTime) final { | 128 std::unique_ptr<WorkerThread> createWorkerThread(double originTime) final { |
131 NOTREACHED(); | 129 NOTREACHED(); |
132 return nullptr; | 130 return nullptr; |
133 } | 131 } |
134 | 132 |
(...skipping 23 matching lines...) Expand all Loading... |
158 } | 156 } |
159 | 157 |
160 Document& document() { return m_page->document(); } | 158 Document& document() { return m_page->document(); } |
161 | 159 |
162 private: | 160 private: |
163 std::unique_ptr<DummyPageHolder> m_page; | 161 std::unique_ptr<DummyPageHolder> m_page; |
164 std::unique_ptr<ThreadedWorkletMessagingProxyForTest> m_messagingProxy; | 162 std::unique_ptr<ThreadedWorkletMessagingProxyForTest> m_messagingProxy; |
165 }; | 163 }; |
166 | 164 |
167 TEST_F(ThreadedWorkletTest, UseCounter) { | 165 TEST_F(ThreadedWorkletTest, UseCounter) { |
168 messagingProxy()->start(); | 166 messagingProxy()->start(document()); |
169 | 167 |
170 // This feature is randomly selected. | 168 // This feature is randomly selected. |
171 const UseCounter::Feature feature1 = UseCounter::Feature::RequestFileSystem; | 169 const UseCounter::Feature feature1 = UseCounter::Feature::RequestFileSystem; |
172 | 170 |
173 // API use on the DedicatedWorkerGlobalScope should be recorded in UseCounter | 171 // API use on the DedicatedWorkerGlobalScope should be recorded in UseCounter |
174 // on the Document. | 172 // on the Document. |
175 EXPECT_FALSE(UseCounter::isCounted(document(), feature1)); | 173 EXPECT_FALSE(UseCounter::isCounted(document(), feature1)); |
176 workerThread()->postTask( | 174 workerThread()->postTask( |
177 BLINK_FROM_HERE, | 175 BLINK_FROM_HERE, |
178 crossThreadBind(&ThreadedWorkletThreadForTest::countFeature, | 176 crossThreadBind(&ThreadedWorkletThreadForTest::countFeature, |
179 crossThreadUnretained(workerThread()), feature1)); | 177 crossThreadUnretained(workerThread()), feature1)); |
180 testing::enterRunLoop(); | 178 testing::enterRunLoop(); |
181 EXPECT_TRUE(UseCounter::isCounted(document(), feature1)); | 179 EXPECT_TRUE(UseCounter::isCounted(document(), feature1)); |
182 | 180 |
183 // This feature is randomly selected from Deprecation::deprecationMessage(). | 181 // This feature is randomly selected from Deprecation::deprecationMessage(). |
184 const UseCounter::Feature feature2 = UseCounter::Feature::PrefixedStorageInfo; | 182 const UseCounter::Feature feature2 = UseCounter::Feature::PrefixedStorageInfo; |
185 | 183 |
186 // Deprecated API use on the ThreadedWorkletGlobalScope should be recorded in | 184 // Deprecated API use on the ThreadedWorkletGlobalScope should be recorded in |
187 // UseCounter on the Document. | 185 // UseCounter on the Document. |
188 EXPECT_FALSE(UseCounter::isCounted(document(), feature2)); | 186 EXPECT_FALSE(UseCounter::isCounted(document(), feature2)); |
189 workerThread()->postTask( | 187 workerThread()->postTask( |
190 BLINK_FROM_HERE, | 188 BLINK_FROM_HERE, |
191 crossThreadBind(&ThreadedWorkletThreadForTest::countDeprecation, | 189 crossThreadBind(&ThreadedWorkletThreadForTest::countDeprecation, |
192 crossThreadUnretained(workerThread()), feature2)); | 190 crossThreadUnretained(workerThread()), feature2)); |
193 testing::enterRunLoop(); | 191 testing::enterRunLoop(); |
194 EXPECT_TRUE(UseCounter::isCounted(document(), feature2)); | 192 EXPECT_TRUE(UseCounter::isCounted(document(), feature2)); |
195 } | 193 } |
196 | 194 |
197 } // namespace blink | 195 } // namespace blink |
OLD | NEW |