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

Side by Side Diff: third_party/WebKit/Source/core/workers/DedicatedWorkerTest.cpp

Issue 2857583003: Worker: Avoid sending IPC messages for features already counted (Closed)
Patch Set: wip 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 5 #include <memory>
6 #include "core/dom/TaskRunnerHelper.h" 6 #include "core/dom/TaskRunnerHelper.h"
7 #include "core/events/MessageEvent.h" 7 #include "core/events/MessageEvent.h"
8 #include "core/inspector/ConsoleMessageStorage.h" 8 #include "core/inspector/ConsoleMessageStorage.h"
9 #include "core/testing/DummyPageHolder.h" 9 #include "core/testing/DummyPageHolder.h"
10 #include "core/workers/DedicatedWorkerGlobalScope.h" 10 #include "core/workers/DedicatedWorkerGlobalScope.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 EXPECT_TRUE(IsCurrentThread()); 60 EXPECT_TRUE(IsCurrentThread());
61 GlobalScope()->CountFeature(feature); 61 GlobalScope()->CountFeature(feature);
62 GetParentFrameTaskRunners() 62 GetParentFrameTaskRunners()
63 ->Get(TaskType::kUnspecedTimer) 63 ->Get(TaskType::kUnspecedTimer)
64 ->PostTask(BLINK_FROM_HERE, CrossThreadBind(&testing::ExitRunLoop)); 64 ->PostTask(BLINK_FROM_HERE, CrossThreadBind(&testing::ExitRunLoop));
65 } 65 }
66 66
67 // Emulates deprecated API use on DedicatedWorkerGlobalScope. 67 // Emulates deprecated API use on DedicatedWorkerGlobalScope.
68 void CountDeprecation(UseCounter::Feature feature) { 68 void CountDeprecation(UseCounter::Feature feature) {
69 EXPECT_TRUE(IsCurrentThread()); 69 EXPECT_TRUE(IsCurrentThread());
70 EXPECT_EQ(0u, GetConsoleMessageStorage()->size());
71 GlobalScope()->CountDeprecation(feature); 70 GlobalScope()->CountDeprecation(feature);
72 71
73 // countDeprecation() should add a warning message. 72 // countDeprecation() should add a warning message.
74 EXPECT_EQ(1u, GetConsoleMessageStorage()->size()); 73 EXPECT_EQ(1u, GetConsoleMessageStorage()->size());
75 String console_message = GetConsoleMessageStorage()->at(0)->Message(); 74 String console_message = GetConsoleMessageStorage()->at(0)->Message();
76 EXPECT_TRUE(console_message.Contains("deprecated")); 75 EXPECT_TRUE(console_message.Contains("deprecated"));
77 76
78 GetParentFrameTaskRunners() 77 GetParentFrameTaskRunners()
79 ->Get(TaskType::kUnspecedTimer) 78 ->Get(TaskType::kUnspecedTimer)
80 ->PostTask(BLINK_FROM_HERE, CrossThreadBind(&testing::ExitRunLoop)); 79 ->PostTask(BLINK_FROM_HERE, CrossThreadBind(&testing::ExitRunLoop));
81 } 80 }
82 }; 81 };
83 82
83 class InProcessWorkerObjectProxyForTest final
84 : public InProcessWorkerObjectProxy {
85 public:
86 InProcessWorkerObjectProxyForTest(
87 const WeakPtr<InProcessWorkerMessagingProxy>& messaging_proxy_weak_ptr,
88 ParentFrameTaskRunners* parent_frame_task_runners)
89 : InProcessWorkerObjectProxy(messaging_proxy_weak_ptr,
90 parent_frame_task_runners),
91 reported_features_(UseCounter::kNumberOfFeatures) {
92 default_interval_in_sec_ = kDefaultIntervalInSec;
93 next_interval_in_sec_ = kNextIntervalInSec;
94 max_interval_in_sec_ = kMaxIntervalInSec;
95 }
96
97 void CountFeature(UseCounter::Feature feature) override {
98 // Any feature should be reported only one time.
99 EXPECT_FALSE(reported_features_.QuickGet(feature));
100 reported_features_.QuickSet(feature);
101 InProcessWorkerObjectProxy::CountFeature(feature);
102 }
103
104 void CountDeprecation(UseCounter::Feature feature) override {
105 // Any feature should be reported only one time.
106 EXPECT_FALSE(reported_features_.QuickGet(feature));
107 reported_features_.QuickSet(feature);
108 InProcessWorkerObjectProxy::CountDeprecation(feature);
109 }
110
111 private:
112 BitVector reported_features_;
113 };
114
84 class InProcessWorkerMessagingProxyForTest 115 class InProcessWorkerMessagingProxyForTest
85 : public InProcessWorkerMessagingProxy { 116 : public InProcessWorkerMessagingProxy {
86 public: 117 public:
87 InProcessWorkerMessagingProxyForTest(ExecutionContext* execution_context) 118 InProcessWorkerMessagingProxyForTest(ExecutionContext* execution_context)
88 : InProcessWorkerMessagingProxy(execution_context, 119 : InProcessWorkerMessagingProxy(execution_context,
89 nullptr /* workerObject */, 120 nullptr /* workerObject */,
90 nullptr /* workerClients */) { 121 nullptr /* workerClients */) {
91 WorkerObjectProxy().default_interval_in_sec_ = kDefaultIntervalInSec; 122 worker_object_proxy_ = WTF::MakeUnique<InProcessWorkerObjectProxyForTest>(
92 WorkerObjectProxy().next_interval_in_sec_ = kNextIntervalInSec; 123 weak_ptr_factory_.CreateWeakPtr(), GetParentFrameTaskRunners());
93 WorkerObjectProxy().max_interval_in_sec_ = kMaxIntervalInSec;
94
95 worker_loader_proxy_provider_ = 124 worker_loader_proxy_provider_ =
96 WTF::MakeUnique<WorkerLoaderProxyProvider>(); 125 WTF::MakeUnique<WorkerLoaderProxyProvider>();
97 worker_thread_ = WTF::WrapUnique(new DedicatedWorkerThreadForTest( 126 worker_thread_ = WTF::WrapUnique(new DedicatedWorkerThreadForTest(
98 worker_loader_proxy_provider_.get(), WorkerObjectProxy())); 127 worker_loader_proxy_provider_.get(), WorkerObjectProxy()));
99 mock_worker_thread_lifecycle_observer_ = 128 mock_worker_thread_lifecycle_observer_ =
100 new MockWorkerThreadLifecycleObserver( 129 new MockWorkerThreadLifecycleObserver(
101 worker_thread_->GetWorkerThreadLifecycleContext()); 130 worker_thread_->GetWorkerThreadLifecycleContext());
102 EXPECT_CALL(*mock_worker_thread_lifecycle_observer_, 131 EXPECT_CALL(*mock_worker_thread_lifecycle_observer_,
103 ContextDestroyed(::testing::_)) 132 ContextDestroyed(::testing::_))
104 .Times(1); 133 .Times(1);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // on the Document. 421 // on the Document.
393 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1)); 422 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1));
394 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread()) 423 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread())
395 ->PostTask( 424 ->PostTask(
396 BLINK_FROM_HERE, 425 BLINK_FROM_HERE,
397 CrossThreadBind(&DedicatedWorkerThreadForTest::CountFeature, 426 CrossThreadBind(&DedicatedWorkerThreadForTest::CountFeature,
398 CrossThreadUnretained(GetWorkerThread()), kFeature1)); 427 CrossThreadUnretained(GetWorkerThread()), kFeature1));
399 testing::EnterRunLoop(); 428 testing::EnterRunLoop();
400 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature1)); 429 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature1));
401 430
431 // API use should be reported to the Document only one time. See comments in
432 // InProcessWorkerObjectProxyForTest::CountFeature.
433 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread())
434 ->PostTask(
435 BLINK_FROM_HERE,
436 CrossThreadBind(&DedicatedWorkerThreadForTest::CountFeature,
437 CrossThreadUnretained(GetWorkerThread()), kFeature1));
438 testing::EnterRunLoop();
439
402 // This feature is randomly selected from Deprecation::deprecationMessage(). 440 // This feature is randomly selected from Deprecation::deprecationMessage().
403 const UseCounter::Feature kFeature2 = 441 const UseCounter::Feature kFeature2 =
404 UseCounter::Feature::kPrefixedStorageInfo; 442 UseCounter::Feature::kPrefixedStorageInfo;
405 443
406 // Deprecated API use on the DedicatedWorkerGlobalScope should be recorded in 444 // Deprecated API use on the DedicatedWorkerGlobalScope should be recorded in
407 // UseCounter on the Document. 445 // UseCounter on the Document.
408 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2)); 446 EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2));
409 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread()) 447 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread())
410 ->PostTask( 448 ->PostTask(
411 BLINK_FROM_HERE, 449 BLINK_FROM_HERE,
412 CrossThreadBind(&DedicatedWorkerThreadForTest::CountDeprecation, 450 CrossThreadBind(&DedicatedWorkerThreadForTest::CountDeprecation,
413 CrossThreadUnretained(GetWorkerThread()), kFeature2)); 451 CrossThreadUnretained(GetWorkerThread()), kFeature2));
414 testing::EnterRunLoop(); 452 testing::EnterRunLoop();
415 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2)); 453 EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2));
454
455 // API use should be reported to the Document only one time. See comments in
456 // InProcessWorkerObjectProxyForTest::CountDeprecation.
457 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, GetWorkerThread())
458 ->PostTask(
459 BLINK_FROM_HERE,
460 CrossThreadBind(&DedicatedWorkerThreadForTest::CountDeprecation,
461 CrossThreadUnretained(GetWorkerThread()), kFeature2));
462 testing::EnterRunLoop();
416 } 463 }
417 464
418 } // namespace blink 465 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698