diff options
author | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-09 14:26:24 +0000 |
---|---|---|
committer | cduvall@chromium.org <cduvall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-09 14:26:24 +0000 |
commit | 4f1633f8ab00e5362a585948ff1e5231bcbca5ef (patch) | |
tree | 5f0e3e4d1d7a27970fe97074cf0aabe520a0d8ad /chrome/renderer/extensions/event_unittest.cc | |
parent | 7c04e5896a71a6061ebfc13facdcf5579b7bda9d (diff) | |
download | chromium_src-4f1633f8ab00e5362a585948ff1e5231bcbca5ef.zip chromium_src-4f1633f8ab00e5362a585948ff1e5231bcbca5ef.tar.gz chromium_src-4f1633f8ab00e5362a585948ff1e5231bcbca5ef.tar.bz2 |
Set up V8 bindings for extension/app APIs when they're first used, not on
context creation. This should gives us a significant reduction in extension/app
startup time and slightly better memory usage.
It also gives us better error messages, the chance to complete the
implementation of API features, and eventually the ability to expose select
extension APIs (e.g. extension.sendMessage) to web pages.
Resubmitting: changes made to resubmit this patch reviewed in: https://codereview.chromium.org/12378077/
BUG=163678,120070,55316,177163
TBR=ben@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=186643
Review URL: https://chromiumcodereview.appspot.com/11571014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions/event_unittest.cc')
-rw-r--r-- | chrome/renderer/extensions/event_unittest.cc | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/chrome/renderer/extensions/event_unittest.cc b/chrome/renderer/extensions/event_unittest.cc index edd47c0..8258b42 100644 --- a/chrome/renderer/extensions/event_unittest.cc +++ b/chrome/renderer/extensions/event_unittest.cc @@ -62,6 +62,9 @@ class EventUnittest : public ModuleSystemTest { OverrideNativeHandler("chrome_hidden", "var chromeHidden = {};" "exports.GetChromeHidden = function() { return chromeHidden; };"); + OverrideNativeHandler("chrome", + "var chrome = {};" + "exports.GetChrome = function() { return chrome; };"); OverrideNativeHandler("sendRequest", "exports.sendRequest = function() {};"); OverrideNativeHandler("apiDefinitions", @@ -79,9 +82,10 @@ TEST_F(EventUnittest, AddRemoveTwoListeners) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", "var assert = requireNative('assert');" - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var eventBindings = requireNative('event_bindings');" - "var myEvent = new event.Event('named-event');" + "var myEvent = new Event('named-event');" "var cb1 = function() {};" "var cb2 = function() {};" "myEvent.addListener(cb1);" @@ -97,10 +101,11 @@ TEST_F(EventUnittest, OnUnloadDetachesAllListeners) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", "var assert = requireNative('assert');" - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var eventBindings = requireNative('event_bindings');" "var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();" - "var myEvent = new event.Event('named-event');" + "var myEvent = new Event('named-event');" "var cb1 = function() {};" "var cb2 = function() {};" "myEvent.addListener(cb1);" @@ -114,10 +119,11 @@ TEST_F(EventUnittest, OnUnloadDetachesAllListenersEvenDupes) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", "var assert = requireNative('assert');" - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var eventBindings = requireNative('event_bindings');" "var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();" - "var myEvent = new event.Event('named-event');" + "var myEvent = new Event('named-event');" "var cb1 = function() {};" "myEvent.addListener(cb1);" "myEvent.addListener(cb1);" @@ -129,12 +135,13 @@ TEST_F(EventUnittest, OnUnloadDetachesAllListenersEvenDupes) { TEST_F(EventUnittest, EventsThatSupportRulesMustHaveAName) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var eventOpts = {supportsRules: true};" "var assert = requireNative('assert');" "var caught = false;" "try {" - " var myEvent = new event.Event(undefined, undefined, eventOpts);" + " var myEvent = new Event(undefined, undefined, eventOpts);" "} catch (e) {" " caught = true;" "}" @@ -145,10 +152,11 @@ TEST_F(EventUnittest, EventsThatSupportRulesMustHaveAName) { TEST_F(EventUnittest, NamedEventDispatch) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();" "var assert = requireNative('assert');" - "var e = new event.Event('myevent');" + "var e = new Event('myevent');" "var called = false;" "e.addListener(function() { called = true; });" "chromeHidden.Event.dispatchEvent('myevent', []);" @@ -159,9 +167,10 @@ TEST_F(EventUnittest, NamedEventDispatch) { TEST_F(EventUnittest, AddListenerWithFiltersThrowsErrorByDefault) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var assert = requireNative('assert');" - "var e = new event.Event('myevent');" + "var e = new Event('myevent');" "var filter = [{" " url: {hostSuffix: 'google.com'}," "}];" @@ -178,11 +187,12 @@ TEST_F(EventUnittest, AddListenerWithFiltersThrowsErrorByDefault) { TEST_F(EventUnittest, FilteredEventsAttachment) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var assert = requireNative('assert');" "var bindings = requireNative('event_bindings');" "var eventOpts = {supportsListeners: true, supportsFilters: true};" - "var e = new event.Event('myevent', undefined, eventOpts);" + "var e = new Event('myevent', undefined, eventOpts);" "var cb = function() {};" "var filters = {url: [{hostSuffix: 'google.com'}]};" "e.addListener(cb, filters);" @@ -195,11 +205,12 @@ TEST_F(EventUnittest, FilteredEventsAttachment) { TEST_F(EventUnittest, DetachFilteredEvent) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var assert = requireNative('assert');" "var bindings = requireNative('event_bindings');" "var eventOpts = {supportsListeners: true, supportsFilters: true};" - "var e = new event.Event('myevent', undefined, eventOpts);" + "var e = new Event('myevent', undefined, eventOpts);" "var cb1 = function() {};" "var cb2 = function() {};" "var filters = {url: [{hostSuffix: 'google.com'}]};" @@ -213,11 +224,12 @@ TEST_F(EventUnittest, DetachFilteredEvent) { TEST_F(EventUnittest, AttachAndRemoveSameFilteredEventListener) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var assert = requireNative('assert');" "var bindings = requireNative('event_bindings');" "var eventOpts = {supportsListeners: true, supportsFilters: true};" - "var e = new event.Event('myevent', undefined, eventOpts);" + "var e = new Event('myevent', undefined, eventOpts);" "var cb = function() {};" "var filters = {url: [{hostSuffix: 'google.com'}]};" "e.addListener(cb, filters);" @@ -233,10 +245,11 @@ TEST_F(EventUnittest, AttachAndRemoveSameFilteredEventListener) { TEST_F(EventUnittest, AddingFilterWithUrlFieldNotAListThrowsException) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var assert = requireNative('assert');" "var eventOpts = {supportsListeners: true, supportsFilters: true};" - "var e = new event.Event('myevent', undefined, eventOpts);" + "var e = new Event('myevent', undefined, eventOpts);" "var cb = function() {};" "var filters = {url: {hostSuffix: 'google.com'}};" "var caught = false;" @@ -252,10 +265,11 @@ TEST_F(EventUnittest, AddingFilterWithUrlFieldNotAListThrowsException) { TEST_F(EventUnittest, MaxListeners) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterModule("test", - "var event = require('event');" + "require('event');" + "var Event = requireNative('chrome').GetChrome().Event;" "var assert = requireNative('assert');" "var eventOpts = {supportsListeners: true, maxListeners: 1};" - "var e = new event.Event('myevent', undefined, eventOpts);" + "var e = new Event('myevent', undefined, eventOpts);" "var cb = function() {};" "var caught = false;" "try {" |