dom/apps/tests/test_receipt_operations.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE html>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id={757226}
     5 -->
     6 <head>
     7   <title>Test for Bug {757226} Implement mozApps app.replaceReceipt</title>
     8   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     9   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    12 <body>
    14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={757226}">Mozilla Bug {757226}</a>
    15 <p id="display"></p>
    16 <div id="content" style="display: none">
    18 </div>
    19 <pre id="test">
    20 <script class="testbody" type="application/javascript;version=1.7">
    22 var gManifestURL = "http://test/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true";
    23 var gGenerator = runTest();
    25 function debug(aMsg) {
    26   //dump("== Tests debug == " + aMsg + "\n");
    27 }
    29 function go() {
    30   SpecialPowers.pushPermissions(
    31     [{ "type": "webapps-manage", "allow": 1, "context": document }],
    32     function() { gGenerator.next() });
    33 }
    35 function continueTest() {
    36   try {
    37     gGenerator.next();
    38   } catch (e if e instanceof StopIteration) {
    39     finish();
    40   }
    41 }
    43 function finish() {
    44   SimpleTest.finish();
    45 }
    47 function cbError(aError) {
    48   ok(false, "Error callback invoked " + aError);
    49   finish();
    50 }
    52 SimpleTest.waitForExplicitFinish();
    54 function runTest() {
    55   SpecialPowers.setAllAppsLaunchable(true);
    57   SpecialPowers.autoConfirmAppInstall(continueTest);
    58   yield undefined;
    60   var request = navigator.mozApps.install(gManifestURL);
    61   request.onerror = cbError;
    62   request.onsuccess = continueTest;
    63   yield undefined;
    65   var app = request.result;
    66   ok(app, "App is non-null");
    67   ok(app.receipts.length == 0, "No receipts");
    69   let receipt1 = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJwcm9kdWN0IjogeyJ1cmwiOiAiaHR0cHM6Ly93d3cubW96aWxsYS5vcmciLCAic3RvcmVkYXRhIjogIjUxNjkzMTQzNTYifSwgInJlaXNzdWUiOiAiaHR0cDovL21vY2hpLnRlc3Q6ODg4OC9yZWlzc3VlLzUxNjkzMTQzNTYiLCAidXNlciI6IHsidHlwZSI6ICJkaXJlY3RlZC1pZGVudGlmaWVyIiwgInZhbHVlIjogIjRmYjM1MTUxLTJiOWItNGJhMi04MjgzLWM0OWQzODE2NDBiZCJ9LCAidmVyaWZ5IjogImh0dHA6Ly9tb2NoaS50ZXN0Ojg4ODgvdmVyaWZ5LzUxNjkzMTQzNTYiLCAiaXNzIjogImh0dHA6Ly9tb2NoaS50ZXN0Ojg4ODgiLCAiaWF0IjogMTMxMzYwMTg4LCAidHlwIjogInB1cmNoYXNlLXJlY2VpcHQiLCAibmJmIjogMTMxMzYwMTg1LCAiZGV0YWlsIjogImh0dHA6Ly9tb2NoaS50ZXN0Ojg4ODgvcmVjZWlwdC81MTY5MzE0MzU2In0.eZpTEnCLUR3iP3rm9WyJOqx1k66mQaAxqcrvX11r5E0';
    71   let receipt2 = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJwcm9kdWN0IjogeyJ1cmwiOiAiaHR0cHM6Ly93d3cubW96aWxsYS5vcmciLCAic3RvcmVkYXRhIjogIjUxNjkzMTQzNTcifSwgInJlaXNzdWUiOiAiaHR0cDovL21vY2hpLnRlc3Q6ODg4OC9yZWlzc3VlLzUxNjkzMTQzNTYiLCAidXNlciI6IHsidHlwZSI6ICJkaXJlY3RlZC1pZGVudGlmaWVyIiwgInZhbHVlIjogIjRmYjM1MTUxLTJiOWItNGJh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cHM6Ly9tYXJrZXRwbGFjZS5maXJlZm94LmNvbS9hcGkvdjEvcmVjZWlwdHMvcmVpc3N1ZS8iLCAicmVpc3N1ZSI6ICJodHRwczovL21hcmtldHBsYWNlLmZpcmVmb3guY29tL2FwaS92MS9yZWNlaXB0cy9yZWlzc3VlLyIsICJ1c2VyIjogeyJ0eXBlIjogImRpcmVjdGVkLWlkZW50aWZpZXIiLCAidmFsdWUiOiAiMTkzMzI2LTVjMTUzNmQ1LWUxMDQtNDAzYy04NDBlLTQ5YjMyMmQ5Yjg4NSJ9LCAiZXhwIjogMTQwMTgyNTEyOCwgImlhdCI6IDEzODYxMDAzMjgsICJ0eXAiOiAicHVyY2hhc2UtcmVjZWlwdCIsICJuYmYiOiAxMzg2MTAwMzI4fQ.r2DVUpouRDJYqZe61LJBcIwmeF2mI8FmbGMRlfNFcinKAIs8nMVVNX8xSWJ6jXXgZ62VfHJCLHapADX8rCg6NgxFV_FdP7j2H_2Ufo0E0TREifTN6V4v1dCnzDulNhZmO8G-nQJUVOAtNfNC95PY7tVa8WC7dYXnKZsD6NhIxxVEtBGuiiySpWArI-g3pcl41rXNHHpJbRfrOD4QgVNrsV83TWILYRr6PWr3aqOM2XT_x2SzEfhBNvdG8AJmR0MKQytvfcgz3Vt1hMak88nFrzTLiKkuuPAXpwB5q83LZIl4EYG3UAnte4-XWlLb-NJ78vgXa64myy-3fPr7EO6LaQ';
    75   // Test removeReceipt or replaceReceipt when there the app doesn't have any receipt
    76   request = app.replaceReceipt(receipt1, receipt3);
    77   request.onsuccess = function() {
    78     ok(false, "replaceReceipt should fail if the app doesn't have any receipt");
    79   }
    80   request.onerror = function() {
    81     ok(this.error.name == "NO_SUCH_RECEIPT",
    82        "Request failed because there isn't any receipt");
    83     continueTest();
    84   }
    85   yield undefined;
    87   request = app.removeReceipt(receipt1);
    88   request.onsuccess = function() {
    89     ok(false, "removeReceipt should fail if the app doesn't have any receipt");
    90   }
    91   request.onerror = function() {
    92     ok(this.error.name == "NO_SUCH_RECEIPT",
    93        "Request failed because there isn't any receipt");
    94     continueTest();
    95   }
    96   yield undefined;
    98   // Test addReceipt
    99   request = app.addReceipt(null);
   100   request.onsuccess = function() {
   101     ok(false, "Call with missing parameter should've failed");
   102   }
   103   request.onerror = function() {
   104     ok(this.error.name == "INVALID_PARAMETERS",
   105        "Request failed because of a missing parameter");
   106     continueTest();
   107   }
   108   yield undefined;
   110   request = app.addReceipt(receipt1);
   111   request.onerror = cbError;
   112   request.onsuccess = function() {
   113     ok(app.receipts.length == 1, "One receipt");
   114     ok(app.receipts[0] == receipt1, "Receipt correctly added");
   115     continueTest();
   116   };
   117   yield undefined;
   119   request = app.addReceipt(receipt1);
   120   request.onerror = function() {
   121     ok(this.error.name == "RECEIPT_ALREADY_EXISTS",
   122         "Request failed because the receipt already exists");
   123     continueTest();
   124   };
   125   request.onsuccess = function() {
   126     ok(false, "addReceipt should fail if the receipt already exists");
   127   };
   128   yield undefined;
   130   request = app.addReceipt(receipt2);
   131   request.onerror = cbError;
   132   request.onsuccess = function() {
   133     ok(app.receipts.length == 2, "Two receipts");
   134     ok(app.receipts[0] == receipt1, "First receipt is still there");
   135     ok(app.receipts[1] == receipt2, "Second receipt correctly added");
   136     continueTest();
   137   }
   138   yield undefined;
   140   // Test replace receipts
   141   request = app.replaceReceipt(null, null);
   142   request.onsuccess = function() {
   143     ok(false, "Call with missing parameters should've failed");
   144   }
   145   request.onerror = function() {
   146     ok(this.error.name == "INVALID_PARAMETERS",
   147        "Request failed because of missing parameters");
   148     continueTest();
   149   }
   150   yield undefined;
   152   request = app.replaceReceipt(null, receipt1);
   153   request.onsuccess = function() {
   154     ok(false, "Call with missing parameter should've failed");
   155   }
   156   request.onerror = function() {
   157     ok(this.error.name == "INVALID_PARAMETERS",
   158        "Request failed because of a missing parameter");
   159     continueTest();
   160   }
   161   yield undefined;
   163   request = app.replaceReceipt(receipt1, null);
   164   request.onsuccess = function() {
   165     ok(false, "Call with missing parameter should've failed");
   166   }
   167   request.onerror = function() {
   168     ok(this.error.name == "INVALID_PARAMETERS",
   169        "Request failed because of a missing parameter");
   170     continueTest();
   171   }
   172   yield undefined;
   174   request = app.replaceReceipt(receipt3, receipt1);
   175   request.onsuccess = function() {
   176     ok(false, "Call with non-existent receipt should've failed");
   177   }
   178   request.onerror = function() {
   179     ok(this.error.name == "NO_SUCH_RECEIPT",
   180        "Exception thrown because of a non-existent receipt");
   181     ok(app.receipts.length == 2, "Two receipts");
   182     ok(app.receipts[0] == receipt1 && app.receipts[1] == receipt2,
   183        "No receipt was replaced");
   184     continueTest();
   185   }
   186   yield undefined;
   188   request = app.replaceReceipt(receipt1, receipt3);
   189   request.onerror = cbError;
   190   request.onsuccess = function() {
   191     ok(app.receipts.length == 2, "Two receipts");
   192     ok(app.receipts[0] == receipt3, "First receipt was replaced");
   193     ok(app.receipts[1] == receipt2, "Second receipt wasn't replaced");
   194     continueTest();
   195   }
   196   yield undefined;
   198   // Test remove receipt
   199   request = app.removeReceipt(null);
   200   request.onsuccess = function() {
   201     ok(false, "Call with missing parameter should've failed");
   202   }
   203   request.onerror = function() {
   204     ok(this.error.name == "INVALID_PARAMETERS",
   205        "Request failed because of a missing parameter");
   206     continueTest();
   207   }
   208   yield undefined;
   210   request = app.removeReceipt(receipt1);
   211   request.onsuccess = function() {
   212     ok(false, "Call with non-existent receipt should've failed");
   213   }
   214   request.onerror = function() {
   215     ok(this.error.name == "NO_SUCH_RECEIPT",
   216        "Exception thrown because of a non-existent receipt");
   217     ok(app.receipts.length == 2, "Two receipts");
   218     ok(app.receipts[0] == receipt3 && app.receipts[1] == receipt2,
   219        "No receipt was removed");
   220     continueTest();
   221   }
   222   yield undefined;
   224   request = app.removeReceipt(receipt3);
   225   request.onerror = cbError;
   226   request.onsuccess = function() {
   227     ok(app.receipts.length == 1, "One receipt");
   228     ok(app.receipts[0] == receipt2, "The receipt is still alive");
   229     continueTest();
   230   }
   231   yield undefined;
   233   // Uninstall the app.
   234   request = navigator.mozApps.mgmt.uninstall(app);
   235   request.onerror = cbError;
   236   request.onsuccess = continueTest;
   237   yield undefined;
   238   ok(true, "App uninstalled");
   239 }
   241 addLoadEvent(go);
   243 </script>
   244 </pre>
   245 </body>
   246 </html>

mercurial