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

Commit

Permalink
Merge pull request #14338 from dwi2/bug942762
Browse files Browse the repository at this point in the history
Bug 942762 - Update label of bookmark on homescreen when user update boo...
  • Loading branch information
dwi2 committed Dec 20, 2013
2 parents db9f8c6 + fd14f08 commit af74217
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 4 deletions.
7 changes: 3 additions & 4 deletions apps/homescreen/js/page.js
Expand Up @@ -494,8 +494,7 @@ Icon.prototype = {
*/
translate: function icon_translate() {
var descriptor = this.descriptor;
if (descriptor.type === GridItemsFactory.TYPE.BOOKMARK ||
descriptor.customName)
if (descriptor.customName)
return;

var app = this.app;
Expand All @@ -506,13 +505,13 @@ Icon.prototype = {
if (!manifest)
return;

var localizedName;
var localizedName = manifest.name;

if (descriptor.type === GridItemsFactory.TYPE.COLLECTION) {
// try to translate, but fall back to current name
// (translation might fail for custom collection name)
localizedName = navigator.mozL10n.get(manifest.name) || manifest.name;
} else {
} else if (descriptor.type !== GridItemsFactory.TYPE.BOOKMARK) {
var iconsAndNameHolder = manifest;
var entryPoint = descriptor.entry_point;
if (entryPoint)
Expand Down
11 changes: 11 additions & 0 deletions apps/homescreen/test/marionette/fixtures/sample.html
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sample page</title>
</head>
<body>
<header><h1>Mozilla</h1></header>
<section>We are global community with a common purpose</section>
</body>
</html>
111 changes: 111 additions & 0 deletions apps/homescreen/test/marionette/install_bookmark_test.js
@@ -0,0 +1,111 @@
'use strict';

var assert = require('assert');
var Browser = require('./lib/browser');
var Homescreen = require('./lib/homescreen');
var Server = require('./lib/server');

marionette('Install bookmark on homescreen', function() {
var client = marionette.client({
settings: {
// disable keyboard ftu because it blocks our display
'keyboard.ftu.enabled': false
}
});
var browser;
var homescreen;
var server;

suiteSetup(function(done) {
Server.create(function(err, _server) {
server = _server;
done();
});
});

suiteTeardown(function() {
server.stop();
});

setup(function() {
browser = new Browser(client);
browser.launch();
client.helper.waitForElement('body.loaded');
});

suite(' > Navigate to sample.html and bookmark it on homescreen', function() {
var url;
var expectedTitle = 'Sample page';

setup(function() {
var notifToaster;
homescreen = new Homescreen(client);

url = server.url('sample.html');

// Running tests with B2G desktop on Linux, a 'Download complete'
// notification-toaster will pop up and make tests failed
client.switchToFrame();
notifToaster = client.findElement('#notification-toaster');
if (notifToaster.displayed()) {
// Bug 952377: client.helper.waitForElementToDisappear(notifToaster)
// will failed and got timeout.
// (notifToaster.displayed() is always true)
// So we workaround this to wait for .displayed get removed
// from notifToaster
client.helper.waitFor(function() {
return notifToaster.getAttribute('class').indexOf('displayed') < 0;
});
}
browser.backToApp();

browser.searchBar.sendKeys(url);
browser.searchButton.click();
// this will fail on linux because a downloaded notification poped up
client.helper.waitForElement(browser.bookmarkButton).click();
client.helper.waitForElement(browser.addToHomeButton).click();
homescreen.switchToBookmarkEditorFrame();
homescreen.bookmarkEditor.bookmarkAddButton.click();
});

test(' sample.html is on homescreen with expected title',
function() {
client.switchToFrame();
homescreen.launch();
assert.ok(homescreen.getHomescreenIcon(expectedTitle) != null);
assert.ok(
homescreen.getLabelOfBookmark(expectedTitle).text(),
expectedTitle);
});

suite(' > Change the title of bookmark on homescreen to new expected title',
function() {
var newExpectedTitle = 'New Title';

setup(function() {
homescreen.bookmarkEditor.waitForDisappearance();
browser.backToApp();
client.helper.waitForElement(browser.bookmarkButton).click();
client.helper.waitForElement(browser.addToHomeButton).click();
homescreen.switchToBookmarkEditorFrame();
homescreen.bookmarkEditor.bookmarkTitleField.clear();
homescreen.bookmarkEditor
.bookmarkTitleField.sendKeys(newExpectedTitle);
// tap head element to make keyboard away
homescreen.bookmarkEditor.bookmarkEntrySheetHead.tap();
homescreen.bookmarkEditor.bookmarkAddButton.click();
});

test(' And we change the title of it', function() {
client.switchToFrame();
homescreen.launch();
// aria-label won't change after we change bookmark title,
// so we select the element using previous title
assert.ok(homescreen.getHomescreenIcon(expectedTitle) != null);
assert.ok(
homescreen.getLabelOfBookmark(expectedTitle).text(),
newExpectedTitle);
});
});
});
});
44 changes: 44 additions & 0 deletions apps/homescreen/test/marionette/lib/bookmark_editor.js
@@ -0,0 +1,44 @@
var BookmarkEditor = function b_ctor(client) {
this.client = client;
};

BookmarkEditor.Selectors = {
'mozbrowser': '.inline-activity.active > iframe[mozbrowser]',
'bookmarkAddButton': '#button-bookmark-add',
'bookmarkTitleField': '#bookmark-title',
'bookmarkEntrySheetHead': '#bookmark-entry-sheet > header > h1'
};

BookmarkEditor.prototype = {
get bookmarkAddButton() {
return this.client.findElement(
BookmarkEditor.Selectors['bookmarkAddButton']);
},

get bookmarkTitleField() {
return this.client.findElement(
BookmarkEditor.Selectors['bookmarkTitleField']);
},

get bookmarkEntrySheetHead() {
return this.client.findElement(
BookmarkEditor.Selectors['bookmarkEntrySheetHead']);
},

get currentTabFrame() {
return this.client.findElement(
BookmarkEditor.Selectors['mozbrowser']);
},

backToApp: function() {
this.client.switchToFrame();
this.client.switchToFrame(this.currentTabFrame);
},

waitForDisappearance: function() {
this.client.switchToFrame();
this.client.helper.waitForElementToDisappear(this.currentTabFrame);
}
};

module.exports = BookmarkEditor;
78 changes: 78 additions & 0 deletions apps/homescreen/test/marionette/lib/browser.js
@@ -0,0 +1,78 @@
/**
* Abstraction around browser app.
* @constructor
* @param {Marionette.Client} client for operations.
*/
function Browser(client) {
this.client = client;
}

/**
* @type {string} Origin of browser app.
*/
Browser.URL = 'app://browser.gaiamobile.org';

Browser.Selectors = {
'searchBar': '#url-input',
'searchButton': '#url-button',
'mozbrowser': 'iframe[mozbrowser]',
'bookmarkButton': '#bookmark-button',
'addToHomeButton': '#bookmark-menu-add-home'
};

/**
* @private
* @param {Marionette.Client} client for selector.
* @param {String} name of selector [its a key in Browser.Selectors].
*/
function findElement(client, name) {
return client.findElement(Browser.Selectors[name]);
}

Browser.prototype = {
get searchBar() {
return findElement(this.client, 'searchBar');
},

get searchButton() {
return findElement(this.client, 'searchButton');
},

get bookmarkButton() {
return findElement(this.client, 'bookmarkButton');
},

get addToHomeButton() {
return findElement(this.client, 'addToHomeButton');
},

/**
* Finds iframe of current running tab.
*/
currentTabFrame: function() {
// being really lazy right now and just finding first mozbrowser
return this.client.findElement(Browser.Selectors.mozbrowser);
},

/**
* Launches browser app and focuses on frame.
*/
launch: function() {
this.client.apps.launch(Browser.URL);
this.client.apps.switchToApp(Browser.URL);
},

close: function() {
this.client.apps.close(Browser.URL);
},

/**
* Back to Browser app frame
*/
backToApp: function() {
this.client.switchToFrame();
this.client.apps.switchToApp(Browser.URL);
}
};

module.exports = Browser;
31 changes: 31 additions & 0 deletions apps/homescreen/test/marionette/lib/homescreen.js
Expand Up @@ -7,6 +7,8 @@ function Homescreen(client) {
this.client = client;
}

var BookmarkEditor = require('./bookmark_editor');

/**
* @type String Origin of Homescreen app
*/
Expand All @@ -17,6 +19,13 @@ Homescreen.Selectors = {
};

Homescreen.prototype = {
get bookmarkEditor() {
if (!this._bookmarkEditor) {
this._bookmarkEditor = new BookmarkEditor(this.client);
}
return this._bookmarkEditor;
},

/**
* Launches Homescreen app and focuses on frame.
*/
Expand All @@ -33,6 +42,28 @@ Homescreen.prototype = {
var selectors = Homescreen.Selectors;
this.client.helper.waitForElement(selectors.searchBar)
.click();
},

close: function() {
this.client.apps.close(Homescreen.URL);
},

backToApp: function() {
this.client.switchToFrame();
this.client.apps.switchToApp(Homescreen.URL);
},

getHomescreenIcon: function(title) {
return this.client.findElement('li.icon[aria-label="' + title + '"]');
},

getLabelOfBookmark: function(title) {
return this.client.findElement(
'li.icon[aria-label="' + title + '"] span.labelWrapper > span');
},

switchToBookmarkEditorFrame: function() {
this.bookmarkEditor.backToApp();
}
};

Expand Down
45 changes: 45 additions & 0 deletions apps/homescreen/test/marionette/lib/server.js
@@ -0,0 +1,45 @@
function Server(port, child) {
this.port = port;
this.child = child;
}

Server.prototype = {
/**
* Formats given input with localhost and port.
*
* @param {String} path part of url.
* @return {String} url of location.
*/
url: function(path) {
return 'http://localhost:' + this.port + '/' + path;
},

/**
* Sends signal to stop child process and stop server.
*/
stop: function() {
this.child.send('stop');
this.child.kill();
}
};

/**
* Spawn the child process where the http server lives.
*
* @param {Function} callback [Error err, Server server].
*/
function create(callback) {
var fork = require('child_process').fork;
var child = fork(__dirname + '/server_child.js');

// wait for start message ['start', PORT_NUMBER].
child.on('message', function(data) {
if (Array.isArray(data) && data[0] === 'start') {
callback(null, new Server(data[1], child));
}
});
}

Server.create = create;

module.exports = Server;

0 comments on commit af74217

Please sign in to comment.