| 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/timing/PerformanceObserver.h" | 5 #include "core/timing/PerformanceObserver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/PerformanceObserverCallback.h" | 7 #include "bindings/core/v8/PerformanceObserverCallback.h" |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/dom/ExecutionContext.h" |
| 9 #include "core/dom/TaskRunnerHelper.h" | 10 #include "core/dom/TaskRunnerHelper.h" |
| 10 #include "core/timing/Performance.h" | 11 #include "core/timing/Performance.h" |
| 11 #include "core/timing/PerformanceBase.h" | 12 #include "core/timing/PerformanceBase.h" |
| 12 #include "core/timing/PerformanceMark.h" | 13 #include "core/timing/PerformanceMark.h" |
| 13 #include "core/timing/PerformanceObserverInit.h" | 14 #include "core/timing/PerformanceObserverInit.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 class MockPerformanceBase : public PerformanceBase { | 19 class MockPerformanceBase : public PerformanceBase { |
| 19 public: | 20 public: |
| 20 explicit MockPerformanceBase(ScriptState* script_state) | 21 explicit MockPerformanceBase(ScriptState* script_state) |
| 21 : PerformanceBase(0, | 22 : PerformanceBase(0, |
| 22 TaskRunnerHelper::Get(TaskType::kPerformanceTimeline, | 23 TaskRunnerHelper::Get(TaskType::kPerformanceTimeline, |
| 23 script_state)) {} | 24 script_state)) {} |
| 24 ~MockPerformanceBase() {} | 25 ~MockPerformanceBase() {} |
| 25 | 26 |
| 26 ExecutionContext* GetExecutionContext() const override { return nullptr; } | 27 ExecutionContext* GetExecutionContext() const override { return nullptr; } |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 class PerformanceObserverTest : public ::testing::Test { | 30 class PerformanceObserverTest : public ::testing::Test { |
| 30 protected: | 31 protected: |
| 31 void Initialize(ScriptState* script_state) { | 32 void Initialize(ScriptState* script_state) { |
| 32 v8::Local<v8::Function> callback = | 33 v8::Local<v8::Function> callback = |
| 33 v8::Function::New(script_state->GetContext(), nullptr).ToLocalChecked(); | 34 v8::Function::New(script_state->GetContext(), nullptr).ToLocalChecked(); |
| 34 base_ = new MockPerformanceBase(script_state); | 35 base_ = new MockPerformanceBase(script_state); |
| 35 cb_ = PerformanceObserverCallback::Create(script_state, callback); | 36 cb_ = PerformanceObserverCallback::Create(script_state, callback); |
| 36 observer_ = PerformanceObserver::Create(script_state->GetExecutionContext(), | 37 observer_ = PerformanceObserver::Create( |
| 37 base_, cb_); | 38 ExecutionContext::From(script_state), base_, cb_); |
| 38 } | 39 } |
| 39 | 40 |
| 40 bool IsRegistered() { return observer_->is_registered_; } | 41 bool IsRegistered() { return observer_->is_registered_; } |
| 41 int NumPerformanceEntries() { return observer_->performance_entries_.size(); } | 42 int NumPerformanceEntries() { return observer_->performance_entries_.size(); } |
| 42 void Deliver() { observer_->Deliver(); } | 43 void Deliver() { observer_->Deliver(); } |
| 43 | 44 |
| 44 Persistent<MockPerformanceBase> base_; | 45 Persistent<MockPerformanceBase> base_; |
| 45 Persistent<PerformanceObserverCallback> cb_; | 46 Persistent<PerformanceObserverCallback> cb_; |
| 46 Persistent<PerformanceObserver> observer_; | 47 Persistent<PerformanceObserver> observer_; |
| 47 }; | 48 }; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 EXPECT_EQ(0, NumPerformanceEntries()); | 94 EXPECT_EQ(0, NumPerformanceEntries()); |
| 94 | 95 |
| 95 observer_->EnqueuePerformanceEntry(*entry); | 96 observer_->EnqueuePerformanceEntry(*entry); |
| 96 EXPECT_EQ(1, NumPerformanceEntries()); | 97 EXPECT_EQ(1, NumPerformanceEntries()); |
| 97 | 98 |
| 98 observer_->disconnect(); | 99 observer_->disconnect(); |
| 99 EXPECT_FALSE(IsRegistered()); | 100 EXPECT_FALSE(IsRegistered()); |
| 100 EXPECT_EQ(0, NumPerformanceEntries()); | 101 EXPECT_EQ(0, NumPerformanceEntries()); |
| 101 } | 102 } |
| 102 } | 103 } |
| OLD | NEW |