1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/test/icu_test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "url/android/gurl_android.h"
12 #include "url/gurl.h"
13 #include "url/gurl_j_test_jni_headers/GURLJavaTestHelper_jni.h"
14
15 using base::android::AttachCurrentThread;
16
17 namespace url {
18
JNI_GURLJavaTestHelper_InitializeICU(JNIEnv * env)19 static void JNI_GURLJavaTestHelper_InitializeICU(JNIEnv* env) {
20 base::test::InitializeICUForTesting();
21 }
22
JNI_GURLJavaTestHelper_TestGURLEquivalence(JNIEnv * env)23 static void JNI_GURLJavaTestHelper_TestGURLEquivalence(JNIEnv* env) {
24 const char* cases[] = {
25 // Common Standard URLs.
26 "https://www.google.com",
27 "https://www.google.com/",
28 "https://www.google.com/maps.htm",
29 "https://www.google.com/maps/",
30 "https://www.google.com/index.html",
31 "https://www.google.com/index.html?q=maps",
32 "https://www.google.com/index.html#maps/",
33 "https://foo:bar@www.google.com/maps.htm",
34 "https://www.google.com/maps/au/index.html",
35 "https://www.google.com/maps/au/north",
36 "https://www.google.com/maps/au/north/",
37 "https://www.google.com/maps/au/index.html?q=maps#fragment/",
38 "http://www.google.com:8000/maps/au/index.html?q=maps#fragment/",
39 "https://www.google.com/maps/au/north/?q=maps#fragment",
40 "https://www.google.com/maps/au/north?q=maps#fragment",
41 // Less common standard URLs.
42 "filesystem:http://www.google.com/temporary/bar.html?baz=22",
43 "file:///temporary/bar.html?baz=22",
44 "ftp://foo/test/index.html",
45 "gopher://foo/test/index.html",
46 "ws://foo/test/index.html",
47 // Non-standard,
48 "chrome://foo/bar.html",
49 "httpa://foo/test/index.html",
50 "blob:https://foo.bar/test/index.html",
51 "about:blank",
52 "data:foobar",
53 "scheme:opaque_data",
54 // Invalid URLs.
55 "foobar",
56 };
57 for (const char* uri : cases) {
58 GURL gurl(uri);
59 base::android::ScopedJavaLocalRef<jobject> j_gurl =
60 Java_GURLJavaTestHelper_createGURL(
61 env, base::android::ConvertUTF8ToJavaString(env, uri));
62 std::unique_ptr<GURL> gurl2 = GURLAndroid::ToNativeGURL(env, j_gurl);
63 EXPECT_EQ(gurl, *gurl2);
64 }
65 }
66
67 } // namespace url
68