tests/auto/declarative/qdeclarativexmlhttprequest/data/open_username.qml
changeset 30 5dc02b23752f
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 import Qt 4.7
       
     2 
       
     3 QtObject {
       
     4     property string url
       
     5 
       
     6     property bool readyState: false
       
     7     property bool openedState: false
       
     8 
       
     9     property bool status: false
       
    10     property bool statusText: false
       
    11     property bool responseText: false
       
    12     property bool responseXML: false
       
    13 
       
    14     property bool dataOK: false
       
    15 
       
    16     Component.onCompleted: {
       
    17         var x = new XMLHttpRequest;
       
    18 
       
    19         if (x.readyState == XMLHttpRequest.UNSENT)
       
    20             readyState = true;
       
    21 
       
    22         x.open("GET", url, true, "sampleusername", "password");
       
    23 
       
    24         if (x.readyState  == XMLHttpRequest.OPENED)
       
    25             openedState = true;
       
    26 
       
    27         try {
       
    28             var a = x.status;
       
    29         } catch (error) {
       
    30             if (error.code == DOMException.INVALID_STATE_ERR)
       
    31                 status = true;
       
    32         }
       
    33         try {
       
    34             var a = x.statusText;
       
    35         } catch (error) {
       
    36             if (error.code == DOMException.INVALID_STATE_ERR)
       
    37                 statusText = true;
       
    38         }
       
    39         responseText = (x.responseText == "");
       
    40         responseXML = (x.responseXML == null);
       
    41 
       
    42         // Test to the end
       
    43         x.onreadystatechange = function() {
       
    44             if (x.readyState == XMLHttpRequest.DONE) {
       
    45                 dataOK = (x.responseText == "QML Rocks!\n");
       
    46             }
       
    47         }
       
    48 
       
    49 
       
    50         x.send()
       
    51     }
       
    52 }
       
    53 
       
    54