Commit 421cfbd8 authored by lwchkg@gmail.com's avatar lwchkg@gmail.com

- Changed instrumentation-service-worker.js so the value NaN can be copied...

- Changed instrumentation-service-worker.js so the value NaN can be copied properly in cloneNotification.
- Added testing of NaN and null in serviceworker-notificationclick-event-data-reflection.html

BUG=525652

Review URL: https://codereview.chromium.org/1311413006

git-svn-id: svn://svn.chromium.org/blink/trunk@201562 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4bbcb1a2
importScripts('/resources/testharness-helpers.js'); importScripts('/resources/testharness-helpers.js');
// For copying Notification.data. Currently a deep copy algorithm is used. Note
// that the robustness of this function (and also |assert_object_equals| in
// testharness.js) affects the types of possible testing can be done.
// TODO(peter): change this to a structured clone algorithm.
function cloneObject(src) {
if (typeof src != 'object' || src === null)
return src;
var dst = Array.isArray(src) ? [] : {};
for (var property in src) {
if (src.hasOwnProperty(property))
dst[property] = cloneObject(src[property]);
}
return dst;
}
// Copies the serializable attributes of |notification|. // Copies the serializable attributes of |notification|.
function cloneNotification(notification) { function cloneNotification(notification) {
return JSON.parse(stringifyDOMObject(notification)); var copiedNotification = JSON.parse(stringifyDOMObject(notification));
copiedNotification.data = cloneObject(notification.data);
return copiedNotification;
} }
// Allows a document to exercise the Notifications API within a service worker by sending commands. // Allows a document to exercise the Notifications API within a service worker by sending commands.
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
var notificationDataList = new Array( var notificationDataList = new Array(
true, // Check Boolean type true, // Check Boolean type
1024, // Check Number type 1024, // Check Number type
Number.NaN, // Check Number.NaN type
'any data', // Check String type 'any data', // Check String type
null, // Check null
new Array('Saab', 'Volvo', 'BMW'), // Check Array type new Array('Saab', 'Volvo', 'BMW'), // Check Array type
{ first: 'first', second: 'second' } // Check object { first: 'first', second: 'second' } // Check object
); );
...@@ -63,7 +65,7 @@ ...@@ -63,7 +65,7 @@
var pos = event.data.notification.tag; var pos = event.data.notification.tag;
if (typeof notificationDataList[pos] === 'object') if (typeof notificationDataList[pos] === 'object' && notificationDataList[pos] !== null)
assert_object_equals(event.data.notification.data, notificationDataList[pos], 'The data field must be the same.'); assert_object_equals(event.data.notification.data, notificationDataList[pos], 'The data field must be the same.');
else else
assert_equals(event.data.notification.data, notificationDataList[pos], 'The data field must be the same.'); assert_equals(event.data.notification.data, notificationDataList[pos], 'The data field must be the same.');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment