Skip to content

Commit e7effd0

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/quickjs
2 parents d93c075 + 93035ed commit e7effd0

File tree

131 files changed

+2506
-1068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+2506
-1068
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ libkraken.dylib
6565
Podfile.lock
6666
.cxx
6767

68+
temp
69+
coverage

bridge/bindings/jsc/DOM/elements/input_element.cc

+10-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,16 @@ bool JSInputElement::InputElementInstance::setProperty(std::string &name, JSValu
101101
if (prototypePropertyMap.count(name) > 0) return false;
102102

103103
if (propertyMap.count(name) > 0) {
104-
JSStringRef stringRef = JSValueToStringCopy(_hostClass->ctx, value, exception);
105-
std::string string = JSStringToStdString(stringRef);
104+
JSStringRef valueString;
105+
// https://github.com/WebKit/WebKit/blob/main/Source/WebCore/html/HTMLInputElement.cpp#L1060
106+
// Webkit have specific logic when value is null.
107+
if (name == "value" && JSValueIsNull(ctx, value)) {
108+
valueString = JSStringCreateWithUTF8CString(""); // input's fallback value is null.
109+
} else {
110+
valueString = JSValueToStringCopy(_hostClass->ctx, value, exception);
111+
}
112+
113+
std::string string = JSStringToStdString(valueString);
106114
NativeString args_01{};
107115
NativeString args_02{};
108116
buildUICommandArgs(name, string, args_01, args_02);

bridge/bindings/jsc/kraken.cc

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ void bindKraken(std::unique_ptr<JSContext> &context) {
1616
JSValueProtect(context->context(), kraken);
1717

1818
// Other properties are injected by dart.
19-
JSStringRef userAgentStr = JSStringCreateWithUTF8CString(krakenInfo->getUserAgent(krakenInfo));
20-
JSC_SET_STRING_PROPERTY(context, kraken, "userAgent", JSValueMakeString(context->context(), userAgentStr));
2119
JSC_GLOBAL_SET_PROPERTY(context, "__kraken__", kraken);
2220
}
2321

bridge/bindings/qjs/kraken.cc

-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ namespace kraken::binding::qjs {
1010

1111
void bindKraken(std::unique_ptr<JSContext> &context) {
1212
JSValue krakenObject = JS_NewObject(context->ctx());
13-
KrakenInfo *krakenInfo = getKrakenInfo();
14-
const char *userAgent = krakenInfo->getUserAgent(krakenInfo);
15-
JSAtom userAgentKey = JS_NewAtom(context->ctx(), "userAgent");
16-
JS_DefinePropertyValue(context->ctx(), krakenObject, userAgentKey, JS_NewString(context->ctx(), userAgent), JS_PROP_NORMAL);
1713

1814
context->defineGlobalProperty("__kraken__", krakenObject);
19-
JS_FreeAtom(context->ctx(), userAgentKey);
2015
}
2116
}

bridge/bindings/qjs/module_manager.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,16 @@ JSValue krakenInvokeModule(QjsContext *ctx, JSValueConst this_val, int argc, JSV
117117
return JS_NULL;
118118
};
119119
JSValue callbackFunc = JS_NewCFunction(ctx, emptyFunction, "_f", 0);
120-
moduleContext = new ModuleContext{callbackFunc};
120+
moduleContext = new ModuleContext{
121+
callbackFunc, context
122+
};
121123
} else {
122124
moduleContext = new ModuleContext{
123-
JS_DupValue(ctx, callbackValue)
125+
JS_DupValue(ctx, callbackValue),
126+
context
124127
};
125128
}
126-
list_add_tail(&context->module_list, &moduleContext->link);
129+
list_add_tail(&moduleContext->link, &context->module_list);
127130

128131
NativeString *result;
129132

bridge/include/kraken_bridge.h

-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ struct KRAKEN_EXPORT NativeString {
3333

3434
struct KrakenInfo;
3535

36-
using GetUserAgent = const char *(*)(KrakenInfo *);
3736
struct KrakenInfo {
3837
const char *app_name{nullptr};
3938
const char *app_version{nullptr};
4039
const char *app_revision{nullptr};
4140
const char *system_name{nullptr};
42-
GetUserAgent getUserAgent;
4341
};
4442

4543
struct Screen {

bridge/kraken_bridge.cc

-10
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,13 @@ Screen *createScreen(double width, double height) {
186186

187187
static KrakenInfo *krakenInfo{nullptr};
188188

189-
const char *getUserAgent(KrakenInfo *info) {
190-
const char *format = "%s/%s (%s; %s/%s)";
191-
int32_t length = strlen(format) + sizeof(*info);
192-
char *buf = new char[length];
193-
std::string result;
194-
std::snprintf(&buf[0], length, format, info->app_name, info->app_version, info->system_name, info->app_name, info->app_revision);
195-
return buf;
196-
}
197-
198189
KrakenInfo *getKrakenInfo() {
199190
if (krakenInfo == nullptr) {
200191
krakenInfo = new KrakenInfo();
201192
krakenInfo->app_name = "Kraken";
202193
krakenInfo->app_revision = APP_REV;
203194
krakenInfo->app_version = APP_VERSION;
204195
krakenInfo->system_name = SYSTEM_NAME;
205-
krakenInfo->getUserAgent = getUserAgent;
206196
}
207197

208198
return krakenInfo;

bridge/polyfill/src/bridge.ts

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export interface PrivateKraken {
1414
product: string;
1515
productSub: string;
1616
comment: string;
17-
userAgent: string;
1817
}
1918

2019
declare const __kraken__: PrivateKraken;

bridge/polyfill/src/navigator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const navigator = {
77
connection,
88
// UA is read-only.
99
get userAgent() {
10-
return kraken.userAgent;
10+
return kraken.invokeModule('Navigator', 'getUserAgent');
1111
},
1212
get hardwareConcurrency() {
1313
const logicalProcessors = kraken.invokeModule('DeviceInfo', 'getHardwareConcurrency');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
Content-Length: 72
4+
ETag: "4EE5B35FB8C5FB2CF8041FC41D3D199E"
5+
expires: Mon, 16 Aug 2221 10:17:45 GMT
6+
Last-Modified: Sun, 15 Mar 2020 11:32:20 GMT
7+
8+
{
9+
"method": "GET",
10+
"data": {
11+
"userName": "12345"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../kraken/test/local_http_server.dart

integration_tests/lib/main.dart

+29-11
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import 'dart:async';
22
import 'dart:io';
33
import 'package:flutter/material.dart';
44
import 'package:flutter/widgets.dart';
5+
import 'package:kraken/css.dart';
56
import 'package:kraken/bridge.dart';
67
import 'package:kraken/dom.dart';
8+
import 'package:kraken/foundation.dart';
79
import 'package:kraken/module.dart';
810
import 'package:kraken/widget.dart';
9-
import 'package:kraken/css.dart';
1011
import 'package:ansicolor/ansicolor.dart';
1112
import 'package:path/path.dart' as path;
1213
import 'bridge/from_native.dart';
@@ -20,6 +21,7 @@ import 'package:kraken/foundation.dart';
2021
// import 'package:kraken_animation_player/kraken_animation_player.dart';
2122
// import 'package:kraken_video_player/kraken_video_player.dart';
2223
// import 'package:kraken_webview/kraken_webview.dart';
24+
import 'local_http_server.dart'
2325

2426
String? pass = (AnsiPen()..green())('[TEST PASS]');
2527
String? err = (AnsiPen()..red())('[TEST FAILED]');
@@ -53,11 +55,16 @@ class NativeGestureClient implements GestureClient {
5355
}
5456
}
5557

56-
class MyUriParser extends UriParser {
58+
// Test for UriParser.
59+
class IntegrationTestUriParser extends UriParser {
5760
@override
58-
String resolve(Uri base, Uri relative) {
59-
String uri = super.resolve(base, relative);
60-
return uri;
61+
Uri resolve(Uri base, Uri relative) {
62+
if (base.toString().isEmpty
63+
&& relative.path.startsWith('assets/')) {
64+
return Uri.file(relative.path);
65+
} else {
66+
return super.resolve(base, relative);
67+
}
6168
}
6269
}
6370

@@ -68,6 +75,17 @@ void main() async {
6875
// KrakenVideoPlayer.initialize();
6976
// KrakenWebView.initialize();
7077
// defineKrakenCustomElements();
78+
79+
// Local HTTP server.
80+
var httpServer = LocalHttpServer.getInstance();
81+
print('Local HTTP server started at: ${httpServer.getUri()}');
82+
83+
String codeInjection = '''
84+
// This segment inject variables for test environment.
85+
LOCAL_HTTP_SERVER = '${httpServer.getUri().toString()}';
86+
''';
87+
88+
7189
// Set render font family AlibabaPuHuiTi to resolve rendering difference.
7290
CSSText.DEFAULT_FONT_FAMILY_FALLBACK = ['AlibabaPuHuiTi'];
7391
// setObjectElementFactory(customObjectElementFactory);
@@ -99,21 +117,21 @@ void main() async {
99117
return 'method: ' + method;
100118
};
101119

102-
krakenMap[i] = Kraken(
120+
var kraken = krakenMap[i] = Kraken(
103121
viewportWidth: 360,
104122
viewportHeight: 640,
105123
bundleContent: 'console.log("Starting integration tests...")',
106124
disableViewportWidthAssertion: true,
107125
disableViewportHeightAssertion: true,
108126
javaScriptChannel: javaScriptChannel,
109-
gestureClient: NativeGestureClient(gestureClientID:i),
110-
uriParser: MyUriParser(),
127+
gestureClient: NativeGestureClient(gestureClientID: i),
128+
uriParser: IntegrationTestUriParser(),
111129
);
112-
widgets.add(krakenMap[i]!);
130+
widgets.add(kraken);
113131
}
114132

115133
runApp(MaterialApp(
116-
title: 'Kraken Intergration Tests',
134+
title: 'Kraken Integration Tests',
117135
debugShowCheckedModeBanner: false,
118136
home: Scaffold(
119137
appBar: AppBar(
@@ -146,7 +164,7 @@ void main() async {
146164
for (Map spec in testPayload) {
147165
String filename = spec['filename'];
148166
String code = spec['code'];
149-
evaluateTestScripts(contextId, code, url: filename);
167+
evaluateTestScripts(contextId, codeInjection + code, url: filename);
150168
}
151169

152170
testResults.add(executeTest(contextId));

integration_tests/runtime/kraken.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ interface HTMLMediaElement {
6262
interface HTMLElement {
6363
toBlob(devicePixcelRatio: number): Promise<Blob>;
6464
}
65+
66+
/**
67+
* The mocked local http server origin.
68+
*/
69+
declare const LOCAL_HTTP_SERVER :string;
Loading
Loading
Loading

integration_tests/specs/css/css-backgrounds/background-size.ts

+23
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,29 @@ describe('Background-size', () => {
357357
await snapshot(0.1);
358358
});
359359

360+
it('should works with background size bigger than image container', async () => {
361+
let div1;
362+
let div = createElement(
363+
'div',
364+
{
365+
style: {},
366+
},
367+
[
368+
(div1 = createElement('div', {
369+
style: {
370+
height: '150px',
371+
width: '200px',
372+
backgroundColor: '#999',
373+
backgroundImage: 'url(assets/bg.jpg)',
374+
backgroundRepeat: 'no-repeat',
375+
backgroundSize: '250px',
376+
},
377+
})),
378+
]
379+
);
380+
append(BODY, div);
381+
await snapshot(0.1);
382+
});
360383

361384
it('should not work with negative value', async () => {
362385
let div1;

0 commit comments

Comments
 (0)