| 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; |
| 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 CounterNatives() : counter_(0) { | 15 CounterNatives() : counter_(0) { |
| 15 RouteFunction("Get", base::Bind(&CounterNatives::Get, | 16 RouteFunction("Get", base::Bind(&CounterNatives::Get, |
| 16 base::Unretained(this))); | 17 base::Unretained(this))); |
| 17 RouteFunction("Increment", base::Bind(&CounterNatives::Increment, | 18 RouteFunction("Increment", base::Bind(&CounterNatives::Increment, |
| 18 base::Unretained(this))); | 19 base::Unretained(this))); |
| 19 } | 20 } |
| 20 | 21 |
| 21 v8::Handle<v8::Value> Get(const v8::Arguments& args) { | 22 v8::Handle<v8::Value> Get(const v8::Arguments& args) { |
| 22 return v8::Integer::New(counter_); | 23 return v8::Integer::New(counter_); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 252 } |
| 252 | 253 |
| 253 TEST_F(ModuleSystemTest, TestOverrideNonExistentNativeHandler) { | 254 TEST_F(ModuleSystemTest, TestOverrideNonExistentNativeHandler) { |
| 254 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); | 255 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); |
| 255 OverrideNativeHandler("thing", "exports.x = 5;"); | 256 OverrideNativeHandler("thing", "exports.x = 5;"); |
| 256 RegisterModule("test", | 257 RegisterModule("test", |
| 257 "var assert = requireNative('assert');" | 258 "var assert = requireNative('assert');" |
| 258 "assert.AssertTrue(requireNative('thing').x == 5);"); | 259 "assert.AssertTrue(requireNative('thing').x == 5);"); |
| 259 module_system_->Require("test"); | 260 module_system_->Require("test"); |
| 260 } | 261 } |
| OLD | NEW |