| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_TEST_BASE_V8_UNIT_TEST_H_ | 5 #ifndef CHROME_TEST_BASE_V8_UNIT_TEST_H_ |
| 6 #define CHROME_TEST_BASE_V8_UNIT_TEST_H_ | 6 #define CHROME_TEST_BASE_V8_UNIT_TEST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // will log |args| to the console and also signal an error condition causing | 61 // will log |args| to the console and also signal an error condition causing |
| 62 // |RunJavascriptF| to fail. | 62 // |RunJavascriptF| to fail. |
| 63 static void Error(const v8::FunctionCallbackInfo<v8::Value>& args); | 63 static void Error(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 64 | 64 |
| 65 // This method is bound to a method "chrome.send" in the context. When | 65 // This method is bound to a method "chrome.send" in the context. When |
| 66 // test_api calls testDone with |args| to report its results, this will | 66 // test_api calls testDone with |args| to report its results, this will |
| 67 // capture and hold the results for analysis by |RunJavascriptF|. | 67 // capture and hold the results for analysis by |RunJavascriptF|. |
| 68 static void ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args); | 68 static void ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 // A helper class to ensure that the lifetimes of the Isolate and the | |
| 72 // HandleScope are correctly nested. | |
| 73 class IsolateScope { | |
| 74 public: | |
| 75 IsolateScope() : isolate_(v8::Isolate::New()) { isolate_->Enter(); } | |
| 76 | |
| 77 ~IsolateScope() { | |
| 78 isolate_->Exit(); | |
| 79 isolate_->Dispose(); | |
| 80 } | |
| 81 | |
| 82 v8::Isolate* isolate() const { return isolate_; } | |
| 83 | |
| 84 private: | |
| 85 v8::Isolate* isolate_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(IsolateScope); | |
| 88 }; | |
| 89 | |
| 90 // A handy shortcut. | |
| 91 v8::Isolate* isolate() const { return isolate_scope_.isolate(); } | |
| 92 | |
| 93 // Executes all added javascript libraries. Returns true if no errors. | 71 // Executes all added javascript libraries. Returns true if no errors. |
| 94 bool ExecuteJavascriptLibraries(); | 72 bool ExecuteJavascriptLibraries(); |
| 95 | 73 |
| 96 // Initializes paths and libraries. | 74 // Initializes paths and libraries. |
| 97 void InitPathsAndLibraries(); | 75 void InitPathsAndLibraries(); |
| 98 | 76 |
| 99 IsolateScope isolate_scope_; | |
| 100 | |
| 101 // Handle scope that is used throughout the life of this class. | 77 // Handle scope that is used throughout the life of this class. |
| 102 v8::HandleScope handle_scope_; | 78 v8::HandleScope handle_scope_; |
| 103 | 79 |
| 104 // Context for the JavaScript in the test. | 80 // Context for the JavaScript in the test. |
| 105 v8::Persistent<v8::Context> context_; | 81 v8::Persistent<v8::Context> context_; |
| 106 | 82 |
| 107 // User added libraries. | 83 // User added libraries. |
| 108 std::vector<base::FilePath> user_libraries_; | 84 std::vector<base::FilePath> user_libraries_; |
| 109 }; | 85 }; |
| 110 | 86 |
| 111 #endif // CHROME_TEST_BASE_V8_UNIT_TEST_H_ | 87 #endif // CHROME_TEST_BASE_V8_UNIT_TEST_H_ |
| OLD | NEW |