| 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/V8BindingForCore.h" | 7 #include "bindings/core/v8/V8BindingForCore.h" |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/loader/resource/ScriptResource.h" | 9 #include "core/loader/resource/ScriptResource.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 bool CompileScript(ScriptState* script_state, V8CacheOptions cache_options) { | 61 bool CompileScript(ScriptState* script_state, V8CacheOptions cache_options) { |
| 62 return !V8ScriptRunner::CompileScript( | 62 return !V8ScriptRunner::CompileScript( |
| 63 script_state, V8String(script_state->GetIsolate(), Code()), | 63 script_state, V8String(script_state->GetIsolate(), Code()), |
| 64 Filename(), String(), WTF::TextPosition(), resource_.Get(), | 64 Filename(), String(), WTF::TextPosition(), resource_.Get(), |
| 65 nullptr, resource_.Get() ? resource_->CacheHandler() : nullptr, | 65 nullptr, resource_.Get() ? resource_->CacheHandler() : nullptr, |
| 66 kNotSharableCrossOrigin, cache_options) | 66 kNotSharableCrossOrigin, cache_options) |
| 67 .IsEmpty(); | 67 .IsEmpty(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SetEmptyResource() { | 70 void SetEmptyResource() { SetResourceInternal(KURL()); } |
| 71 resource_ = ScriptResource::CreateForTest(NullURL(), UTF8Encoding()); | |
| 72 } | |
| 73 | 71 |
| 74 void SetResource() { | 72 void SetResource() { SetResourceInternal(Url()); } |
| 75 resource_ = ScriptResource::CreateForTest(Url(), UTF8Encoding()); | 73 |
| 74 void SetResourceInternal(const KURL& url) { |
| 75 ScriptResource* resource = |
| 76 ScriptResource::CreateForTest(url, UTF8Encoding()); |
| 77 // This is not a complete Resource (e.g. lacks ResourceResponse) |
| 78 // but is sufficient for testing here. |
| 79 resource->Finish(); |
| 80 resource_ = resource->ResourceData(); |
| 76 } | 81 } |
| 77 | 82 |
| 78 CachedMetadataHandler* CacheHandler() { return resource_->CacheHandler(); } | 83 CachedMetadataHandler* CacheHandler() { return resource_->CacheHandler(); } |
| 79 | 84 |
| 80 protected: | 85 protected: |
| 81 Persistent<ScriptResource> resource_; | 86 Persistent<const ScriptResourceData> resource_; |
| 82 | 87 |
| 83 static int counter_; | 88 static int counter_; |
| 84 }; | 89 }; |
| 85 | 90 |
| 86 int V8ScriptRunnerTest::counter_ = 0; | 91 int V8ScriptRunnerTest::counter_ = 0; |
| 87 | 92 |
| 88 TEST_F(V8ScriptRunnerTest, resourcelessShouldPass) { | 93 TEST_F(V8ScriptRunnerTest, resourcelessShouldPass) { |
| 89 V8TestingScope scope; | 94 V8TestingScope scope; |
| 90 EXPECT_TRUE(CompileScript(scope.GetScriptState(), kV8CacheOptionsNone)); | 95 EXPECT_TRUE(CompileScript(scope.GetScriptState(), kV8CacheOptionsNone)); |
| 91 EXPECT_TRUE(CompileScript(scope.GetScriptState(), kV8CacheOptionsParse)); | 96 EXPECT_TRUE(CompileScript(scope.GetScriptState(), kV8CacheOptionsParse)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // The cached data is associated with the encoding. | 131 // The cached data is associated with the encoding. |
| 127 ScriptResource* another_resource = | 132 ScriptResource* another_resource = |
| 128 ScriptResource::CreateForTest(Url(), UTF16LittleEndianEncoding()); | 133 ScriptResource::CreateForTest(Url(), UTF16LittleEndianEncoding()); |
| 129 EXPECT_FALSE(CacheHandler()->GetCachedMetadata( | 134 EXPECT_FALSE(CacheHandler()->GetCachedMetadata( |
| 130 TagForCodeCache(another_resource->CacheHandler()))); | 135 TagForCodeCache(another_resource->CacheHandler()))); |
| 131 } | 136 } |
| 132 | 137 |
| 133 } // namespace | 138 } // namespace |
| 134 | 139 |
| 135 } // namespace blink | 140 } // namespace blink |
| OLD | NEW |