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 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "base/test/scoped_async_task_scheduler.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
16 | 15 |
17 // A superclass for unit tests that involve running JavaScript. This class | 16 // A superclass for unit tests that involve running JavaScript. This class |
18 // sets up V8 context and has methods that make it easy to execute scripts in | 17 // sets up V8 context and has methods that make it easy to execute scripts in |
19 // this context as well as call functions in the context. | 18 // this context as well as call functions in the context. |
20 class V8UnitTest : public testing::Test { | 19 class V8UnitTest : public testing::Test { |
21 public: | 20 public: |
22 V8UnitTest(); | 21 V8UnitTest(); |
23 ~V8UnitTest() override; | 22 ~V8UnitTest() override; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // capture and hold the results for analysis by |RunJavascriptF|. | 67 // capture and hold the results for analysis by |RunJavascriptF|. |
69 static void ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args); | 68 static void ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args); |
70 | 69 |
71 private: | 70 private: |
72 // Executes all added javascript libraries. Returns true if no errors. | 71 // Executes all added javascript libraries. Returns true if no errors. |
73 bool ExecuteJavascriptLibraries(); | 72 bool ExecuteJavascriptLibraries(); |
74 | 73 |
75 // Initializes paths and libraries. | 74 // Initializes paths and libraries. |
76 void InitPathsAndLibraries(); | 75 void InitPathsAndLibraries(); |
77 | 76 |
78 // Required by gin::V8Platform::CallOnBackgroundThread(). Can't be a | |
79 // ScopedTaskScheduler because v8 synchronously waits for tasks to run. | |
80 base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler_; | |
81 | |
82 // Handle scope that is used throughout the life of this class. | 77 // Handle scope that is used throughout the life of this class. |
83 v8::HandleScope handle_scope_; | 78 v8::HandleScope handle_scope_; |
84 | 79 |
85 // Context for the JavaScript in the test. | 80 // Context for the JavaScript in the test. |
86 v8::Persistent<v8::Context> context_; | 81 v8::Persistent<v8::Context> context_; |
87 | 82 |
88 // User added libraries. | 83 // User added libraries. |
89 std::vector<base::FilePath> user_libraries_; | 84 std::vector<base::FilePath> user_libraries_; |
90 }; | 85 }; |
91 | 86 |
92 #endif // CHROME_TEST_BASE_V8_UNIT_TEST_H_ | 87 #endif // CHROME_TEST_BASE_V8_UNIT_TEST_H_ |
OLD | NEW |