Skip to content

Commit

Permalink
Merge remote-tracking branch 'mozilla/master' into delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Bebe authored and Bebe committed Jan 7, 2013
2 parents 2db6dea + e456809 commit 50ee8c9
Show file tree
Hide file tree
Showing 46 changed files with 636 additions and 279 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
debug/
dist/
gaiatest/debug/
*.pyc
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Introduction
============

Expand Down Expand Up @@ -85,14 +84,16 @@ Variables:
}
`

` WPA-EAP:
"wifi": {
"ssid": "MyNetwork",
"keyManagement": "WPA-EAP",
"password": "MyPassword",
"identity": "MyIdentity"
}
`
__Note__: Due to [Bug 775499](http://bugzil.la/775499), WiFi connections via WPA-EAP are not capable at this time.

Test data Prerequisites
=======================

Occasionally a test will need data on the hardware that cannot be set during the test setUp.
The following tests need data set up before they can be run successfully:

`test_ftu` Requires a single record/contact saved onto the SIM card to test the SIM contact import


Writing Tests
=============
Expand Down
20 changes: 10 additions & 10 deletions gaiatest/atoms/gaia_data_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ var GaiaDataLayer = {
var manager = window.navigator.mozMobileConnection;

if (!manager.data.connected) {
manager.ondatachange = function () {
if (manager.data.connected) {
waitFor(
function () {
console.log('cell data enabled');
manager.ondatachange = null;
marionetteScriptFinished(true);
}
};
},
function () { return manager.data.connected; }
);
this.setSetting('ril.data.enabled', true, false);
}
else {
Expand All @@ -237,13 +237,13 @@ var GaiaDataLayer = {
var manager = window.navigator.mozMobileConnection;

if (manager.data.connected) {
manager.ondatachange = function () {
if (!manager.data.connected) {
waitFor(
function () {
console.log('cell data disabled');
manager.ondatachange = null;
marionetteScriptFinished(true);
}
};
},
function () { return !manager.data.connected; }
);
this.setSetting('ril.data.enabled', false, false);
}
else {
Expand Down
30 changes: 26 additions & 4 deletions gaiatest/gaia_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import base64
import json
import os
import sys
import time

from marionette import MarionetteTestCase
Expand Down Expand Up @@ -65,6 +67,7 @@ def launch(self, name, switch_to_frame=True, url=None):
return app

def uninstall(self, name):
self.marionette.switch_to_frame()
self.marionette.execute_async_script("GaiaApps.uninstallWithName('%s')" % name)

def kill(self, app):
Expand Down Expand Up @@ -116,27 +119,31 @@ def insert_contact(self, contact):
def remove_contact(self, contact):
self.marionette.execute_script("GaiaDataLayer.findAndRemoveContact(%s)" % contact.json())

@property
def all_settings(self):
return self.marionette.execute_async_script('return GaiaDataLayer.getSetting("*")')

def get_setting(self, name):
self.marionette.switch_to_frame()
return self.marionette.execute_async_script('return GaiaDataLayer.getSetting("%s")' % name)

@property
def all_settings(self):
return self.get_setting('*')

def set_setting(self, name, value):
import json
value = json.dumps(value)
self.marionette.switch_to_frame()
result = self.marionette.execute_async_script('return GaiaDataLayer.setSetting("%s", %s)' % (name, value))
assert result, "Unable to change setting with name '%s' to '%s'" % (name, value)

def set_volume(self, value):
self.set_setting('audio.volume.master', value)

def enable_cell_data(self):
self.marionette.switch_to_frame()
result = self.marionette.execute_async_script("return GaiaDataLayer.enableCellData()")
assert result, 'Unable to enable cell data'

def disable_cell_data(self):
self.marionette.switch_to_frame()
result = self.marionette.execute_async_script("return GaiaDataLayer.disableCellData()")
assert result, 'Unable to disable cell data'

Expand All @@ -147,10 +154,12 @@ def disable_cell_roaming(self):
self.set_setting('ril.data.roaming_enabled', False)

def enable_wifi(self):
self.marionette.switch_to_frame()
result = self.marionette.execute_async_script("return GaiaDataLayer.enableWiFi()")
assert result, 'Unable to enable WiFi'

def disable_wifi(self):
self.marionette.switch_to_frame()
result = self.marionette.execute_async_script("return GaiaDataLayer.disableWiFi()")
assert result, 'Unable to disable WiFi'

Expand Down Expand Up @@ -303,6 +312,19 @@ def is_element_present(self, by, locator):
return False

def tearDown(self):
if any(sys.exc_info()):
# test has failed, gather debug
test_name = self.marionette.test_name.split()[-1]
debug_path = os.path.join('debug', *test_name.split('.'))
if not os.path.exists(debug_path):
os.makedirs(debug_path)

# screenshot
with open(os.path.join(debug_path, 'screenshot.png'), 'w') as f:
# TODO: Bug 818287 - Screenshots include data URL prefix
screenshot = self.marionette.screenshot()[22:]
f.write(base64.decodestring(screenshot))

self.lockscreen = None
self.apps = None
self.data_layer = None
Expand Down
2 changes: 0 additions & 2 deletions gaiatest/tests/clock/clock_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

_clock_day_date = ('id', 'clock-day-date')
_analog_clock_display = ('id', 'analog-clock-svg')
_analog_clock_body = ('id', 'analog-clock-svg-body')
_digital_clock_display = ('id', 'digital-clock-display')
_digital_clock_body = ('id', 'clock-time')
_digital_clock_hour24_state = ('id', 'clock-hour24-state')

_all_alarms = ('css selector', '#alarms li')
Expand Down
70 changes: 24 additions & 46 deletions gaiatest/tests/clock/test_clock_all_items_present_new_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,36 @@

from gaiatest import GaiaTestCase
from gaiatest.tests.clock import clock_object
import time


class TestClockTestAllItemsPresentNewAlarm(GaiaTestCase):

def setUp(self):
GaiaTestCase.setUp(self)

# unlock the lockscreen if it's locked
self.lockscreen.unlock()

# launch the Clock app
self.app = self.apps.launch('Clock')


def test_all_items_present_new_alarm(self):

def test_all_items_present_new_alarm(self):
# Wait for the new alarm screen to load
self.wait_for_element_displayed(*clock_object._alarm_create_new_locator)
self.marionette.find_element(*clock_object._alarm_create_new_locator).click()

# Ensure the picker is displayed
picker = self.marionette.find_element(*clock_object._picker_container)
self.assertTrue(picker.is_displayed(), 'Picker container not displayed.')

# Ensure label has the default placeholder and text
label = self.marionette.find_element(*clock_object._alarm_name)
self.assertEquals(label.get_attribute('placeholder'), 'Alarm')
self.assertEquals(label.text, '')

# Ensure repeat has the default value
repeat = self.marionette.find_element(*clock_object._repeat_menu)
self.assertEquals(repeat.text, 'Never')

# Ensure sound has the default value
sound = self.marionette.find_element(*clock_object._sound_menu)
self.assertEquals(sound.text, 'Classic Buzz')

picker_container_tagname = self.marionette.find_element(*clock_object._picker_container).tag_name
alarm_name_txt = self.marionette.find_element(*clock_object._alarm_name).text
repeat_selector_txt = self.marionette.find_element(*clock_object._repeat_menu).text
sound_selector_txt = self.marionette.find_element(*clock_object._sound_menu).text
snooze_selector_txt = self.marionette.find_element(*clock_object._snooze_menu).text

# Ensure that the picker container exists and is displayed
self.assertEquals(picker_container_tagname, 'div',
'Container was %s' % picker_container_tagname)
self.assertTrue(self.marionette.find_element(*clock_object._picker_container)
.is_displayed(), 'Picker container not displayed.')

# Ensure the alarm name input has the default text Alarm
self.assertEquals(alarm_name_txt, 'Alarm',
'Alarm name was %s' % alarm_name_txt)

# If either Never is not the text or it does not exist the below will fail
self.assertEquals(repeat_selector_txt, 'Never',
'Actual repeat selector text: %s' % repeat_selector_txt)

# If either Classic is not the text or it does not exist the below will fail
self.assertEquals(sound_selector_txt, 'Classic',
'Actual sound selector text: %s' % sound_selector_txt)

# If either 5 minutes is not the text or it does not exist the below will fail
self.assertEquals(snooze_selector_txt, '5 minutes',
'Actual snooze selector text: %s' % snooze_selector_txt)


def tearDown(self):

# close the app
if hasattr(self, 'app'):
self.apps.kill(self.app)

GaiaTestCase.tearDown(self)
# Ensure snooze has the default value
snooze = self.marionette.find_element(*clock_object._snooze_menu)
self.assertEquals(snooze.text, '5 minutes')
5 changes: 0 additions & 5 deletions gaiatest/tests/clock/test_clock_create_new_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ def test_clock_set_alarm_label(self):


def tearDown(self):

# delete the new alarm
clock_object.delete_alarm(self)

# close the app
if hasattr(self, 'app'):
self.apps.kill(self.app)

GaiaTestCase.tearDown(self)
9 changes: 0 additions & 9 deletions gaiatest/tests/clock/test_clock_delete_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,3 @@ def test_clock_delete_alarm(self):
new_alarms_count = len(self.marionette.find_elements(*clock_object._all_alarms))

self.assertEqual(initial_alarms_count, new_alarms_count+1, "delete alarm failed.")


def tearDown(self):

# close the app
if hasattr(self, 'app'):
self.apps.kill(self.app)

GaiaTestCase.tearDown(self)
17 changes: 4 additions & 13 deletions gaiatest/tests/clock/test_clock_switch_clock_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def test_clock_switch_clock_type(self):
# switch to digital clock
self.marionette.find_element(*clock_object._analog_clock_display).click()
self.wait_for_element_displayed(*clock_object._digital_clock_display)
self.assertTrue(self.marionette.find_element(*clock_object._digital_clock_body).is_displayed(), "The digital clock should be displayed.")
self.assertTrue(self.marionette.find_element(*clock_object._digital_clock_display).is_displayed(), "The digital clock should be displayed.")

# switch to analog clock
self.marionette.find_element(*clock_object._digital_clock_display).click()
self.wait_for_element_displayed(*clock_object._analog_clock_display)
self.assertTrue(self.marionette.find_element(*clock_object._analog_clock_body).is_displayed(), "The analog clock should be displayed.")
self.assertTrue(self.marionette.find_element(*clock_object._analog_clock_display).is_displayed(), "The analog clock should be displayed.")


def test_clock_show_time_date(self):
Expand All @@ -49,20 +49,11 @@ def test_clock_show_time_date(self):
self.marionette.find_element(*clock_object._analog_clock_display).click()
self.wait_for_element_displayed(*clock_object._digital_clock_display)
self.assertTrue(self.marionette.find_element(*clock_object._clock_day_date).is_displayed(), "The date of digital clock should be displayed.")
self.assertTrue(self.marionette.find_element(*clock_object._digital_clock_body).is_displayed(), "The time of digital clock should be displayed.")
self.assertTrue(self.marionette.find_element(*clock_object._digital_clock_display).is_displayed(), "The time of digital clock should be displayed.")
self.assertTrue(self.marionette.find_element(*clock_object._digital_clock_hour24_state).is_displayed(), "The hour24-state of digital clock should be displayed.")

# check the date, time for analog clock
self.marionette.find_element(*clock_object._digital_clock_display).click()
self.wait_for_element_displayed(*clock_object._analog_clock_display)
self.assertTrue(self.marionette.find_element(*clock_object._clock_day_date).is_displayed(), "The date should be displayed.")
self.assertTrue(self.marionette.find_element(*clock_object._analog_clock_body).is_displayed(), "The date should be displayed.")


def tearDown(self):

# close the app
if hasattr(self, 'app'):
self.apps.kill(self.app)

GaiaTestCase.tearDown(self)
self.assertTrue(self.marionette.find_element(*clock_object._analog_clock_display).is_displayed(), "The date should be displayed.")
9 changes: 2 additions & 7 deletions gaiatest/tests/clock/test_clock_turn_on_off_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ def test_clock_turn_on_off_alarm(self):
time.sleep(2)
new_alarm_checked = self.marionette.find_element(*clock_object._alarm_checked_status).get_attribute('checked')
self.assertTrue(origin_alarm_checked != new_alarm_checked, 'user should be able to turn off the alarm.')


def tearDown(self):

# delete the new alarm
clock_object.delete_alarm(self)

# close the app
if hasattr(self, 'app'):
self.apps.kill(self.app)

GaiaTestCase.tearDown(self)
6 changes: 0 additions & 6 deletions gaiatest/tests/contacts/test_add_new_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,3 @@ def test_add_new_contact(self):

contact_locator = self.create_contact_locator(self.contact['givenName'])
self.wait_for_element_displayed(*contact_locator)


def tearDown(self):

# close all apps
self.apps.kill_all()
3 changes: 1 addition & 2 deletions gaiatest/tests/contacts/test_call_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,4 @@ def tearDown(self):
self.marionette.switch_to_frame(self.app.frame_id)
self.data_layer.remove_contact(self.contact)

# close all apps
self.apps.kill_all()
GaiaTestCase.tearDown(self)
3 changes: 1 addition & 2 deletions gaiatest/tests/contacts/test_edit_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,4 @@ def tearDown(self):
self.marionette.switch_to_frame(self.app.frame_id)
self.data_layer.remove_contact(self.contact)

# close all apps
self.apps.kill_all()
GaiaTestCase.tearDown(self)
3 changes: 1 addition & 2 deletions gaiatest/tests/contacts/test_sms_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ def tearDown(self):
self.marionette.switch_to_frame(self.app.frame_id)
self.data_layer.remove_contact(self.contact)

# close all apps
self.apps.kill_all()
GaiaTestCase.tearDown(self)
3 changes: 3 additions & 0 deletions gaiatest/tests/fmradio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 changes: 11 additions & 0 deletions gaiatest/tests/fmradio/manifest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[DEFAULT]
# Test requires B2G
b2g = true

# Test requires antenna (headphones)
antenna = true

[test_fmradio_add_to_favorite.py]
[test_fmradio_find_stations.py]
[test_fmradio_remove_from_favorite.py]
[test_fmradio_turn_on_off.py]
Loading

0 comments on commit 50ee8c9

Please sign in to comment.