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 #include "nweb_js_dialog_impl_test.h"
17 #include "nweb_test_log.h"
18
19 namespace OHOS::NWeb {
SetNWeb(std::shared_ptr<NWeb> nweb)20 void NWebJSDialogImplTest::SetNWeb(std::shared_ptr<NWeb> nweb)
21 {
22 nwebweak_ = nweb;
23 }
24
OnAlertDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)25 bool NWebJSDialogImplTest::OnAlertDialogByJS(const std::string &url,
26 const std::string &message,
27 std::shared_ptr<NWebJSDialogResult> result)
28 {
29 TESTLOG_I("OnAlertDialogByJS message:%{public}s", message.c_str());
30 type_ == Type::CONFIRM ? result->Confirm() : result->Cancel();
31 return true;
32 }
33
OnBeforeUnloadByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)34 bool NWebJSDialogImplTest::OnBeforeUnloadByJS(const std::string &url,
35 const std::string &message,
36 std::shared_ptr<NWebJSDialogResult> result)
37 {
38 TESTLOG_I("OnBeforeUnloadByJS message:%{public}s", message.c_str());
39 type_ == Type::CONFIRM ? result->Confirm() : result->Cancel();
40 return true;
41 }
42
OnPromptDialogByJS(const std::string & url,const std::string & message,const std::string & defaultValue,std::shared_ptr<NWebJSDialogResult> result)43 bool NWebJSDialogImplTest::OnPromptDialogByJS(const std::string &url,
44 const std::string &message,
45 const std::string &defaultValue,
46 std::shared_ptr<NWebJSDialogResult> result)
47 {
48 TESTLOG_I("OnPromptDialogByJS message:%{public}s", message.c_str());
49 TESTLOG_I("OnPromptDialogByJS defaultValue:%{public}s", defaultValue.c_str());
50 type_ == Type::CONFIRM ? result->Confirm("my input") : result->Cancel();
51 return true;
52 }
53
OnConfirmDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)54 bool NWebJSDialogImplTest::OnConfirmDialogByJS(const std::string &url,
55 const std::string &message,
56 std::shared_ptr<NWebJSDialogResult> result)
57 {
58 TESTLOG_I("OnConfirmDialogByJS message:%{public}s", message.c_str());
59 type_ == Type::CONFIRM ? result->Confirm() : result->Cancel();
60 return true;
61 }
62
OnConsoleLog(const NWebConsoleLog & message)63 bool NWebJSDialogImplTest::OnConsoleLog(const NWebConsoleLog& message)
64 {
65 TESTLOG_I("message:%{public}s", message.Log().c_str());
66 TESTLOG_I("lineNumer:%{public}d", message.LineNumer());
67 TESTLOG_I("messageLevel:%{public}d", message.LogLevel());
68 TESTLOG_I("sourceId:%{public}s", message.SourceId().c_str());
69 return true;
70 }
71 }