Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Migration tests</title> |
michael@0 | 5 | <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <h1>migration tests</h1> |
michael@0 | 11 | <p id="display"></p> |
michael@0 | 12 | <div id="content" style="display: none"> |
michael@0 | 13 | |
michael@0 | 14 | </div> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script type="text/javascript;version=1.8" src="shared.js"></script> |
michael@0 | 17 | <script class="testbody" type="text/javascript"> |
michael@0 | 18 | "use strict"; |
michael@0 | 19 | |
michael@0 | 20 | var backend, contactsCount, allContacts; |
michael@0 | 21 | function loadChromeScript() { |
michael@0 | 22 | var url = SimpleTest.getTestFileURL("test_migration_chrome.js"); |
michael@0 | 23 | backend = SpecialPowers.loadChromeScript(url); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function addBackendEvents() { |
michael@0 | 27 | backend.addMessageListener("createDB.success", function(count) { |
michael@0 | 28 | contactsCount = count; |
michael@0 | 29 | ok(true, "Created the database"); |
michael@0 | 30 | next(); |
michael@0 | 31 | }); |
michael@0 | 32 | backend.addMessageListener("createDB.error", function(err) { |
michael@0 | 33 | ok(false, err); |
michael@0 | 34 | next(); |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | backend.addMessageListener("deleteDB.success", function() { |
michael@0 | 38 | ok(true, "Deleted the database"); |
michael@0 | 39 | next(); |
michael@0 | 40 | }); |
michael@0 | 41 | backend.addMessageListener("deleteDB.error", function(err) { |
michael@0 | 42 | ok(false, err); |
michael@0 | 43 | next(); |
michael@0 | 44 | }); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function createDB(version) { |
michael@0 | 48 | info("Will create the DB at version " + version); |
michael@0 | 49 | backend.sendAsyncMessage("createDB", version); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function deleteDB() { |
michael@0 | 53 | info("Will delete the DB."); |
michael@0 | 54 | backend.sendAsyncMessage("deleteDB"); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function setSubstringMatching(value) { |
michael@0 | 58 | info("Setting substring matching to " + value); |
michael@0 | 59 | |
michael@0 | 60 | if (value) { |
michael@0 | 61 | SpecialPowers.setIntPref("dom.phonenumber.substringmatching.BR", value); |
michael@0 | 62 | |
michael@0 | 63 | // this is the Mcc for Brazil, so that we trigger the previous pref |
michael@0 | 64 | SpecialPowers.setCharPref("ril.lastKnownSimMcc", "724"); |
michael@0 | 65 | } else { |
michael@0 | 66 | SpecialPowers.clearUserPref("dom.phonenumber.substringmatching.BR"); |
michael@0 | 67 | SpecialPowers.clearUserPref("ril.lastKnownSimMcc"); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | next(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | var steps = [ |
michael@0 | 74 | function setupChromeScript() { |
michael@0 | 75 | loadChromeScript(); |
michael@0 | 76 | addBackendEvents(); |
michael@0 | 77 | next(); |
michael@0 | 78 | }, |
michael@0 | 79 | |
michael@0 | 80 | deleteDB, // let's be sure the DB does not exist yet |
michael@0 | 81 | createDB.bind(null, 12), |
michael@0 | 82 | setSubstringMatching.bind(null, 7), |
michael@0 | 83 | |
michael@0 | 84 | function testAccessMozContacts() { |
michael@0 | 85 | info("Checking we have the right number of contacts: " + contactsCount); |
michael@0 | 86 | var req = mozContacts.getCount(); |
michael@0 | 87 | req.onsuccess = function onsuccess() { |
michael@0 | 88 | ok(true, "Could access the mozContacts API"); |
michael@0 | 89 | ise(this.result, contactsCount, "Contacts count is correct"); |
michael@0 | 90 | next(); |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | req.onerror = function onerror() { |
michael@0 | 94 | ok(false, "Couldn't access the mozContacts API"); |
michael@0 | 95 | next(); |
michael@0 | 96 | }; |
michael@0 | 97 | }, |
michael@0 | 98 | |
michael@0 | 99 | function testRetrieveAllContacts() { |
michael@0 | 100 | /* if the migration does not work right, either we'll have an error, or the |
michael@0 | 101 | contacts won't be migrated properly and thus will fail WebIDL conversion, |
michael@0 | 102 | which will manifest as a timeout */ |
michael@0 | 103 | info("Checking the contacts are corrected to obey WebIDL constraints. (upgrades 14 to 17)"); |
michael@0 | 104 | var req = mozContacts.find(); |
michael@0 | 105 | req.onsuccess = function onsuccess() { |
michael@0 | 106 | if (this.result) { |
michael@0 | 107 | ise(this.result.length, contactsCount, "Contacts array length is correct"); |
michael@0 | 108 | allContacts = this.result; |
michael@0 | 109 | next(); |
michael@0 | 110 | } else { |
michael@0 | 111 | ok(false, "Could access the mozContacts API but got no contacts!"); |
michael@0 | 112 | next(); |
michael@0 | 113 | } |
michael@0 | 114 | }; |
michael@0 | 115 | |
michael@0 | 116 | req.onerror = function onerror() { |
michael@0 | 117 | ok(false, "Couldn't access the mozContacts API"); |
michael@0 | 118 | next(); |
michael@0 | 119 | }; |
michael@0 | 120 | }, |
michael@0 | 121 | |
michael@0 | 122 | function checkNameIndex() { |
michael@0 | 123 | info("Checking name index migration (upgrades 17 to 19)."); |
michael@0 | 124 | if (!allContacts) { |
michael@0 | 125 | next(); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | var count = allContacts.length; |
michael@0 | 129 | |
michael@0 | 130 | function finishRequest() { |
michael@0 | 131 | count--; |
michael@0 | 132 | if (!count) { |
michael@0 | 133 | next(); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | allContacts.forEach(function(contact) { |
michael@0 | 138 | var name = contact.name && contact.name[0]; |
michael@0 | 139 | if (!name) { |
michael@0 | 140 | count--; |
michael@0 | 141 | return; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | var req = mozContacts.find({ |
michael@0 | 145 | filterBy: ["name"], |
michael@0 | 146 | filterValue: name, |
michael@0 | 147 | filterOp: "equals" |
michael@0 | 148 | }); |
michael@0 | 149 | |
michael@0 | 150 | req.onsuccess = function onsuccess() { |
michael@0 | 151 | if (this.result) { |
michael@0 | 152 | info("Found contact '" + name + "', checking it's the correct one."); |
michael@0 | 153 | checkContacts(this.result[0], contact); |
michael@0 | 154 | } else { |
michael@0 | 155 | ok(false, "Could not find contact with name '" + name + "'"); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | finishRequest(); |
michael@0 | 159 | }; |
michael@0 | 160 | |
michael@0 | 161 | req.onerror = function onerror() { |
michael@0 | 162 | ok(false, "Error while finding contact with name '" + name + "'!"); |
michael@0 | 163 | finishRequest(); |
michael@0 | 164 | } |
michael@0 | 165 | }); |
michael@0 | 166 | |
michael@0 | 167 | if (!count) { |
michael@0 | 168 | ok(false, "No contact had a name, this is unexpected."); |
michael@0 | 169 | next(); |
michael@0 | 170 | } |
michael@0 | 171 | }, |
michael@0 | 172 | |
michael@0 | 173 | function checkSubstringMatching() { |
michael@0 | 174 | var subject = "0004567890"; // the last 7 digits are the same that at least one contact |
michael@0 | 175 | info("Looking for a contact matching " + subject); |
michael@0 | 176 | var req = mozContacts.find({ |
michael@0 | 177 | filterValue: subject, |
michael@0 | 178 | filterOp: "match", |
michael@0 | 179 | filterBy: ["tel"], |
michael@0 | 180 | filterLimit: 1 |
michael@0 | 181 | }); |
michael@0 | 182 | |
michael@0 | 183 | req.onsuccess = function onsuccess() { |
michael@0 | 184 | if (this.result && this.result[0]) { |
michael@0 | 185 | ok(true, "Found a contact with number " + this.result[0].tel[0].value); |
michael@0 | 186 | } |
michael@0 | 187 | next(); |
michael@0 | 188 | }; |
michael@0 | 189 | |
michael@0 | 190 | req.onerror = function onerror() { |
michael@0 | 191 | ok(false, "Error while finding contact for substring matching check!"); |
michael@0 | 192 | next(); |
michael@0 | 193 | }; |
michael@0 | 194 | }, |
michael@0 | 195 | |
michael@0 | 196 | deleteDB, |
michael@0 | 197 | setSubstringMatching.bind(null, null), |
michael@0 | 198 | |
michael@0 | 199 | function finish() { |
michael@0 | 200 | backend.destroy(); |
michael@0 | 201 | info("all done!\n"); |
michael@0 | 202 | SimpleTest.finish(); |
michael@0 | 203 | } |
michael@0 | 204 | ]; |
michael@0 | 205 | |
michael@0 | 206 | start_tests(); |
michael@0 | 207 | </script> |
michael@0 | 208 | </pre> |
michael@0 | 209 | </body> |
michael@0 | 210 | </html> |