This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14338 from dwi2/bug942762
Bug 942762 - Update label of bookmark on homescreen when user update boo...
- Loading branch information
Showing
8 changed files
with
366 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
111
apps/homescreen/test/marionette/install_bookmark_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Oops, something went wrong.