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 return !V8ScriptRunner::CompileScript( | 60 return !V8ScriptRunner::CompileScript( |
61 V8String(isolate, Code()), Filename(), String(), | 61 V8String(isolate, Code()), Filename(), String(), |
62 WTF::TextPosition(), isolate, resource_.Get(), nullptr, | 62 WTF::TextPosition(), isolate, resource_.Get(), nullptr, |
63 resource_.Get() ? resource_->CacheHandler() : nullptr, | 63 resource_.Get() ? resource_->CacheHandler() : nullptr, |
64 kNotSharableCrossOrigin, cache_options) | 64 kNotSharableCrossOrigin, cache_options) |
65 .IsEmpty(); | 65 .IsEmpty(); |
66 } | 66 } |
67 | 67 |
68 void SetEmptyResource() { | 68 void SetEmptyResource() { |
69 resource_request_ = ResourceRequest(); | 69 resource_request_ = ResourceRequest(); |
70 resource_ = ScriptResource::Create(resource_request_, "UTF-8"); | 70 SetResourceInternal(); |
71 } | 71 } |
72 | 72 |
73 void SetResource() { | 73 void SetResource() { |
74 resource_request_ = ResourceRequest(Url()); | 74 resource_request_ = ResourceRequest(Url()); |
75 resource_ = ScriptResource::Create(resource_request_, "UTF-8"); | 75 SetResourceInternal(); |
| 76 } |
| 77 |
| 78 void SetResourceInternal() { |
| 79 ScriptResource* resource = |
| 80 ScriptResource::Create(resource_request_, "UTF-8"); |
| 81 // This is not a complete Resource (e.g. lacks ResourceResponse) |
| 82 // but is sufficient for testing here. |
| 83 resource->Finish(); |
| 84 resource_ = resource->ResourceData(); |
76 } | 85 } |
77 | 86 |
78 CachedMetadataHandler* CacheHandler() { return resource_->CacheHandler(); } | 87 CachedMetadataHandler* CacheHandler() { return resource_->CacheHandler(); } |
79 | 88 |
80 protected: | 89 protected: |
81 ResourceRequest resource_request_; | 90 ResourceRequest resource_request_; |
82 Persistent<ScriptResource> resource_; | 91 Persistent<const ScriptResourceData> resource_; |
83 | 92 |
84 static int counter_; | 93 static int counter_; |
85 }; | 94 }; |
86 | 95 |
87 int V8ScriptRunnerTest::counter_ = 0; | 96 int V8ScriptRunnerTest::counter_ = 0; |
88 | 97 |
89 TEST_F(V8ScriptRunnerTest, resourcelessShouldPass) { | 98 TEST_F(V8ScriptRunnerTest, resourcelessShouldPass) { |
90 V8TestingScope scope; | 99 V8TestingScope scope; |
91 EXPECT_TRUE(CompileScript(scope.GetIsolate(), kV8CacheOptionsNone)); | 100 EXPECT_TRUE(CompileScript(scope.GetIsolate(), kV8CacheOptionsNone)); |
92 EXPECT_TRUE(CompileScript(scope.GetIsolate(), kV8CacheOptionsParse)); | 101 EXPECT_TRUE(CompileScript(scope.GetIsolate(), kV8CacheOptionsParse)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // The cached data is associated with the encoding. | 136 // The cached data is associated with the encoding. |
128 ResourceRequest request(Url()); | 137 ResourceRequest request(Url()); |
129 ScriptResource* another_resource = ScriptResource::Create(request, "UTF-16"); | 138 ScriptResource* another_resource = ScriptResource::Create(request, "UTF-16"); |
130 EXPECT_FALSE(CacheHandler()->GetCachedMetadata( | 139 EXPECT_FALSE(CacheHandler()->GetCachedMetadata( |
131 TagForCodeCache(another_resource->CacheHandler()))); | 140 TagForCodeCache(another_resource->CacheHandler()))); |
132 } | 141 } |
133 | 142 |
134 } // namespace | 143 } // namespace |
135 | 144 |
136 } // namespace blink | 145 } // namespace blink |
OLD | NEW |