Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptModuleTest.cpp

Issue 2781303002: [ES6 modules] Introduce ScriptModuleHash (Closed)
Patch Set: rebased Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ScriptModule.h" 5 #include "bindings/core/v8/ScriptModule.h"
6 6
7 #include "bindings/core/v8/V8BindingForTesting.h" 7 #include "bindings/core/v8/V8BindingForTesting.h"
8 #include "bindings/core/v8/V8PerContextData.h" 8 #include "bindings/core/v8/V8PerContextData.h"
9 #include "core/dom/ScriptModuleResolver.h" 9 #include "core/dom/ScriptModuleResolver.h"
10 #include "core/testing/DummyModulator.h" 10 #include "core/testing/DummyModulator.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 ASSERT_FALSE(module.isNull()); 79 ASSERT_FALSE(module.isNull());
80 } 80 }
81 81
82 TEST(ScriptModuleTest, compileFail) { 82 TEST(ScriptModuleTest, compileFail) {
83 V8TestingScope scope; 83 V8TestingScope scope;
84 ScriptModule module = 84 ScriptModule module =
85 ScriptModule::compile(scope.isolate(), "123 = 456", "foo.js"); 85 ScriptModule::compile(scope.isolate(), "123 = 456", "foo.js");
86 ASSERT_TRUE(module.isNull()); 86 ASSERT_TRUE(module.isNull());
87 } 87 }
88 88
89 TEST(ScriptModuleTest, equalAndHash) {
90 V8TestingScope scope;
91
92 ScriptModule moduleNull;
93 ScriptModule moduleA =
94 ScriptModule::compile(scope.isolate(), "export const a = 'a';", "a.js");
95 ASSERT_FALSE(moduleA.isNull());
96 ScriptModule moduleB =
97 ScriptModule::compile(scope.isolate(), "export const b = 'b';", "b.js");
98 ASSERT_FALSE(moduleB.isNull());
99 Vector<char> moduleDeletedBuffer(sizeof(ScriptModule));
100 ScriptModule& moduleDeleted =
101 *reinterpret_cast<ScriptModule*>(moduleDeletedBuffer.data());
102 HashTraits<ScriptModule>::constructDeletedValue(moduleDeleted, true);
103
104 EXPECT_EQ(moduleNull, moduleNull);
105 EXPECT_EQ(moduleA, moduleA);
106 EXPECT_EQ(moduleB, moduleB);
107 EXPECT_EQ(moduleDeleted, moduleDeleted);
108
109 EXPECT_NE(moduleNull, moduleA);
110 EXPECT_NE(moduleNull, moduleB);
111 EXPECT_NE(moduleNull, moduleDeleted);
112
113 EXPECT_NE(moduleA, moduleNull);
114 EXPECT_NE(moduleA, moduleB);
115 EXPECT_NE(moduleA, moduleDeleted);
116
117 EXPECT_NE(moduleB, moduleNull);
118 EXPECT_NE(moduleB, moduleA);
119 EXPECT_NE(moduleB, moduleDeleted);
120
121 EXPECT_NE(moduleDeleted, moduleNull);
122 EXPECT_NE(moduleDeleted, moduleA);
123 EXPECT_NE(moduleDeleted, moduleB);
124
125 EXPECT_NE(DefaultHash<ScriptModule>::Hash::hash(moduleA),
126 DefaultHash<ScriptModule>::Hash::hash(moduleB));
127 EXPECT_NE(DefaultHash<ScriptModule>::Hash::hash(moduleNull),
128 DefaultHash<ScriptModule>::Hash::hash(moduleA));
129 EXPECT_NE(DefaultHash<ScriptModule>::Hash::hash(moduleNull),
130 DefaultHash<ScriptModule>::Hash::hash(moduleB));
131 }
132
89 TEST(ScriptModuleTest, moduleRequests) { 133 TEST(ScriptModuleTest, moduleRequests) {
90 V8TestingScope scope; 134 V8TestingScope scope;
91 ScriptModule module = ScriptModule::compile( 135 ScriptModule module = ScriptModule::compile(
92 scope.isolate(), "import 'a'; import 'b'; export const c = 'c';", 136 scope.isolate(), "import 'a'; import 'b'; export const c = 'c';",
93 "foo.js"); 137 "foo.js");
94 ASSERT_FALSE(module.isNull()); 138 ASSERT_FALSE(module.isNull());
95 139
96 auto requests = module.moduleRequests(scope.getScriptState()); 140 auto requests = module.moduleRequests(scope.getScriptState());
97 EXPECT_THAT(requests, ::testing::ContainerEq<Vector<String>>({"a", "b"})); 141 EXPECT_THAT(requests, ::testing::ContainerEq<Vector<String>>({"a", "b"}));
98 } 142 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ASSERT_TRUE(exception.isEmpty()); 185 ASSERT_TRUE(exception.isEmpty());
142 186
143 ASSERT_EQ(2u, resolver->resolveCount()); 187 ASSERT_EQ(2u, resolver->resolveCount());
144 EXPECT_EQ("a", resolver->specifiers()[0]); 188 EXPECT_EQ("a", resolver->specifiers()[0]);
145 EXPECT_EQ("b", resolver->specifiers()[1]); 189 EXPECT_EQ("b", resolver->specifiers()[1]);
146 } 190 }
147 191
148 } // namespace 192 } // namespace
149 193
150 } // namespace blink 194 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698