• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
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 "url/gurl.h"
10 #include "url/origin.h"
11 
12 // Must come after all headers that specialize FromJniType() / ToJniType().
13 #include "url/j_test_jni_headers/OriginJavaTestHelper_jni.h"
14 
15 namespace url {
16 
JNI_OriginJavaTestHelper_TestOriginEquivalence(JNIEnv * env)17 static void JNI_OriginJavaTestHelper_TestOriginEquivalence(JNIEnv* env) {
18   Origin cases[] = {
19       Origin(),
20       Origin::Create(GURL("http://a.com")),
21       Origin::Create(GURL("http://a.com:8000")),
22       Origin::Create(GURL("scheme:host")),
23       Origin::Create(GURL("http://a.com:8000")).DeriveNewOpaqueOrigin(),
24   };
25   for (const Origin& origin : cases) {
26     base::android::ScopedJavaLocalRef<jobject> j_origin =
27         origin.ToJavaObject(env);
28     Origin sameOrigin = Origin::FromJavaObject(env, j_origin);
29     if (origin != sameOrigin) {
30       std::stringstream ss;
31       ss << "Origin not equivalent: " << origin << ", " << sameOrigin;
32       env->ThrowNew(env->FindClass("java/lang/AssertionError"),
33                     ss.str().data());
34       return;
35     }
36   }
37 }
38 
39 }  // namespace url
40