From c90c20c1412105a8753c0d1236ae9e72fb29f930 Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Fri, 7 Feb 2014 15:03:21 -0800 Subject: [PATCH 1/2] Bug 969587 - Make customization run without ICCHelper present --- apps/communications/ftu/js/variant.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/communications/ftu/js/variant.js b/apps/communications/ftu/js/variant.js index 44e574a8c717..e5257001da89 100644 --- a/apps/communications/ftu/js/variant.js +++ b/apps/communications/ftu/js/variant.js @@ -4,11 +4,6 @@ var VariantManager = { // This file is created during the BUILD process CUSTOMIZATION_FILE: '/resources/customization.json', init: function vm_init() { - if (!IccHelper) { - console.error('Impossible to access iccInfo via IccHelper. Aborting.'); - return; - } - // Check if the iccInfo is available this.mcc_mnc = this.getMccMnc(); if (this.mcc_mnc) { @@ -40,7 +35,9 @@ var VariantManager = { iccHandler: function vm_iccHandler() { this.mcc_mnc = this.getMccMnc(); if (this.mcc_mnc) { - IccHelper.removeEventListener('iccinfochange', this.boundIccHandler); + if (IccHelper) { + IccHelper.removeEventListener('iccinfochange', this.boundIccHandler); + } // Load the variant customizers and the variant JSON file. LazyLoader.load( this.CUSTOMIZERS, @@ -86,8 +83,20 @@ var VariantManager = { }, getMccMnc: function vm_getMccMnc() { - var mcc = IccHelper.iccInfo ? IccHelper.iccInfo.mcc : undefined; - var mnc = IccHelper.iccInfo ? IccHelper.iccInfo.mnc : undefined; + var mcc = undefined; + var mnc = undefined; + // If we have valid iccInfo, use that. Otherwise continue with undefined + // values. + if (IccHelper && IccHelper.iccInfo) { + mcc = IccHelper.iccInfo.mcc; + mnc = IccHelper.iccInfo.mnc; + } else if (!IccHelper || IccHelper.cardState === null) { + // if IccHelper isn't available or if it is available + // but has null cardState (this means no SIM available) configure with + // defaults + mcc = '000'; + mnc = '000'; + } if ((mcc !== undefined) && (mcc !== null) && (mnc !== undefined) && (mnc !== null)) { return this.normalizeCode(mcc) + '-' + this.normalizeCode(mnc); From 8afc6521e1b33d75b5fc726a407f08fe7b3f8b09 Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Mon, 10 Feb 2014 16:52:00 -0800 Subject: [PATCH 2/2] Bug 969587 - Integration tests for FTU variant customization --- apps/browser/build/build.js | 2 + .../ftu/test/marionette/ftu_tests.js | 53 +++++++------------ .../ftu/test/marionette/lib/ftu_test_lib.js | 36 +++++++++++++ .../ftu/test/marionette/variant_test.js | 34 ++++++++++++ .../unit/resources/default_bookmarks.json | 13 +++++ 5 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 apps/communications/ftu/test/marionette/lib/ftu_test_lib.js create mode 100644 apps/communications/ftu/test/marionette/variant_test.js create mode 100644 apps/communications/ftu/test/unit/resources/default_bookmarks.json diff --git a/apps/browser/build/build.js b/apps/browser/build/build.js index 26a566486477..0acc8bbe9dbe 100644 --- a/apps/browser/build/build.js +++ b/apps/browser/build/build.js @@ -20,6 +20,8 @@ BrowserAppBuilder.prototype.setOptions = function(options) { }; BrowserAppBuilder.prototype.initJSON = function() { + // Note: The variant integration test in FTU will need to be changed if the + // defaults here change, otherwise the tests will fail. var defaultJSONpath = utils.joinPath(this.appDir.path, 'build', 'default.json'); var defaultJson = utils.getJSON(utils.getFile(defaultJSONpath)); diff --git a/apps/communications/ftu/test/marionette/ftu_tests.js b/apps/communications/ftu/test/marionette/ftu_tests.js index f50e3cd10720..513bf6984f70 100644 --- a/apps/communications/ftu/test/marionette/ftu_tests.js +++ b/apps/communications/ftu/test/marionette/ftu_tests.js @@ -1,47 +1,34 @@ +/* jshint node: true */ +'use strict'; + marionette('First Time Use >', function() { var assert = require('assert'); - var FTU = 'app://communications.gaiamobile.org'; - + var FTU = require('./lib/ftu_test_lib').FTU; var client = marionette.client(); - - var clickThruPanel = function(panel_id, button_id) { - if (panel_id == '#wifi') { - // The wifi panel will bring up a screen to show it is scanning for - // networks. Not waiting for this to clear will blow test timing and cause - // things to fail. - client.helper.waitForElementToDisappear('#loading-overlay'); - } - // waitForElement is used to make sure animations and page changes have - // finished, and that the panel is displayed. - client.helper.waitForElement(panel_id); - if (button_id) { - var button = client.waitForElement(button_id); - button.click(); - } - }; + var ftu = new FTU(client); test('FTU comes up on profile generation', function() { - client.apps.switchToApp(FTU); + ftu.waitForFTU(); }); test('FTU click thru', function() { - client.apps.switchToApp(FTU); - clickThruPanel('#languages', '#forward'); - clickThruPanel('#wifi', '#forward'); - clickThruPanel('#date_and_time', '#forward'); - clickThruPanel('#geolocation', '#forward'); - clickThruPanel('#import_contacts', '#forward'); - clickThruPanel('#welcome_browser', '#forward'); - clickThruPanel('#browser_privacy', '#forward'); - clickThruPanel('#finish-screen', undefined); + ftu.waitForFTU(); + ftu.clickThruPanel('#languages', '#forward'); + ftu.clickThruPanel('#wifi', '#forward'); + ftu.clickThruPanel('#date_and_time', '#forward'); + ftu.clickThruPanel('#geolocation', '#forward'); + ftu.clickThruPanel('#import_contacts', '#forward'); + ftu.clickThruPanel('#welcome_browser', '#forward'); + ftu.clickThruPanel('#browser_privacy', '#forward'); + ftu.clickThruPanel('#finish-screen', undefined); }); test('FTU Wifi Scanning Tests', function() { - client.apps.switchToApp(FTU); - clickThruPanel('#languages', '#forward'); - clickThruPanel('#wifi', '#forward'); - clickThruPanel('#date_and_time', '#back'); - clickThruPanel('#wifi', undefined); + ftu.waitForFTU(); + ftu.clickThruPanel('#languages', '#forward'); + ftu.clickThruPanel('#wifi', '#forward'); + ftu.clickThruPanel('#date_and_time', '#back'); + ftu.clickThruPanel('#wifi', undefined); }); }); diff --git a/apps/communications/ftu/test/marionette/lib/ftu_test_lib.js b/apps/communications/ftu/test/marionette/lib/ftu_test_lib.js new file mode 100644 index 000000000000..d3d74675151b --- /dev/null +++ b/apps/communications/ftu/test/marionette/lib/ftu_test_lib.js @@ -0,0 +1,36 @@ +/* jshint node: true */ +'use strict'; + +function FTUHelper(client) { + this.client = client; +} + +FTUHelper.prototype = { + client: null, + FTU_URL: 'app://communications.gaiamobile.org', + waitForFTU: function() { + this.client.apps.switchToApp(this.FTU_URL); + }, + clickThruPanel: function(panel_id, button_id) { + if (panel_id == '#wifi') { + // The wifi panel will bring up a screen to show it is scanning for + // networks. Not waiting for this to clear will blow test timing and cause + // things to fail. + this.client.helper.waitForElementToDisappear('#loading-overlay'); + } + // waitForElement is used to make sure animations and page changes have + // finished, and that the panel is displayed. + this.client.helper.waitForElement(panel_id); + if (button_id) { + var button = this.client.helper.waitForElement(button_id); + button.click(); + } + }, + close: function() { + this.client.apps.close(this.FTU_URL); + } +}; + +module.exports = { + FTU: FTUHelper +}; diff --git a/apps/communications/ftu/test/marionette/variant_test.js b/apps/communications/ftu/test/marionette/variant_test.js new file mode 100644 index 000000000000..4bbd061acd90 --- /dev/null +++ b/apps/communications/ftu/test/marionette/variant_test.js @@ -0,0 +1,34 @@ +/* jshint node: true */ +'use strict'; + +marionette('First Time Use > Single Variant Customization > ', function() { + var assert = require('assert'); + var FTU = require('./lib/ftu_test_lib').FTU; + var client = marionette.client(); + var ftu = new FTU(client); + + var browser_url = 'app://browser.gaiamobile.org'; + + // This test will need to be changed if we change default bookmarks in + // build system. + test('FTU runs customization when no ICCHelper available', function() { + // wait for the ftu to come up, which means customization will have been run + ftu.waitForFTU(); + ftu.close(); + // bring up browser + client.apps.launch(browser_url); + client.apps.switchToApp(browser_url); + + // Wait for the document body to know we're really 'launched'. + client.helper.waitForElement('body'); + + // Bring up the bookmarks tab, make sure we have 2 bookmarks. Not the most + // through of tests, but it'll do for now. + client.findElement('#url-input').click(); + client.findElement('#bookmarks-tab').click(); + client.helper.waitForElement('#bookmarks > ul'); + var links = client.findElements('#bookmarks > ul > li'); + assert(links.length == 2, 'Not enough links in bookmarks! ' + links.length); + }); + +}); diff --git a/apps/communications/ftu/test/unit/resources/default_bookmarks.json b/apps/communications/ftu/test/unit/resources/default_bookmarks.json new file mode 100644 index 000000000000..3969bc085fcf --- /dev/null +++ b/apps/communications/ftu/test/unit/resources/default_bookmarks.json @@ -0,0 +1,13 @@ +{ + "bookmarks": [ + { "title": "Test", + "uri": "http://www.google.com", + "iconUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC[truncated]" + }, + { "title": "Also Test", + "uri": "http://www.google.co.uk", + "iconUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC[truncated]" + } + + ] +}