| 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 "bindings/core/v8/V8BindingForCore.h" | 5 #include "bindings/core/v8/V8BindingForCore.h" |
| 6 #include "core/frame/UseCounter.h" | 6 #include "core/frame/UseCounter.h" |
| 7 #include "core/testing/DummyPageHolder.h" | 7 #include "core/testing/DummyPageHolder.h" |
| 8 #include "core/workers/MainThreadWorkletGlobalScope.h" | 8 #include "core/workers/MainThreadWorkletGlobalScope.h" |
| 9 #include "platform/weborigin/SecurityOrigin.h" | 9 #include "platform/weborigin/SecurityOrigin.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class MainThreadWorkletGlobalScopeForTest |
| 15 : public MainThreadWorkletGlobalScope { |
| 16 public: |
| 17 MainThreadWorkletGlobalScopeForTest(LocalFrame* frame, |
| 18 const KURL& url, |
| 19 const String& user_agent, |
| 20 RefPtr<SecurityOrigin> security_origin, |
| 21 v8::Isolate* isolate) |
| 22 : MainThreadWorkletGlobalScope(frame, |
| 23 url, |
| 24 user_agent, |
| 25 std::move(security_origin), |
| 26 isolate), |
| 27 reported_features_(UseCounter::kNumberOfFeatures) {} |
| 28 |
| 29 void ReportFeature(UseCounter::Feature feature) override { |
| 30 // Any feature should be reported only one time. |
| 31 EXPECT_FALSE(reported_features_.QuickGet(feature)); |
| 32 reported_features_.QuickSet(feature); |
| 33 MainThreadWorkletGlobalScope::ReportFeature(feature); |
| 34 } |
| 35 |
| 36 void ReportDeprecation(UseCounter::Feature feature) final { |
| 37 // Any feature should be reported only one time. |
| 38 EXPECT_FALSE(reported_features_.QuickGet(feature)); |
| 39 reported_features_.QuickSet(feature); |
| 40 MainThreadWorkletGlobalScope::ReportDeprecation(feature); |
| 41 } |
| 42 |
| 43 private: |
| 44 BitVector reported_features_; |
| 45 }; |
| 46 |
| 14 class MainThreadWorkletTest : public ::testing::Test { | 47 class MainThreadWorkletTest : public ::testing::Test { |
| 15 public: | 48 public: |
| 16 void SetUp() override { | 49 void SetUp() override { |
| 17 KURL url(kParsedURLString, "https://example.com/"); | 50 KURL url(kParsedURLString, "https://example.com/"); |
| 18 page_ = DummyPageHolder::Create(); | 51 page_ = DummyPageHolder::Create(); |
| 19 security_origin_ = SecurityOrigin::Create(url); | 52 security_origin_ = SecurityOrigin::Create(url); |
| 20 global_scope_ = new MainThreadWorkletGlobalScope( | 53 global_scope_ = new MainThreadWorkletGlobalScope( |
| 21 &page_->GetFrame(), url, "fake user agent", security_origin_.Get(), | 54 &page_->GetFrame(), url, "fake user agent", security_origin_.Get(), |
| 22 ToIsolate(page_->GetFrame().GetDocument())); | 55 ToIsolate(page_->GetFrame().GetDocument())); |
| 23 } | 56 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 | 68 |
| 36 // This feature is randomly selected. | 69 // This feature is randomly selected. |
| 37 const UseCounter::Feature kFeature1 = UseCounter::Feature::kRequestFileSystem; | 70 const UseCounter::Feature kFeature1 = UseCounter::Feature::kRequestFileSystem; |
| 38 | 71 |
| 39 // API use on the MainThreadWorkletGlobalScope should be recorded in | 72 // API use on the MainThreadWorkletGlobalScope should be recorded in |
| 40 // UseCounter on the Document. | 73 // UseCounter on the Document. |
| 41 EXPECT_FALSE(UseCounter::IsCounted(document, kFeature1)); | 74 EXPECT_FALSE(UseCounter::IsCounted(document, kFeature1)); |
| 42 UseCounter::Count(global_scope_, kFeature1); | 75 UseCounter::Count(global_scope_, kFeature1); |
| 43 EXPECT_TRUE(UseCounter::IsCounted(document, kFeature1)); | 76 EXPECT_TRUE(UseCounter::IsCounted(document, kFeature1)); |
| 44 | 77 |
| 78 // API use should be reported to the Document only one time. See comments in |
| 79 // MainThreadGlobalScopeForTest::ReportFeature. |
| 80 UseCounter::Count(global_scope_, kFeature1); |
| 81 |
| 45 // This feature is randomly selected from Deprecation::deprecationMessage(). | 82 // This feature is randomly selected from Deprecation::deprecationMessage(). |
| 46 const UseCounter::Feature kFeature2 = | 83 const UseCounter::Feature kFeature2 = |
| 47 UseCounter::Feature::kPrefixedStorageInfo; | 84 UseCounter::Feature::kPrefixedStorageInfo; |
| 48 | 85 |
| 49 // Deprecated API use on the MainThreadWorkletGlobalScope should be recorded | 86 // Deprecated API use on the MainThreadWorkletGlobalScope should be recorded |
| 50 // in UseCounter on the Document. | 87 // in UseCounter on the Document. |
| 51 EXPECT_FALSE(UseCounter::IsCounted(document, kFeature2)); | 88 EXPECT_FALSE(UseCounter::IsCounted(document, kFeature2)); |
| 52 Deprecation::CountDeprecation(global_scope_, kFeature2); | 89 Deprecation::CountDeprecation(global_scope_, kFeature2); |
| 53 EXPECT_TRUE(UseCounter::IsCounted(document, kFeature2)); | 90 EXPECT_TRUE(UseCounter::IsCounted(document, kFeature2)); |
| 91 |
| 92 // API use should be reported to the Document only one time. See comments in |
| 93 // MainThreadWorkletGlobalScopeForTest::ReportDeprecation. |
| 94 Deprecation::CountDeprecation(global_scope_, kFeature2); |
| 54 } | 95 } |
| 55 | 96 |
| 56 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |