tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

pagevistestharness.js (2728B)


      1 //
      2 // Helper functions for Page Visibility tests
      3 //
      4 
      5 var VISIBILITY_STATES =
      6 {
      7    HIDDEN: "hidden",
      8    VISIBLE: "visible"
      9 };
     10 
     11 var feature_check = false;
     12 
     13 //
     14 // All test() functions in the WebPerf PageVis test suite should use pv_test() instead.
     15 //
     16 // pv_test() validates the document.hidden and document.visibilityState attributes
     17 // exist prior to running tests and immediately shows a failure if they do not.
     18 //
     19 
     20 function pv_test(func, msg, doc)
     21 {
     22    if (!doc)
     23    {
     24        doc = document;
     25    }
     26 
     27    // only run the feature check once, unless func == null, in which case,
     28    // this call is intended as a feature check
     29    if (!feature_check)
     30    {
     31        feature_check = true;
     32 
     33        var hiddenVal = doc.hidden;
     34        var visStateVal = doc.visibilityState;
     35 
     36        // show a single error that the Page Visibility feature is undefined
     37        test(function()
     38        {
     39            assert_true(hiddenVal !== undefined && hiddenVal != null,
     40                        "document.hidden is defined and not null.");},
     41                        "document.hidden is defined and not null.");
     42 
     43        test(function()
     44        {
     45            assert_true(visStateVal !== undefined && hiddenVal != null,
     46                        "document.visibilityState is defined and not null.");},
     47                        "document.visibilityState is defined and not null.");
     48 
     49    }
     50 
     51    if (func)
     52    {
     53        test(func, msg);
     54    }
     55 }
     56 
     57 
     58 function test_feature_exists(doc, msg)
     59 {
     60    if (!msg)
     61    {
     62        msg = "";
     63    }
     64    var hiddenMsg = "document.hidden is defined" + msg + ".";
     65    var stateMsg = "document.visibilityState is defined" + msg + ".";
     66    pv_test(function(){assert_not_equals(document.hidden, undefined, hiddenMsg);}, hiddenMsg, doc);
     67    pv_test(function(){assert_not_equals(document.visibilityState, undefined, stateMsg);}, stateMsg, doc);
     68 }
     69 
     70 //
     71 // Common helper functions
     72 //
     73 
     74 function test_true(value, msg)
     75 {
     76    pv_test(function() { assert_true(value, msg); }, msg);
     77 }
     78 
     79 function test_equals(value, equals, msg)
     80 {
     81    pv_test(function() { assert_equals(value, equals, msg); }, msg);
     82 }
     83 
     84 //
     85 // asynchronous test helper functions
     86 //
     87 
     88 function add_async_result(test_obj, pass_state)
     89 {
     90    // add assertion to manual test for the pass state
     91    test_obj.step(function() { assert_true(pass_state) });
     92 
     93    // end manual test
     94    test_obj.done();
     95 }
     96 
     97 function add_async_result_assert(test_obj, func)
     98 {
     99    // add assertion to manual test for the pass state
    100    test_obj.step(func);
    101 
    102    // end manual test
    103    test_obj.done();
    104 }
    105 
    106 var open_link;
    107 function TabSwitch()
    108 {
    109    //var open_link = window.open("http://www.bing.com");
    110    open_link = window.open('', '_blank');
    111    step_timeout(function() { open_link.close(); }, 2000);
    112 }