Revision fb690bc22dd76408313b02fc08b55cbdf3350c22 authored by jgraham on 03 January 2014, 16:04:38 UTC, committed by jgraham on 03 January 2014, 16:04:38 UTC
Add tool for generating test list in JSON format
2 parent s 94d07b3 + a1ef7c8
Raw File
key_valid.html
<!DOCTYPE html>
<!-- Submitted from TestTWF Paris -->
<meta charset=utf-8">
<title>Valid key</title>
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#key-construct">
<link rel=assert title="A value is said to be a valid key if it is one of the following types: Array JavaScript objects [ECMA-262], DOMString [WEBIDL], Date [ECMA-262] or float [WEBIDL]. However Arrays are only valid keys if every item in the array is defined and is a valid key (i.e. sparse arrays can not be valid keys) and if the Array doesn't directly or indirectly contain itself. Any non-numeric properties are ignored, and thus does not affect whether the Array is a valid key. Additionally, if the value is of type float, it is only a valid key if it is not NaN, and if the value is of type Date it is only a valid key if its [[PrimitiveValue]] internal property, as defined by [ECMA-262], is not NaN. Conforming user agents must support all valid keys as keys.">
<link rel=author href="mailto:batifon@yahoo.fr" title="Baptiste Fontaine">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=support.js></script>

<script>

    var db        = createdb_for_multiple_tests(),
        // cache for ObjectStores
        objStore  = null,
        objStore2 = null;

    function valid_key(desc, key) {
        var t = async_test(document.title + " - " + desc);

        // set the current test, and run it
        db.setTest(t).onupgradeneeded = function(e) {
            objStore = objStore || e.target.result.createObjectStore("store"),
                value = "value";
            
            try { objStore.add(value, key); } catch(e) { console.log(e) };

            assert_true(objStore.add(value, key) instanceof IDBRequest);

            objStore2 = objStore2 || e.target.result.createObjectStore("store2", { keyPath: ["x", "keypath"] });

            try {
                assert_true(objStore2.add({ x: value, keypath: key }) instanceof IDBRequest);
            } catch(e) {
                assert_unreached();
            }

            this.done();
        };
    }

    // Date 
    valid_key( 'new Date()'    , new Date() );
    valid_key( 'new Date(0)'   , new Date(0) );

    // Array
    valid_key( '[]'            , [] );
    valid_key( 'new Array()'   , new Array() );

    valid_key( '["undefined"]' , ['undefined'] );

    // Float
    valid_key( 'Infinity'      , Infinity );
    valid_key( '-Infinity'     , -Infinity );
    valid_key( '0'             , 0 );
    valid_key( '1.5'           , 1.5 );
    valid_key( '3e38'          , 3e38 );
    valid_key( '3e-38'         , 3e38 );

    // String
    valid_key( '"foo"'         , "foo" );
    valid_key( '"\\n"'         , "\n" );
    valid_key( '""'            , "" );
    valid_key( '"\\""'         , "\"" );
    valid_key( '"\\u1234"'     , "\u1234" );
    valid_key( '"\\u0000"'     , "\u0000" );
    valid_key( '"NaN"'         , "NaN" );

</script>

<div id=log></div>
back to top