1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MOCK_JS_RUNTIME_H 17 #define MOCK_JS_RUNTIME_H 18 19 #include <gtest/gtest.h> 20 21 #include "js_runtime.h" 22 #include "mock_js_native_engine.h" 23 24 namespace OHOS { 25 namespace AbilityRuntime { 26 class MockJsRuntime : public JsRuntime { 27 public: 28 MockJsRuntime() = default; 29 ~MockJsRuntime() = default; 30 StartDebugMode(bool needBreakPoint)31 void StartDebugMode(bool needBreakPoint) 32 {} FinishPreload()33 void FinishPreload() 34 { 35 GTEST_LOG_(INFO) << "MockJsRuntime::FinishPreload called"; 36 } LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)37 bool LoadRepairPatch(const std::string &patchFile, const std::string &baseFile) 38 { 39 return true; 40 } NotifyHotReloadPage()41 bool NotifyHotReloadPage() 42 { 43 return true; 44 } UnLoadRepairPatch(const std::string & patchFile)45 bool UnLoadRepairPatch(const std::string &patchFile) 46 { 47 return true; 48 } 49 bool RunScript(const std::string &path, const std::string &hapPath, bool useCommonChunk = false) 50 { 51 GTEST_LOG_(INFO) << "MockJsRuntime::RunScript called"; 52 return true; 53 } Initialize(const Options & options)54 bool Initialize(const Options &options) 55 { 56 GTEST_LOG_(INFO) << "MockJsRuntime::Initialize called"; 57 return true; 58 } Deinitialize()59 void Deinitialize() 60 {} 61 NativeValue* LoadJsBundle(const std::string &path, const std::string &hapPath, bool useCommonChunk = false) 62 { 63 GTEST_LOG_(INFO) << "MockJsRuntime::LoadJsBundle called"; 64 return nullptr; 65 } LoadJsModule(const std::string & path,const std::string & hapPath)66 NativeValue *LoadJsModule(const std::string &path, const std::string &hapPath) 67 { 68 GTEST_LOG_(INFO) << "MockJsRuntime::LoadJsModule called"; 69 return nullptr; 70 } PreloadSystemModule(const std::string & moduleName)71 void PreloadSystemModule(const std::string &moduleName) 72 { 73 GTEST_LOG_(INFO) << "MockJsRuntime::PreloadSystemModule called"; 74 } 75 std::unique_ptr<NativeReference> LoadModule( 76 const std::string &moduleName, const std::string &modulePath, const std::string &hapPath, bool esmodule = false) 77 { 78 GTEST_LOG_(INFO) << "MockJsRuntime::LoadModule called"; 79 return nullptr; 80 } 81 std::unique_ptr<NativeReference> LoadSystemModule( 82 const std::string &moduleName, NativeValue *const *argv = nullptr, size_t argc = 0) 83 { 84 GTEST_LOG_(INFO) << "MockJsRuntime::LoadSystemModule called"; 85 return nullptr; 86 } 87 }; 88 } // namespace AbilityRuntime 89 } // namespace OHOS 90 #endif // MOCK_JS_RUNTIME_H 91