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

Side by Side Diff: chrome/renderer/module_system_unittest.cc

Issue 9835039: Make app_custom_bindings.js lazily evaluated so it doesn't execute on every page load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lazy load webstore bindings as well Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 v8::Handle<v8::Object> object = v8::Object::New(); 174 v8::Handle<v8::Object> object = v8::Object::New();
175 v8::Context::GetCurrent()->Global()->Set(v8::String::New("object"), object); 175 v8::Context::GetCurrent()->Global()->Set(v8::String::New("object"), object);
176 176
177 module_system_->SetLazyField(object, "blah", "lazy", "x"); 177 module_system_->SetLazyField(object, "blah", "lazy", "x");
178 178
179 RegisterModule("test", 179 RegisterModule("test",
180 "var assert = requireNative('assert');" 180 "var assert = requireNative('assert');"
181 "assert.AssertTrue(object.blah == 5);"); 181 "assert.AssertTrue(object.blah == 5);");
182 module_system_->Require("test"); 182 module_system_->Require("test");
183 } 183 }
184
185 TEST_F(ModuleSystemTest, TestLazyFieldYieldingObject) {
186 RegisterModule("lazy",
187 "var object = {};"
188 "object.__defineGetter__('z', function() { return 1; });"
189 "object.x = 5;"
190 "object.y = 10;"
191 "exports.object = object;");
192
193 v8::Handle<v8::Object> object = v8::Object::New();
194 v8::Context::GetCurrent()->Global()->Set(v8::String::New("object"), object);
195
196 module_system_->SetLazyField(object, "thing", "lazy", "object");
197
198 RegisterModule("test",
199 "var assert = requireNative('assert');"
200 "assert.AssertTrue(object.thing.x == 5);"
not at google - send to devlin 2012/03/25 22:42:58 Once again, could you have a global "count" and ch
koz (OOO until 15th September) 2012/03/26 01:36:09 Done in a separate test.
201 "assert.AssertTrue(object.thing.y == 10);"
not at google - send to devlin 2012/03/25 22:42:58 I don't see the advantage in having x and y be bot
koz (OOO until 15th September) 2012/03/26 01:36:09 Done.
202 "assert.AssertTrue(object.thing.z == 1);"
203 );
204 module_system_->Require("test");
205 }
206
207 TEST_F(ModuleSystemTest, TestTransitiveRequire) {
208 RegisterModule("dependency",
209 "exports.x = 5;");
210 RegisterModule("lazy",
211 "exports.output = require('dependency');");
212
213 v8::Handle<v8::Object> object = v8::Object::New();
214 v8::Context::GetCurrent()->Global()->Set(v8::String::New("object"), object);
215
216 module_system_->SetLazyField(object, "thing", "lazy", "output");
217
218 RegisterModule("test",
219 "var assert = requireNative('assert');"
220 "assert.AssertTrue(object.thing.x == 5);");
not at google - send to devlin 2012/03/25 22:42:58 If this was instead var x = object.thing.x; var a
koz (OOO until 15th September) 2012/03/26 01:36:09 Yeah, it would if you wrap it in a NativesEnabledS
221 module_system_->Require("test");
222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698