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 "chrome/test/base/module_system_test.h" | 5 #include "chrome/test/base/module_system_test.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "chrome/renderer/extensions/module_system.h" | 7 #include "chrome/renderer/extensions/module_system.h" |
8 | 8 |
9 using extensions::ModuleSystem; | 9 using extensions::ModuleSystem; |
not at google - send to devlin
2013/02/15 22:26:17
TODO: put this file in extensions namespace.
cduvall
2013/02/19 23:58:49
Done.
| |
10 using extensions::NativeHandler; | 10 using extensions::NativeHandler; |
11 using extensions::ObjectBackedNativeHandler; | |
11 | 12 |
12 class CounterNatives : public NativeHandler { | 13 class CounterNatives : public ObjectBackedNativeHandler { |
13 public: | 14 public: |
14 explicit CounterNatives(v8::Isolate* isolate) | 15 explicit CounterNatives(v8::Isolate* isolate) |
15 : NativeHandler(isolate), counter_(0) { | 16 : ObjectBackedNativeHandler(isolate), counter_(0) { |
16 RouteFunction("Get", base::Bind(&CounterNatives::Get, | 17 RouteFunction("Get", base::Bind(&CounterNatives::Get, |
17 base::Unretained(this))); | 18 base::Unretained(this))); |
18 RouteFunction("Increment", base::Bind(&CounterNatives::Increment, | 19 RouteFunction("Increment", base::Bind(&CounterNatives::Increment, |
19 base::Unretained(this))); | 20 base::Unretained(this))); |
20 } | 21 } |
21 | 22 |
22 v8::Handle<v8::Value> Get(const v8::Arguments& args) { | 23 v8::Handle<v8::Value> Get(const v8::Arguments& args) { |
23 return v8::Integer::New(counter_); | 24 return v8::Integer::New(counter_); |
24 } | 25 } |
25 | 26 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 } | 253 } |
253 | 254 |
254 TEST_F(ModuleSystemTest, TestOverrideNonExistentNativeHandler) { | 255 TEST_F(ModuleSystemTest, TestOverrideNonExistentNativeHandler) { |
255 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); | 256 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); |
256 OverrideNativeHandler("thing", "exports.x = 5;"); | 257 OverrideNativeHandler("thing", "exports.x = 5;"); |
257 RegisterModule("test", | 258 RegisterModule("test", |
258 "var assert = requireNative('assert');" | 259 "var assert = requireNative('assert');" |
259 "assert.AssertTrue(requireNative('thing').x == 5);"); | 260 "assert.AssertTrue(requireNative('thing').x == 5);"); |
260 module_system_->Require("test"); | 261 module_system_->Require("test"); |
261 } | 262 } |
OLD | NEW |