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 <memory> |
| 6 #include "core/dom/TaskRunnerHelper.h" |
5 #include "core/events/MessageEvent.h" | 7 #include "core/events/MessageEvent.h" |
6 #include "core/inspector/ConsoleMessageStorage.h" | 8 #include "core/inspector/ConsoleMessageStorage.h" |
7 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
8 #include "core/workers/DedicatedWorkerGlobalScope.h" | 10 #include "core/workers/DedicatedWorkerGlobalScope.h" |
9 #include "core/workers/DedicatedWorkerThread.h" | 11 #include "core/workers/DedicatedWorkerThread.h" |
10 #include "core/workers/InProcessWorkerMessagingProxy.h" | 12 #include "core/workers/InProcessWorkerMessagingProxy.h" |
11 #include "core/workers/InProcessWorkerObjectProxy.h" | 13 #include "core/workers/InProcessWorkerObjectProxy.h" |
12 #include "core/workers/WorkerInspectorProxy.h" | 14 #include "core/workers/WorkerInspectorProxy.h" |
13 #include "core/workers/WorkerThread.h" | 15 #include "core/workers/WorkerThread.h" |
14 #include "core/workers/WorkerThreadStartupData.h" | 16 #include "core/workers/WorkerThreadStartupData.h" |
15 #include "core/workers/WorkerThreadTestHelper.h" | 17 #include "core/workers/WorkerThreadTestHelper.h" |
16 #include "platform/CrossThreadFunctional.h" | 18 #include "platform/CrossThreadFunctional.h" |
17 #include "platform/testing/UnitTestHelpers.h" | 19 #include "platform/testing/UnitTestHelpers.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 #include <memory> | |
21 | 22 |
22 namespace blink { | 23 namespace blink { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // These are chosen by trial-and-error. Making these intervals smaller causes | 27 // These are chosen by trial-and-error. Making these intervals smaller causes |
27 // test flakiness. The main thread needs to wait until message confirmation and | 28 // test flakiness. The main thread needs to wait until message confirmation and |
28 // activity report separately. If the intervals are very short, they are | 29 // activity report separately. If the intervals are very short, they are |
29 // notified to the main thread almost at the same time and the thread may miss | 30 // notified to the main thread almost at the same time and the thread may miss |
30 // the second notification. | 31 // the second notification. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 TEST_F(DedicatedWorkerTest, UseCounter) { | 382 TEST_F(DedicatedWorkerTest, UseCounter) { |
382 const String source_code = "// Do nothing"; | 383 const String source_code = "// Do nothing"; |
383 WorkerMessagingProxy()->StartWithSourceCode(source_code); | 384 WorkerMessagingProxy()->StartWithSourceCode(source_code); |
384 | 385 |
385 // This feature is randomly selected. | 386 // This feature is randomly selected. |
386 const UseCounter::Feature kFeature1 = UseCounter::Feature::kRequestFileSystem; | 387 const UseCounter::Feature kFeature1 = UseCounter::Feature::kRequestFileSystem; |
387 | 388 |
388 // API use on the DedicatedWorkerGlobalScope should be recorded in UseCounter | 389 // API use on the DedicatedWorkerGlobalScope should be recorded in UseCounter |
389 // on the Document. | 390 // on the Document. |
390 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1)); | 391 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1)); |
391 GetWorkerThread()->PostTask( | 392 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread()) |
392 BLINK_FROM_HERE, | 393 ->PostTask( |
393 CrossThreadBind(&DedicatedWorkerThreadForTest::CountFeature, | 394 BLINK_FROM_HERE, |
394 CrossThreadUnretained(GetWorkerThread()), kFeature1)); | 395 CrossThreadBind(&DedicatedWorkerThreadForTest::CountFeature, |
| 396 CrossThreadUnretained(GetWorkerThread()), kFeature1)); |
395 testing::EnterRunLoop(); | 397 testing::EnterRunLoop(); |
396 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature1)); | 398 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature1)); |
397 | 399 |
398 // This feature is randomly selected from Deprecation::deprecationMessage(). | 400 // This feature is randomly selected from Deprecation::deprecationMessage(). |
399 const UseCounter::Feature kFeature2 = | 401 const UseCounter::Feature kFeature2 = |
400 UseCounter::Feature::kPrefixedStorageInfo; | 402 UseCounter::Feature::kPrefixedStorageInfo; |
401 | 403 |
402 // Deprecated API use on the DedicatedWorkerGlobalScope should be recorded in | 404 // Deprecated API use on the DedicatedWorkerGlobalScope should be recorded in |
403 // UseCounter on the Document. | 405 // UseCounter on the Document. |
404 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2)); | 406 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2)); |
405 GetWorkerThread()->PostTask( | 407 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread()) |
406 BLINK_FROM_HERE, | 408 ->PostTask( |
407 CrossThreadBind(&DedicatedWorkerThreadForTest::CountDeprecation, | 409 BLINK_FROM_HERE, |
408 CrossThreadUnretained(GetWorkerThread()), kFeature2)); | 410 CrossThreadBind(&DedicatedWorkerThreadForTest::CountDeprecation, |
| 411 CrossThreadUnretained(GetWorkerThread()), kFeature2)); |
409 testing::EnterRunLoop(); | 412 testing::EnterRunLoop(); |
410 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2)); | 413 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2)); |
411 } | 414 } |
412 | 415 |
413 } // namespace blink | 416 } // namespace blink |
OLD | NEW |