check_profile.js (1392B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 function check_profile_dir(profd) { 6 Assert.ok(profd.exists()); 7 Assert.ok(profd.isDirectory()); 8 let profd2 = Services.dirsvc.get("ProfD", Ci.nsIFile); 9 Assert.ok(profd2.exists()); 10 Assert.ok(profd2.isDirectory()); 11 // make sure we got the same thing back... 12 Assert.ok(profd.equals(profd2)); 13 } 14 15 function check_do_get_profile(fireProfileAfterChange) { 16 const observedTopics = new Map([ 17 ["profile-do-change", 0], 18 ["profile-after-change", 0], 19 ]); 20 const expectedTopics = new Map(observedTopics); 21 22 for (let [topic] of observedTopics) { 23 Services.obs.addObserver(() => { 24 let val = observedTopics.get(topic) + 1; 25 observedTopics.set(topic, val); 26 }, topic); 27 } 28 29 // Trigger profile creation. 30 let profd = do_get_profile(); 31 check_profile_dir(profd); 32 33 // Check the observed topics 34 expectedTopics.set("profile-do-change", 1); 35 if (fireProfileAfterChange) { 36 expectedTopics.set("profile-after-change", 1); 37 } 38 Assert.deepEqual(observedTopics, expectedTopics); 39 40 // A second do_get_profile() should not trigger more notifications. 41 profd = do_get_profile(); 42 check_profile_dir(profd); 43 Assert.deepEqual(observedTopics, expectedTopics); 44 }