| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/V8ScriptRunner.h" | 5 #include "bindings/core/v8/V8ScriptRunner.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8Binding.h" | 7 #include "bindings/core/v8/V8Binding.h" |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/fetch/CachedMetadataHandler.h" | 9 #include "core/fetch/CachedMetadataHandler.h" |
| 10 #include "core/fetch/ScriptResource.h" | 10 #include "core/fetch/ScriptResource.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 { | 66 { |
| 67 return !V8ScriptRunner::compileScript( | 67 return !V8ScriptRunner::compileScript( |
| 68 v8String(isolate(), code()), filename(), String(), WTF::TextPosition
(), | 68 v8String(isolate(), code()), filename(), String(), WTF::TextPosition
(), |
| 69 isolate(), m_resource.get(), nullptr, m_resource.get() ? m_resource-
>cacheHandler(): nullptr, NotSharableCrossOrigin, cacheOptions) | 69 isolate(), m_resource.get(), nullptr, m_resource.get() ? m_resource-
>cacheHandler(): nullptr, NotSharableCrossOrigin, cacheOptions) |
| 70 .IsEmpty(); | 70 .IsEmpty(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void setEmptyResource() | 73 void setEmptyResource() |
| 74 { | 74 { |
| 75 m_resourceRequest = ResourceRequest(); | 75 m_resourceRequest = ResourceRequest(); |
| 76 m_resource = new ScriptResource(m_resourceRequest, "UTF-8"); | 76 m_resource = ScriptResource::create(m_resourceRequest, "UTF-8"); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void setResource() | 79 void setResource() |
| 80 { | 80 { |
| 81 m_resourceRequest = ResourceRequest(url()); | 81 m_resourceRequest = ResourceRequest(url()); |
| 82 m_resource = new ScriptResource(m_resourceRequest, "UTF-8"); | 82 m_resource = ScriptResource::create(m_resourceRequest, "UTF-8"); |
| 83 } | 83 } |
| 84 | 84 |
| 85 CachedMetadataHandler* cacheHandler() | 85 CachedMetadataHandler* cacheHandler() |
| 86 { | 86 { |
| 87 return m_resource->cacheHandler(); | 87 return m_resource->cacheHandler(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 protected: | 90 protected: |
| 91 ResourceRequest m_resourceRequest; | 91 ResourceRequest m_resourceRequest; |
| 92 ResourcePtr<ScriptResource> m_resource; | 92 RefPtrWillBePersistent<ScriptResource> m_resource; |
| 93 V8TestingScope m_scope; | 93 V8TestingScope m_scope; |
| 94 | 94 |
| 95 static int counter; | 95 static int counter; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 int V8ScriptRunnerTest::counter = 0; | 98 int V8ScriptRunnerTest::counter = 0; |
| 99 | 99 |
| 100 TEST_F(V8ScriptRunnerTest, resourcelessShouldPass) | 100 TEST_F(V8ScriptRunnerTest, resourcelessShouldPass) |
| 101 { | 101 { |
| 102 EXPECT_TRUE(compileScript(V8CacheOptionsNone)); | 102 EXPECT_TRUE(compileScript(V8CacheOptionsNone)); |
| 103 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); | 103 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); |
| 104 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); | 104 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 TEST_F(V8ScriptRunnerTest, emptyResourceDoesNotHaveCacheHandler) | 107 TEST_F(V8ScriptRunnerTest, emptyResourceDoesNotHaveCacheHandler) |
| 108 { | 108 { |
| 109 setEmptyResource(); | 109 setEmptyResource(); |
| 110 EXPECT_FALSE(cacheHandler()); | 110 EXPECT_FALSE(cacheHandler()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(V8ScriptRunnerTest, parseOption) | 113 TEST_F(V8ScriptRunnerTest, parseOption) |
| 114 { | 114 { |
| 115 setResource(); | 115 setResource(); |
| 116 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); | 116 EXPECT_TRUE(compileScript(V8CacheOptionsParse)); |
| 117 EXPECT_TRUE(cacheHandler()->cachedMetadata(tagForParserCache(cacheHandler())
)); | 117 EXPECT_TRUE(cacheHandler()->cachedMetadata(tagForParserCache(cacheHandler())
)); |
| 118 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForCodeCache(cacheHandler()))
); | 118 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForCodeCache(cacheHandler()))
); |
| 119 // The cached data is associated with the encoding. | 119 // The cached data is associated with the encoding. |
| 120 ResourceRequest request(url()); | 120 ResourceRequest request(url()); |
| 121 ResourcePtr<ScriptResource> anotherResource = new ScriptResource(request, "U
TF-16"); | 121 RefPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); |
| 122 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForParserCache(anotherResourc
e->cacheHandler()))); | 122 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForParserCache(anotherResourc
e->cacheHandler()))); |
| 123 } | 123 } |
| 124 | 124 |
| 125 TEST_F(V8ScriptRunnerTest, codeOption) | 125 TEST_F(V8ScriptRunnerTest, codeOption) |
| 126 { | 126 { |
| 127 setResource(); | 127 setResource(); |
| 128 | 128 |
| 129 // Compile twice, since 'code' has a probation period before it caches. | 129 // Compile twice, since 'code' has a probation period before it caches. |
| 130 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); | 130 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); |
| 131 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); | 131 EXPECT_TRUE(compileScript(V8CacheOptionsCode)); |
| 132 | 132 |
| 133 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForParserCache(cacheHandler()
))); | 133 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForParserCache(cacheHandler()
))); |
| 134 EXPECT_TRUE(cacheHandler()->cachedMetadata(tagForCodeCache(cacheHandler())))
; | 134 EXPECT_TRUE(cacheHandler()->cachedMetadata(tagForCodeCache(cacheHandler())))
; |
| 135 // The cached data is associated with the encoding. | 135 // The cached data is associated with the encoding. |
| 136 ResourceRequest request(url()); | 136 ResourceRequest request(url()); |
| 137 ResourcePtr<ScriptResource> anotherResource = new ScriptResource(request, "U
TF-16"); | 137 RefPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); |
| 138 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForCodeCache(anotherResource-
>cacheHandler()))); | 138 EXPECT_FALSE(cacheHandler()->cachedMetadata(tagForCodeCache(anotherResource-
>cacheHandler()))); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace | 141 } // namespace |
| 142 | 142 |
| 143 } // namespace blink | 143 } // namespace blink |
| OLD | NEW |