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

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

Issue 11312157: Add ExceptionHandler to ModuleSystem, remove heap allocated v8::TryCatch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename dispatchJSON -> dispatchEvent Created 8 years 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 "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;
(...skipping 13 matching lines...) Expand all
24 24
25 v8::Handle<v8::Value> Increment(const v8::Arguments& args) { 25 v8::Handle<v8::Value> Increment(const v8::Arguments& args) {
26 counter_++; 26 counter_++;
27 return v8::Undefined(); 27 return v8::Undefined();
28 } 28 }
29 29
30 private: 30 private:
31 int counter_; 31 int counter_;
32 }; 32 };
33 33
34 class TestExceptionHandler : public ModuleSystem::ExceptionHandler {
35 public:
36 TestExceptionHandler()
37 : handled_exception_(false) {
38 }
39
40 virtual void HandleUncaughtException() {
41 handled_exception_ = true;
42 }
43
44 bool handled_exception() const { return handled_exception_; }
45
46 private:
47 bool handled_exception_;
48 };
49
50 TEST_F(ModuleSystemTest, TestExceptionHandling) {
51 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
52 TestExceptionHandler* handler = new TestExceptionHandler;
53 scoped_ptr<ModuleSystem::ExceptionHandler> scoped_handler(handler);
54 ASSERT_FALSE(handler->handled_exception());
55 module_system_->set_exception_handler(scoped_handler.Pass());
56
57 RegisterModule("test", "throw 'hi';");
58 module_system_->Require("test");
59 ASSERT_TRUE(handler->handled_exception());
60
61 ExpectNoAssertionsMade();
62 }
63
34 TEST_F(ModuleSystemTest, TestRequire) { 64 TEST_F(ModuleSystemTest, TestRequire) {
35 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); 65 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
36 RegisterModule("add", "exports.Add = function(x, y) { return x + y; };"); 66 RegisterModule("add", "exports.Add = function(x, y) { return x + y; };");
37 RegisterModule("test", 67 RegisterModule("test",
38 "var Add = require('add').Add;" 68 "var Add = require('add').Add;"
39 "requireNative('assert').AssertTrue(Add(3, 5) == 8);"); 69 "requireNative('assert').AssertTrue(Add(3, 5) == 8);");
40 module_system_->Require("test"); 70 module_system_->Require("test");
41 } 71 }
42 72
43 TEST_F(ModuleSystemTest, TestNestedRequire) { 73 TEST_F(ModuleSystemTest, TestNestedRequire) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 251 }
222 252
223 TEST_F(ModuleSystemTest, TestOverrideNonExistentNativeHandler) { 253 TEST_F(ModuleSystemTest, TestOverrideNonExistentNativeHandler) {
224 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); 254 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get());
225 OverrideNativeHandler("thing", "exports.x = 5;"); 255 OverrideNativeHandler("thing", "exports.x = 5;");
226 RegisterModule("test", 256 RegisterModule("test",
227 "var assert = requireNative('assert');" 257 "var assert = requireNative('assert');"
228 "assert.AssertTrue(requireNative('thing').x == 5);"); 258 "assert.AssertTrue(requireNative('thing').x == 5);");
229 module_system_->Require("test"); 259 module_system_->Require("test");
230 } 260 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/module_system.cc ('k') | chrome/renderer/resource_bundle_source_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698