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 23 namespace OHOS { 24 namespace AbilityRuntime { 25 class MockJsRuntime : public JsRuntime { 26 public: 27 MockJsRuntime() = default; 28 ~MockJsRuntime() = default; 29 StartDebugMode(const DebugOption debugOption)30 void StartDebugMode(const DebugOption debugOption) 31 {} FinishPreload()32 void FinishPreload() 33 { 34 GTEST_LOG_(INFO) << "MockJsRuntime::FinishPreload called"; 35 } LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)36 bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) 37 { 38 return true; 39 } NotifyHotReloadPage()40 bool NotifyHotReloadPage() 41 { 42 return true; 43 } UnLoadRepairPatch(const std::string & patchFile)44 bool UnLoadRepairPatch(const std::string& patchFile) 45 { 46 return true; 47 } 48 bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false) 49 { 50 GTEST_LOG_(INFO) << "MockJsRuntime::RunScript called"; 51 return true; 52 } Initialize(const Options & options)53 bool Initialize(const Options& options) 54 { 55 GTEST_LOG_(INFO) << "MockJsRuntime::Initialize called"; 56 return true; 57 } Deinitialize()58 void Deinitialize() 59 {} 60 napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false) 61 { 62 GTEST_LOG_(INFO) << "MockJsRuntime::LoadJsBundle called"; 63 return nullptr; 64 } LoadJsModule(const std::string & path,const std::string & hapPath)65 napi_value LoadJsModule(const std::string& path, const std::string& hapPath) 66 { 67 GTEST_LOG_(INFO) << "MockJsRuntime::LoadJsModule called"; 68 return nullptr; 69 } PreloadSystemModule(const std::string & moduleName)70 void PreloadSystemModule(const std::string& moduleName) 71 { 72 GTEST_LOG_(INFO) << "MockJsRuntime::PreloadSystemModule called"; 73 } PreloadMainAbility(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,const std::string & srcEntrance)74 void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath, 75 const std::string& hapPath, bool isEsMode, const std::string& srcEntrance) override 76 { 77 GTEST_LOG_(INFO) << "MockJsRuntime::PreloadMainAbility called"; 78 } PreloadModule(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)79 void PreloadModule(const std::string& moduleName, const std::string& srcPath, 80 const std::string& hapPath, bool isEsMode, bool useCommonTrunk)override 81 { 82 GTEST_LOG_(INFO) << "MockJsRuntime::PreloadModule called"; 83 } 84 std::unique_ptr<NativeReference> LoadModule( 85 const std::string& moduleName, const std::string& modulePath, const std::string& hapPath, bool esmodule = false) 86 { 87 GTEST_LOG_(INFO) << "MockJsRuntime::LoadModule called"; 88 return nullptr; 89 } 90 std::unique_ptr<NativeReference> LoadSystemModule( 91 const std::string& moduleName, napi_value const* argv = nullptr, size_t argc = 0) 92 { 93 GTEST_LOG_(INFO) << "MockJsRuntime::LoadSystemModule called"; 94 return nullptr; 95 } GetFileBuffer(const std::string & filePath,std::string & fileFullName,std::vector<uint8_t> & buffer)96 bool GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer) 97 { 98 GTEST_LOG_(INFO) << "MockJsRuntime::GetFileBuffer called"; 99 return true; 100 } DumpHeapSnapshot(bool isPrivate)101 void DumpHeapSnapshot(bool isPrivate) 102 {} 103 }; 104 } // namespace AbilityRuntime 105 } // namespace OHOS 106 #endif // MOCK_JS_RUNTIME_H 107