• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
30     void StartDebugMode(bool needBreakPoint, const std::string &processName, bool isDebug = true)
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     }
74     std::unique_ptr<NativeReference> LoadModule(
75         const std::string& moduleName, const std::string& modulePath, const std::string& hapPath, bool esmodule = false)
76     {
77         GTEST_LOG_(INFO) << "MockJsRuntime::LoadModule called";
78         return nullptr;
79     }
80     std::unique_ptr<NativeReference> LoadSystemModule(
81         const std::string& moduleName, napi_value const* argv = nullptr, size_t argc = 0)
82     {
83         GTEST_LOG_(INFO) << "MockJsRuntime::LoadSystemModule called";
84         return nullptr;
85     }
GetFileBuffer(const std::string & filePath,std::string & fileFullName,std::vector<uint8_t> & buffer)86     bool GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer)
87     {
88         GTEST_LOG_(INFO) << "MockJsRuntime::GetFileBuffer called";
89         return true;
90     }
91 };
92 }  // namespace AbilityRuntime
93 }  // namespace OHOS
94 #endif  // MOCK_JS_RUNTIME_H
95