Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1150755 - merge pull request #29840 from jonallengriffin:removeSp…
Browse files Browse the repository at this point in the history
…ecialPowers to mozilla-b2g:master
  • Loading branch information
mozilla-autolander-deprecated committed May 12, 2015
2 parents e84aa64 + bd99d75 commit 0a9f9b4
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 108 deletions.
10 changes: 5 additions & 5 deletions tests/atoms/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';
/* globals SpecialPowers, marionetteScriptFinished */

/* globals Components, marionetteScriptFinished */
/* exported Accessibility */

var Accessibility = {

_accRetrieval: SpecialPowers.Cc[
_accRetrieval: Components.classes[
'@mozilla.org/accessibleRetrieval;1'].getService(
SpecialPowers.Ci.nsIAccessibleRetrieval),
Components.interfaces.nsIAccessibleRetrieval),

_getAccessible:
function Accessibility__getAccessible(element, callback, once) {
Expand All @@ -35,8 +36,7 @@ var Accessibility = {
},

_matchState: function Accessibility__matchState(acc, stateName) {
let stateToMatch = SpecialPowers.wrap(
SpecialPowers.Components).interfaces.nsIAccessibleStates[stateName];
let stateToMatch = Components.interfaces.nsIAccessibleStates[stateName];
let state = {};
let extState = {};
acc.getState(state, extState);
Expand Down
53 changes: 9 additions & 44 deletions tests/atoms/gaia_data_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'use strict';
/* global marionetteScriptFinished, pair, device:true, mozContact, i */
/* global waitFor, SpecialPowers, adapter:true, aContacts */
/* global waitFor, adapter:true, aContacts */
/* exported pair, discovery, GaiaDataLayer */
/* jshint -W083 */

Expand Down Expand Up @@ -86,22 +86,20 @@ var GaiaDataLayer = {
},

insertContact: function(aContact) {
// requires the 'contacts-create' permission
if (aContact.photo) {
var blob = GaiaDataLayer.base64ToBlob(aContact.photo, 'image/jpg');
aContact.photo = [blob];
}

SpecialPowers.addPermission('contacts-create', true, document);
var contact = new mozContact(aContact);
var req = window.navigator.mozContacts.save(contact);
req.onsuccess = function() {
console.log('success saving contact');
SpecialPowers.removePermission('contacts-create', document);
marionetteScriptFinished(true);
};
req.onerror = function() {
console.error('error saving contact', req.error.name);
SpecialPowers.removePermission('contacts-create', document);
marionetteScriptFinished(false);
};
},
Expand Down Expand Up @@ -146,17 +144,15 @@ var GaiaDataLayer = {


getAllContacts: function(aCallback) {
// requires 'contacts-read' permission
var callback = aCallback || marionetteScriptFinished;
SpecialPowers.addPermission('contacts-read', true, document);
var req = window.navigator.mozContacts.find({});
req.onsuccess = function() {
console.log('success finding contacts');
SpecialPowers.removePermission('contacts-read', document);
callback(req.result);
};
req.onerror = function() {
console.error('error finding contacts ' + req.error.name);
SpecialPowers.removePermission('contacts-read', document);
callback([]);
};
},
Expand All @@ -175,12 +171,10 @@ var GaiaDataLayer = {
var req = icc.readContacts(type);
req.onsuccess = function() {
console.log('success finding ' + type + ' contacts');
SpecialPowers.removePermission('contacts-read', document);
callback(req.result);
};
req.onerror = function() {
console.error('error finding ' + type + ' contacts ' + req.error.name);
SpecialPowers.removePermission('contacts-read', document);
callback([]);
};
},
Expand All @@ -207,27 +201,24 @@ var GaiaDataLayer = {
},

removeContact: function(aContact, aCallback) {
// requires the 'contacts-write' persmission
var callback = aCallback || marionetteScriptFinished;
SpecialPowers.addPermission('contacts-write', true, document);
console.log('removing contact with id \'' + aContact.id + '\'');
var req = window.navigator.mozContacts.remove(aContact);
req.onsuccess = function() {
console.log('success removing contact with id \'' + aContact.id + '\'');
SpecialPowers.removePermission('contacts-write', document);
callback(true);
};
req.onerror = function() {
console.error('error removing contact with id \'' +
aContacts[i].id + '\'');
SpecialPowers.removePermission('contacts-write', document);
callback(false);
};
},

getSetting: function(aName, aCallback) {
// requires the 'settings-read' and 'settings-api-read' permissions
var callback = aCallback || marionetteScriptFinished;
SpecialPowers.addPermission('settings-read', true, document);
SpecialPowers.addPermission('settings-api-read', true, document);
var req = window.navigator.mozSettings.createLock().get(aName);
req.onsuccess = function() {
console.log('setting retrieved');
Expand All @@ -240,8 +231,7 @@ var GaiaDataLayer = {
},

setSetting: function(aName, aValue, aReturnOnSuccess) {
SpecialPowers.addPermission('settings-write', true, document);
SpecialPowers.addPermission('settings-api-write', true, document);
// requires the 'settings-write' and 'settings-api-write' permissions
var returnOnSuccess = aReturnOnSuccess || aReturnOnSuccess === undefined;
var setting = {};
setting[aName] = aValue;
Expand Down Expand Up @@ -506,19 +496,15 @@ var GaiaDataLayer = {
},

sendSMS: function(recipient, content, aCallback) {
// requires the 'sms' permission and the 'dom.sms.enabled' pref
var callback = aCallback || marionetteScriptFinished;
console.log('sending sms message to number: ' + recipient);

SpecialPowers.addPermission('sms', true, document);
SpecialPowers.setBoolPref('dom.sms.enabled', true);

let messageManager = window.navigator.mozMobileMessage;
let request = messageManager.send(recipient, content);

request.onsuccess = function(event) {
var sms = event.target.result;
SpecialPowers.removePermission('sms', document);
SpecialPowers.clearUserPref('dom.sms.enabled');

waitFor(
function() { callback(true); },
Expand All @@ -531,18 +517,15 @@ var GaiaDataLayer = {

request.onerror = function() {
console.log('sms message not sent');
SpecialPowers.removePermission('sms', document);
SpecialPowers.clearUserPref('dom.sms.enabled');
callback(false);
};
},

getAllSms: function(aCallback) {
// requires the 'sms' permission and the 'dom.sms.enabled' pref
var callback = aCallback || marionetteScriptFinished;
console.log('searching for sms messages');

SpecialPowers.addPermission('sms', true, document);
SpecialPowers.setBoolPref('dom.sms.enabled', true);
let sms = window.navigator.mozMobileMessage;

let msgList = [];
Expand All @@ -555,30 +538,22 @@ var GaiaDataLayer = {
// Now get the next in the list
cursor.continue();
}else{
disableSms();
// Send back the list
callback(msgList);
}
};

cursor.onerror = function(event) {
console.log('sms.getMessages error: ' + event.target.error.name);
disableSms();
callback(false);
};

function disableSms() {
SpecialPowers.removePermission('sms', document);
SpecialPowers.clearUserPref('dom.sms.enabled');
}
},

deleteAllSms: function(aCallback) {
// requires the 'sms' permission and the 'dom.sms.enabled' pref
var callback = aCallback || marionetteScriptFinished;
console.log('searching for sms messages');

SpecialPowers.addPermission('sms', true, document);
SpecialPowers.setBoolPref('dom.sms.enabled', true);
let sms = window.navigator.mozMobileMessage;

let msgList = [];
Expand All @@ -597,15 +572,13 @@ var GaiaDataLayer = {
deleteSmsMsgs(msgList);
} else {
console.log('zero sms messages found');
disableSms();
callback(true);
}
}
};

cursor.onerror = function(event) {
console.log('sms.getMessages error: ' + event.target.error.name);
disableSms();
callback(false);
};

Expand All @@ -622,28 +595,20 @@ var GaiaDataLayer = {
} else {
// All messages deleted
console.log('finished deleting all sms messages');
disableSms();
callback(true);
}
} else {
console.log('sms delete failed');
disableSms();
callback(false);
}
};

request.onerror = function(event) {
console.log('sms.delete request returned unexpected error: ' +
event.target.error.name);
disableSms();
callback(false);
};
}

function disableSms() {
SpecialPowers.removePermission('sms', document);
SpecialPowers.clearUserPref('dom.sms.enabled');
}
},

bluetoothSetDeviceName: function(device_name, aCallback) {
Expand Down
4 changes: 2 additions & 2 deletions tests/python/gaia-ui-tests/gaiatest/apps/calendar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def a11y_click_other_day(self, next, previous):
return previous

def a11y_click_header(self, header, selector):
self.marionette.execute_async_script(
self.accessibility.execute_async_script(
"Accessibility.click(arguments[0].shadowRoot.querySelector('%s'));" % selector,
[header], special_powers=True)
[header])

def wait_fot_settings_drawer_animation(self):
el = self.marionette.find_element(*self.settings._settings_drawer_locator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def fill_event_location(self, location):
self.keyboard.dismiss()

def a11y_click_close_button(self):
self.marionette.execute_async_script(
self.accessibility.execute_async_script(
"Accessibility.click(arguments[0].shadowRoot.querySelector('button.action-button'));",
[self.marionette.find_element(*self._modify_event_header_locator)], special_powers=True)
[self.marionette.find_element(*self._modify_event_header_locator)])

def a11y_click_save_event(self):
event_start_time = self.marionette.find_element(*self._event_start_time_value_locator).text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, marionette):
self.marionette.switch_to_frame(select_contacts)

def tap_import_button(self, wait_for_import = True):
self.marionette.execute_script('window.wrappedJSObject.importer.ui.importAll();', special_powers=True)
self.marionette.execute_script('window.wrappedJSObject.importer.ui.importAll();')
# TODO uncomment this when Bug 932804 is resolved
# self.marionette.find_element(*self._import_button_locator).tap()
self.apps.switch_to_displayed_app()
Expand All @@ -35,12 +35,12 @@ def tap_first_friend(self):
self.marionette.execute_script("""
window.wrappedJSObject.document.getElementById("friends-list")
.getElementsByTagName("a")[1].click()
""", special_powers=True)
""")
self.wait_for_element_not_displayed(*self._friends_list_locator)
self.apps.switch_to_displayed_app()

def tap_select_all(self):
# TODO replace this with proper tap when Bug 932804 is resolved
self.marionette.execute_script('window.wrappedJSObject.importer.ui.selectAll();', special_powers=True)
self.marionette.execute_script('window.wrappedJSObject.importer.ui.selectAll();')
el = self.marionette.find_element(*self._import_button_locator)
Wait(self.marionette).until(expected.element_enabled(el))
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ def check_for_emails_interval(self, value):
# rather than the default value of 100 seconds
# The UI data layer of the UI is changed, because the minimum check mail time value is 5 min,
# which is far too long to check for in a test. This allows us to check earlier
with self.marionette.using_context('chrome'):
self.marionette.execute_script(
"Services.prefs.setIntPref('dom.requestSync.minInterval', 1);")
self.marionette.execute_script("""
SpecialPowers.setIntPref('dom.requestSync.minInterval', 1);
document.querySelector("[data-l10n-id = settings-check-every-5min]").value = '%s';
""" % value, special_powers=True)
""" % value)
self.marionette.find_element(*self._check_for_new_messages_locator).tap()
self.select('Every 5 minutes')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ def invoke_controls(self):
def show_controls(self):
Wait(self.marionette).until(lambda m: not self.controls_visible)
self.marionette.execute_script("""
var a = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(SpecialPowers.Ci.inIDOMUtils)
var a = Components.classes["@mozilla.org/inspector/dom-utils;1"]
.getService(Components.interfaces.inIDOMUtils)
.getChildrenForNode(document.getElementsByTagName('video')[0], true);
var x = a[1].ownerDocument.getAnonymousElementByAttribute(a[1],'class', 'controlBar');
x.removeAttribute('hidden');
""")
""", sandbox='system')
Wait(self.marionette).until(lambda m: self.controls_visible)

def get_location(self, class_name):
return self.marionette.execute_script("""
var a = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(SpecialPowers.Ci.inIDOMUtils)
var a = Components.classes["@mozilla.org/inspector/dom-utils;1"]
.getService(Components.interfaces.inIDOMUtils)
.getChildrenForNode(document.getElementsByTagName('video')[0], true);
var x1 = document.getElementsByTagName('video')[0].getBoundingClientRect().left;
var x2 = a[1].ownerDocument
Expand All @@ -82,7 +82,7 @@ def get_location(self, class_name):
var y2 = a[1].ownerDocument.getAnonymousElementByAttribute(a[1],'class', '%s')
.getBoundingClientRect().top;
return (Math.floor(x2-x1) + ',' + Math.floor(y2-y1));
""" % (class_name, class_name)).split(',')
""" % (class_name, class_name), sandbox='system').split(',')

def tap_video_control(self, class_name):
location = self.get_location(class_name)
Expand Down
Loading

0 comments on commit 0a9f9b4

Please sign in to comment.