1 /*
2 * Copyright (c) 2025 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 #include <gtest/gtest.h>
17
18 #define private public
19 #include "base/web/webview/interfaces/native/native_javascript_execute_callback.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace NWeb {
26
27 class NativeJavascriptExecuteCallbackTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33 };
34
SetUpTestCase(void)35 void NativeJavascriptExecuteCallbackTest::SetUpTestCase(void) {}
36
TearDownTestCase(void)37 void NativeJavascriptExecuteCallbackTest::TearDownTestCase(void) {}
38
SetUp(void)39 void NativeJavascriptExecuteCallbackTest::SetUp(void) {}
40
TearDown(void)41 void NativeJavascriptExecuteCallbackTest::TearDown(void) {}
42
CallbackNative(const char * message)43 void CallbackNative(const char* message) {}
44
45 /**
46 * @tc.name : OHNativeJavascriptExecuteCallbackTest_OnReceiveValue_01
47 * @tc.desc : Test OnReceiveValue
48 */
49 HWTEST_F(NativeJavascriptExecuteCallbackTest,
50 OHNativeJavascriptExecuteCallbackTest_OnReceiveValue_01, TestSize.Level1) {
51 std::function<void(const char*)> callback = nullptr;
52 std::shared_ptr<NWebMessage> result = std::make_shared<NWebMessage>(NWebValue::Type::NONE);
53 NativeJavaScriptExecuteCallback nativeJSExecuteCallback(callback);
54 nativeJSExecuteCallback.OnReceiveValue(result);
55 }
56
57 /**
58 * @tc.name : OHNativeJavascriptExecuteCallbackTest_OnReceiveValue_02
59 * @tc.desc : Test OnReceiveValue
60 */
61 HWTEST_F(NativeJavascriptExecuteCallbackTest,
62 OHNativeJavascriptExecuteCallbackTest_OnReceiveValue_02, TestSize.Level1) {
63 std::function<void(const char*)> callback = CallbackNative;
64 std::shared_ptr<NWebMessage> result = std::make_shared<NWebMessage>(NWebValue::Type::NONE);
65 NativeJavaScriptExecuteCallback nativeJSExecuteCallback(callback);
66 nativeJSExecuteCallback.OnReceiveValue(result);
67 }
68
69 /**
70 * @tc.name : OHNativeJavascriptExecuteCallbackTest_OnReceiveValue_03
71 * @tc.desc : Test OnReceiveValue
72 */
73 HWTEST_F(NativeJavascriptExecuteCallbackTest,
74 OHNativeJavascriptExecuteCallbackTest_OnReceiveValue_03, TestSize.Level1) {
75 std::function<void(const char*)> callback = CallbackNative;
76 NativeJavaScriptExecuteCallback nativeJSExecuteCallback(callback);
77 std::shared_ptr<NWebMessage> result = std::make_shared<NWebMessage>(NWebValue::Type::STRING);
78 result->SetString("test");
79 nativeJSExecuteCallback.OnReceiveValue(result);
80 }
81
82 } // namespace NWeb
83 } // namesapce OHOS