| 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 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "chrome/renderer/extensions/native_handler.h" | 10 #include "chrome/renderer/extensions/native_handler.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 bool assertion_made_; | 50 bool assertion_made_; |
| 51 bool failed_; | 51 bool failed_; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // Source map that operates on std::strings. | 54 // Source map that operates on std::strings. |
| 55 class StringSourceMap : public ModuleSystem::SourceMap { | 55 class StringSourceMap : public ModuleSystem::SourceMap { |
| 56 public: | 56 public: |
| 57 StringSourceMap() {} | 57 StringSourceMap() {} |
| 58 virtual ~StringSourceMap() {} | 58 virtual ~StringSourceMap() {} |
| 59 | 59 |
| 60 v8::Handle<v8::Value> GetSource(const std::string& name) OVERRIDE { | 60 virtual v8::Handle<v8::Value> GetSource(const std::string& name) OVERRIDE { |
| 61 if (source_map_.count(name) == 0) | 61 if (source_map_.count(name) == 0) |
| 62 return v8::Undefined(); | 62 return v8::Undefined(); |
| 63 return v8::String::New(source_map_[name].c_str()); | 63 return v8::String::New(source_map_[name].c_str()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool Contains(const std::string& name) OVERRIDE { | 66 virtual bool Contains(const std::string& name) OVERRIDE { |
| 67 return source_map_.count(name); | 67 return source_map_.count(name); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void RegisterModule(const std::string& name, const std::string& source) { | 70 void RegisterModule(const std::string& name, const std::string& source) { |
| 71 CHECK_EQ(0u, source_map_.count(name)); | 71 CHECK_EQ(0u, source_map_.count(name)); |
| 72 source_map_[name] = source; | 72 source_map_[name] = source; |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 std::map<std::string, std::string> source_map_; | 76 std::map<std::string, std::string> source_map_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 class FailsOnException : public ModuleSystem::ExceptionHandler { | 79 class FailsOnException : public ModuleSystem::ExceptionHandler { |
| 80 public: | 80 public: |
| 81 virtual void HandleUncaughtException() { | 81 virtual void HandleUncaughtException() OVERRIDE { |
| 82 FAIL(); | 82 FAIL(); |
| 83 } | 83 } |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 ModuleSystemTest::ModuleSystemTest() | 86 ModuleSystemTest::ModuleSystemTest() |
| 87 : context_(v8::Context::New()), | 87 : context_(v8::Context::New()), |
| 88 source_map_(new StringSourceMap()), | 88 source_map_(new StringSourceMap()), |
| 89 should_assertions_be_made_(true) { | 89 should_assertions_be_made_(true) { |
| 90 context_->Enter(); | 90 context_->Enter(); |
| 91 assert_natives_ = new AssertNatives(context_->GetIsolate()); | 91 assert_natives_ = new AssertNatives(context_->GetIsolate()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 should_assertions_be_made_ = false; | 131 should_assertions_be_made_ = false; |
| 132 } | 132 } |
| 133 | 133 |
| 134 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { | 134 v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) { |
| 135 v8::HandleScope handle_scope; | 135 v8::HandleScope handle_scope; |
| 136 v8::Handle<v8::Object> object = v8::Object::New(); | 136 v8::Handle<v8::Object> object = v8::Object::New(); |
| 137 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()), | 137 v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()), |
| 138 object); | 138 object); |
| 139 return handle_scope.Close(object); | 139 return handle_scope.Close(object); |
| 140 } | 140 } |
| OLD | NEW |