OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef EXTENSIONS_RENDERER_MODULE_SYSTEM_TEST_H_ | 5 #ifndef EXTENSIONS_RENDERER_MODULE_SYSTEM_TEST_H_ |
6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_TEST_H_ | 6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_TEST_H_ |
7 | 7 |
8 #include "extensions/renderer/module_system.h" | 8 #include "extensions/renderer/module_system.h" |
9 #include "extensions/renderer/scoped_persistent.h" | 9 #include "extensions/renderer/scoped_persistent.h" |
10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
11 #include "gin/public/context_holder.h" | 11 #include "gin/public/context_holder.h" |
12 #include "gin/public/isolate_holder.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
15 | 14 |
16 namespace extensions { | 15 namespace extensions { |
17 | 16 |
18 class ModuleSystemTestEnvironment { | 17 class ModuleSystemTestEnvironment { |
19 public: | 18 public: |
20 class AssertNatives; | 19 class AssertNatives; |
21 class StringSourceMap; | 20 class StringSourceMap; |
22 | 21 |
23 explicit ModuleSystemTestEnvironment(gin::IsolateHolder* isolate_holder); | 22 explicit ModuleSystemTestEnvironment(v8::Isolate* isolate); |
24 ~ModuleSystemTestEnvironment(); | 23 ~ModuleSystemTestEnvironment(); |
25 | 24 |
26 // Register a named JS module in the module system. | 25 // Register a named JS module in the module system. |
27 void RegisterModule(const std::string& name, const std::string& code); | 26 void RegisterModule(const std::string& name, const std::string& code); |
28 | 27 |
29 // Register a named JS module with source retrieved from a ResourceBundle. | 28 // Register a named JS module with source retrieved from a ResourceBundle. |
30 void RegisterModule(const std::string& name, int resource_id); | 29 void RegisterModule(const std::string& name, int resource_id); |
31 | 30 |
32 // Register a named JS module in the module system and tell the module system | 31 // Register a named JS module in the module system and tell the module system |
33 // to use it to handle any requireNative() calls for native modules with that | 32 // to use it to handle any requireNative() calls for native modules with that |
34 // name. | 33 // name. |
35 void OverrideNativeHandler(const std::string& name, const std::string& code); | 34 void OverrideNativeHandler(const std::string& name, const std::string& code); |
36 | 35 |
37 // Registers |file_name| from chrome/test/data/extensions as a module name | 36 // Registers |file_name| from chrome/test/data/extensions as a module name |
38 // |module_name|. | 37 // |module_name|. |
39 void RegisterTestFile(const std::string& module_name, | 38 void RegisterTestFile(const std::string& module_name, |
40 const std::string& file_name); | 39 const std::string& file_name); |
41 | 40 |
42 // Create an empty object in the global scope with name |name|. | 41 // Create an empty object in the global scope with name |name|. |
43 v8::Handle<v8::Object> CreateGlobal(const std::string& name); | 42 v8::Handle<v8::Object> CreateGlobal(const std::string& name); |
44 | 43 |
45 void ShutdownGin(); | 44 void ShutdownGin(); |
46 | 45 |
47 void ShutdownModuleSystem(); | 46 void ShutdownModuleSystem(); |
48 | 47 |
49 ModuleSystem* module_system() { return context_->module_system(); } | 48 ModuleSystem* module_system() { return context_->module_system(); } |
50 | 49 |
51 ScriptContext* context() { return context_.get(); } | 50 ScriptContext* context() { return context_.get(); } |
52 | 51 |
53 v8::Isolate* isolate() { return isolate_holder_->isolate(); } | 52 v8::Isolate* isolate() { return isolate_; } |
54 | 53 |
55 AssertNatives* assert_natives() { return assert_natives_; } | 54 AssertNatives* assert_natives() { return assert_natives_; } |
56 | 55 |
57 private: | 56 private: |
58 gin::IsolateHolder* isolate_holder_; | 57 v8::Isolate* isolate_; |
59 scoped_ptr<gin::ContextHolder> context_holder_; | 58 scoped_ptr<gin::ContextHolder> context_holder_; |
60 v8::HandleScope handle_scope_; | 59 v8::HandleScope handle_scope_; |
61 scoped_ptr<ScriptContext> context_; | 60 scoped_ptr<ScriptContext> context_; |
62 AssertNatives* assert_natives_; | 61 AssertNatives* assert_natives_; |
63 scoped_ptr<StringSourceMap> source_map_; | 62 scoped_ptr<StringSourceMap> source_map_; |
64 | 63 |
65 DISALLOW_COPY_AND_ASSIGN(ModuleSystemTestEnvironment); | 64 DISALLOW_COPY_AND_ASSIGN(ModuleSystemTestEnvironment); |
66 }; | 65 }; |
67 | 66 |
68 // Test fixture for testing JS that makes use of the module system. | 67 // Test fixture for testing JS that makes use of the module system. |
(...skipping 22 matching lines...) Expand all Loading... |
91 | 90 |
92 // Make the test fail if any asserts are called. By default a test will fail | 91 // Make the test fail if any asserts are called. By default a test will fail |
93 // if no asserts are called. | 92 // if no asserts are called. |
94 void ExpectNoAssertionsMade(); | 93 void ExpectNoAssertionsMade(); |
95 | 94 |
96 // Runs promises that have been resolved. Resolved promises will not run | 95 // Runs promises that have been resolved. Resolved promises will not run |
97 // until this is called. | 96 // until this is called. |
98 void RunResolvedPromises(); | 97 void RunResolvedPromises(); |
99 | 98 |
100 private: | 99 private: |
101 gin::IsolateHolder isolate_holder_; | 100 v8::Isolate* isolate_; |
102 scoped_ptr<ModuleSystemTestEnvironment> env_; | 101 scoped_ptr<ModuleSystemTestEnvironment> env_; |
103 bool should_assertions_be_made_; | 102 bool should_assertions_be_made_; |
104 | 103 |
105 private: | 104 private: |
106 DISALLOW_COPY_AND_ASSIGN(ModuleSystemTest); | 105 DISALLOW_COPY_AND_ASSIGN(ModuleSystemTest); |
107 }; | 106 }; |
108 | 107 |
109 } // namespace extensions | 108 } // namespace extensions |
110 | 109 |
111 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_TEST_H_ | 110 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_TEST_H_ |
OLD | NEW |