OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/string_piece.h" | 7 #include "base/string_piece.h" |
8 #include "chrome/renderer/module_system.h" | 8 #include "chrome/renderer/module_system.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 "var caught = false;" | 159 "var caught = false;" |
160 "try {" | 160 "try {" |
161 " requireNative('assert');" | 161 " requireNative('assert');" |
162 "} catch (e) {" | 162 "} catch (e) {" |
163 " caught = true;" | 163 " caught = true;" |
164 "}" | 164 "}" |
165 "assert.AssertTrue(caught);"); | 165 "assert.AssertTrue(caught);"); |
166 module_system_->Require("test"); | 166 module_system_->Require("test"); |
167 } | 167 } |
168 | 168 |
169 TEST_F(ModuleSystemTest, TestLazyObject) { | 169 TEST_F(ModuleSystemTest, TestLazyField) { |
170 v8::Handle<v8::String> source = v8::String::New("({x: 5})"); | 170 RegisterModule("lazy", |
171 v8::Handle<v8::Object> lazy_object = | 171 "exports.x = 5;"); |
172 ModuleSystem::CreateLazyObject("lazy.js", source); | 172 |
173 v8::Context::GetCurrent()->Global()->Set(v8::String::New("lazy"), | 173 v8::Handle<v8::Object> object = v8::Object::New(); |
174 lazy_object); | 174 v8::Context::GetCurrent()->Global()->Set(v8::String::New("object"), object); |
175 | |
176 module_system_->SetLazyField(object, "blah", "lazy", "x"); | |
not at google - send to devlin
2012/03/22 00:35:53
can you do the same sort of thing you did below, t
koz (OOO until 15th September)
2012/03/22 01:13:01
That's a good idea for a test. I've added it as a
| |
177 | |
175 RegisterModule("test", | 178 RegisterModule("test", |
176 "var assert = requireNative('assert');" | 179 "var assert = requireNative('assert');" |
177 "assert.AssertTrue(lazy.x == 5);" | 180 "assert.AssertTrue(object.blah == 5);"); |
178 "assert.AssertTrue(lazy.x == 5);"); | |
179 module_system_->Require("test"); | 181 module_system_->Require("test"); |
180 } | 182 } |
181 | |
182 TEST_F(ModuleSystemTest, TestLazyInstanceOnlyGetsEvaledOnce) { | |
183 v8::Context::GetCurrent()->Global()->Set(v8::String::New("evalCount"), | |
184 v8::Integer::New(0)); | |
185 v8::Handle<v8::String> source = v8::String::New("evalCount++; ({x: 5})"); | |
186 v8::Handle<v8::Object> lazy_object = | |
187 ModuleSystem::CreateLazyObject("lazy.js", source); | |
188 v8::Context::GetCurrent()->Global()->Set(v8::String::New("lazy"), | |
189 lazy_object); | |
190 RegisterModule("test", | |
191 "var assert = requireNative('assert');" | |
192 "assert.AssertTrue(evalCount == 0);" | |
193 "lazy.x;" | |
194 "assert.AssertTrue(evalCount == 1);" | |
195 "lazy.x;" | |
196 "assert.AssertTrue(evalCount == 1);"); | |
197 module_system_->Require("test"); | |
198 } | |
OLD | NEW |