| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 m_resource = ScriptResource::create(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 RefPtrWillBePersistent<ScriptResource> m_resource; | 92 Persistent<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 RefPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); | 121 RawPtr<ScriptResource> anotherResource = ScriptResource::create(request, "UT
F-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 RefPtrWillBeRawPtr<ScriptResource> anotherResource = ScriptResource::create(
request, "UTF-16"); | 137 RawPtr<ScriptResource> anotherResource = ScriptResource::create(request, "UT
F-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 |