tor-browser

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

test_minimize-manual.html (8090B)


      1 <!DOCTYPE html>
      2 <html>
      3    <head>
      4        <meta charset="utf-8" />
      5        <title>Page Visibility API Operation While Minimizing Browser Window</title>
      6        <meta name="flags" content="interact" />
      7        <script type="text/javascript" src="/resources/testharness.js"></script>
      8        <script type="text/javascript" src="/resources/testharnessreport.js"></script>
      9        <script type="text/javascript" src="resources/pagevistestharness.js"></script>
     10 
     11    </head>
     12    <body>
     13        <h1>Description</h1>
     14        <p>This test validates that the page properly becomes hidden and visible due to minimizing, maximizing, and
     15           restoring the browser window.</p>
     16 
     17        <h1>Manual Test Steps:</h1>
     18        <p>
     19            <ol>
     20                <li> Ensure this page is the foreground and click the "Start Test"</li>
     21                <li> Minimize the browser</li>
     22                <li> Restore or maximize the browser</li>
     23            </ol>
     24            Note: This test will automatically timeout and fail if not completed within 60 seconds.
     25        </p>
     26 
     27        <button onclick="start_test();">Start Test</button>
     28 
     29        <div id="log"></div>
     30 
     31        <br />
     32        IFrame with default style:
     33        <br />
     34        <iframe id="childDocShown" src="resources/blank_page_green.html">
     35            iframes unsupported
     36        </iframe>
     37        <hr />
     38        IFrame with "display:none" style:
     39        <br />
     40        <iframe id="childDocHidden" src="resources/blank_page_green.html" style="display:none">
     41            iframes unsupported
     42        </iframe>
     43 
     44        <script type="text/javascript" >
     45            var child_doc_shown = null;
     46            var child_doc_hidden = null;
     47            var transition_mode;
     48            var manual_test = null;
     49 
     50            var expected_notification_count = 2;
     51            var notification_count = new Array();
     52            var page_docs = new Array();
     53            var notification_handlers = new Array();
     54            var two_notifications = false;
     55 
     56            var PAGE_HIDDEN_VAL = "hidden";
     57            var PAGE_VISIBLE_VAL = "visible";
     58 
     59            setup({ explicit_done: true });
     60 
     61            function test_transition_init()
     62            {
     63                child_doc_shown = document.getElementById("childDocShown").contentDocument;
     64                child_doc_hidden = document.getElementById("childDocHidden").contentDocument;
     65 
     66                // fill in data for page documents
     67                page_docs.push([document, "document"]);
     68                page_docs.push([child_doc_shown, "document.getElementById(\"childDocShown\").contentDocument"]);
     69                page_docs.push([child_doc_hidden, "document.getElementById(\"childDocHidden\").contentDocument"]);
     70 
     71                notification_handlers[0] = function(){ VerifyNotification(0); };
     72                notification_handlers[1] = function(){ VerifyNotification(1); };
     73                notification_handlers[2] = function(){ VerifyNotification(2); };
     74 
     75                for (var i in page_docs)
     76                {
     77                    notification_count[i] = 0;
     78                    page_docs[i][0].addEventListener("visibilitychange", notification_handlers[i]);
     79                }
     80 
     81                test_true(!document.hidden, "Page is visible on load.");
     82                test_true((!child_doc_shown.hidden) && (!child_doc_hidden.hidden),
     83                          "All IFrame child documents are visible on load.");
     84 
     85                document.addEventListener("visibilitychange", notification_handlers[0]);
     86                document.addEventListener("visibilitychange", VerifyTwoNotifications);
     87 
     88                manual_test = AddManual("Browser minimization has occurred.");
     89            }
     90 
     91            function VerifyNotification(doc_index)
     92            {
     93                doc = page_docs[doc_index][0];
     94                docName = page_docs[doc_index][1];
     95 
     96                notification_count[doc_index]++;
     97                switch (notification_count[doc_index])
     98                {
     99                    case 1:
    100                        // First step, check page visibility after tab deselection / minimization.
    101                        // hidden should change to true; visibilityState should change to "hidden"
    102                        test_true(doc.hidden, docName + ".hidden == true (after browser frame minimization)");
    103                        test_true(doc.visibilityState == PAGE_HIDDEN_VAL,
    104                                  docName + ".visibilityState == \"hidden\" (after browser frame minimization)");
    105 
    106                        break;
    107 
    108                    case 2:
    109                        //Second step, check page visibility after tab reselection / maximization / restoration.
    110                        // hidden should change to false; visibilityState should change to "visible"
    111                        test_true(!doc.hidden,
    112                                  docName + ".hidden == false (after browser frame maximization / restoration)");
    113                        test_true(doc.visibilityState == PAGE_VISIBLE_VAL,
    114                                  docName + ".visibilityState == \"visible\" (after browser frame maximization / " +
    115                                  "restoration)");
    116 
    117                        // perform tests specific to the main document
    118                        if (doc == document)
    119                        {
    120                            //Verify that a second registration to a different callback also occurred
    121                            test_true(two_notifications, "Two registrations (different callbacks) occurred.");
    122 
    123                            //Verify that a second registration to the same callback did not occur
    124                            test_equals(notification_count[doc_index],
    125                                        expected_notification_count,
    126                                        "Two registrations (same callback) did not occur.");
    127 
    128                            // pass the manual item associated with these tests
    129                            AddManualResult(manual_test, true);
    130 
    131                            document.removeEventListener("visibilitychange", VerifyTwoNotifications);
    132 
    133                            // schedule the rollup
    134                            setTimeout(VerifyAllNotifications, 200);
    135                        }
    136 
    137                        //Remove all event listeners and verify that the event does not fire
    138                        doc.removeEventListener("visibilitychange", notification_handlers[doc_index]);
    139                        break;
    140                    case 3:
    141                        //This step should not have occurred since the event handlers were cleared
    142                        test_true(false, "Event did not fire when event listener is removed.");
    143 
    144                        //On final step, schedule the rollup
    145                        setTimeout(done, 2000);
    146                        break;
    147 
    148                    default:
    149                        break;
    150                }
    151            }
    152 
    153            function VerifyAllNotifications()
    154            {
    155                //On final step, schedule the rollup
    156                setTimeout(done, 1000);
    157            }
    158 
    159            function VerifyTwoNotifications()
    160            {
    161                //This is a duplicate registration on visibilitychange and
    162                //should never get fired.  Check that duplicate_notification
    163                //is false to verify that this never occurred.
    164                two_notifications = true;
    165            }
    166 
    167            // Manual Test helper functions
    168            function AddManual(test)
    169            {
    170                // add asynchronous test for manual tests
    171                return async_test(test);
    172            }
    173 
    174            function AddManualResult(oManualTest, passState)
    175            {
    176                // add assertion to manual test for the pass state
    177                oManualTest.step(function() {assert_true(passState)});
    178 
    179                // end manual test
    180                oManualTest.done();
    181            }
    182 
    183            function start_test()
    184            {
    185                test_transition_init();
    186            }
    187        </script>
    188    </body>
    189 </html>