mirror of
				https://github.com/mozilla/gecko-dev.git
				synced 2025-11-04 10:18:41 +02:00 
			
		
		
		
	Automatic update from web-platform-tests Geolocation: generalize tojson.https.window.js (#47087) * Geolocation: generalize tojson.https.window.js * remove setup desc -- wpt-commits: 073136dbb2cba46d864f7e71ef2420c5775bb3b8 wpt-pr: 47087
		
			
				
	
	
		
			37 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
// META: script=/resources/testdriver.js
 | 
						|
// META: script=/resources/testdriver-vendor.js
 | 
						|
"use strict";
 | 
						|
 | 
						|
function check_equals(original, json) {
 | 
						|
  const proto = Object.getPrototypeOf(original);
 | 
						|
  const keys = Object.keys(proto).filter(
 | 
						|
    (k) => typeof original[k] !== "function",
 | 
						|
  );
 | 
						|
  for (const key of keys) {
 | 
						|
    assert_equals(
 | 
						|
      original[key],
 | 
						|
      json[key],
 | 
						|
      `${original.constructor.name} ${key} entry does not match its toJSON value`,
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
promise_setup(async () => {
 | 
						|
  await test_driver.set_permission({ name: "geolocation" }, "granted");
 | 
						|
});
 | 
						|
 | 
						|
promise_test(async (t) => {
 | 
						|
  const position = await new Promise((resolve, reject) => {
 | 
						|
    navigator.geolocation.getCurrentPosition(resolve, reject);
 | 
						|
  });
 | 
						|
 | 
						|
  const json = position.toJSON();
 | 
						|
  assert_equals(
 | 
						|
    position.timestamp,
 | 
						|
    json.timestamp,
 | 
						|
    "GeolocationPosition timestamp entry does not match its toJSON value",
 | 
						|
  );
 | 
						|
 | 
						|
  check_equals(position.coords, json.coords);
 | 
						|
  check_equals(position.coords, position.coords.toJSON());
 | 
						|
}, "Test toJSON() in GeolocationPosition and GeolocationCoordinates.");
 |