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 #29532 from punamdahiya/Bug1080122
Bug 1080122 - [Gallery] Add gallery activities marionette tests
- Loading branch information
Showing
7 changed files
with
487 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* global require, marionette, setup, __dirname */ | ||
'use strict'; | ||
|
||
var Gallery = require('./lib/gallery.js'), | ||
GalleryActivityTester = require('./lib/galleryactivitytester.js'), | ||
System = require('./lib/system.js'), | ||
assert = require('assert'); | ||
|
||
marionette('Gallery Activity Tests', function() { | ||
|
||
var client, apps = {}; | ||
|
||
apps[GalleryActivityTester.ORIGIN] = | ||
__dirname + '/apps/galleryactivitytester'; | ||
|
||
client = marionette.client({ | ||
profile: { | ||
prefs: { | ||
'device.storage.enabled': true, | ||
'device.storage.testing': true, | ||
'device.storage.prompt.testing': true | ||
}, | ||
apps: apps | ||
} | ||
}); | ||
|
||
var galleryApp, activityTesterApp, system; | ||
var imageInfo = { | ||
name: 'pictures/firefoxOS.png', | ||
type: 'image/png', | ||
size: '52458' | ||
}; | ||
|
||
setup(function() { | ||
// Remove all files in temp device storage. | ||
client.fileManager.removeAllFiles(); | ||
// Add file into the pictures directory | ||
client.fileManager.add({ | ||
type: 'pictures', | ||
filePath: 'test_media/Pictures/firefoxOS.png' | ||
}); | ||
galleryApp = new Gallery(client); | ||
activityTesterApp = GalleryActivityTester.create(client); | ||
system = new System(client); | ||
}); | ||
|
||
test('pick and open image using gallery pick and open activity', function() { | ||
activityTesterApp.launch(); | ||
// Initiate pick activity by clicking pick image button | ||
activityTesterApp.tapPickImageButton(); | ||
|
||
// Tap Gallery button from Systm app Action Menu | ||
system.menuOptionButton('Gallery').tap(); | ||
|
||
// We've switched to the system app, and we're calling | ||
// switchToApp that waits for gallery app and then switch to gallery app | ||
client.apps.switchToApp(Gallery.ORIGIN); | ||
|
||
// Select image from thumbnail list in gallery app | ||
galleryApp.tapFirstThumbnail(); | ||
|
||
client.waitFor(function(){ | ||
return galleryApp.editCropCanvas.displayed(); | ||
}); | ||
|
||
galleryApp.cropDoneButton.click(); | ||
system.switchToApp(GalleryActivityTester.ORIGIN); | ||
|
||
client.waitFor(function(){ | ||
return activityTesterApp.pickedImageName.displayed(); | ||
}); | ||
|
||
// Compare returned blob name, type and size with the | ||
// image loaded in gallery app | ||
var pickedImageName = activityTesterApp.pickedImageName.text(); | ||
assert.strictEqual(pickedImageName, imageInfo.name); | ||
|
||
var pickedImageType = activityTesterApp.pickedImageType.text(); | ||
assert.strictEqual(pickedImageType, imageInfo.type); | ||
|
||
var pickedImageSize = activityTesterApp.pickedImageSize.text(); | ||
assert.strictEqual(pickedImageSize, imageInfo.size); | ||
|
||
// Open the picked image using open activity | ||
// with allowSave option as true. Tap picked | ||
// image and invoke gallery open activity | ||
activityTesterApp.tapPickedImage(); | ||
system.switchToApp(Gallery.ORIGIN); | ||
|
||
// Check if the filename displayed in titlebar matches | ||
// data sent by the initiating app | ||
var title = galleryApp.openActivityImageTitle.text(); | ||
assert.strictEqual(title, 'firefoxOS.png'); | ||
|
||
// Check if save button is displayed | ||
client.helper.waitForElement(galleryApp.openActivitySaveButton); | ||
assert.ok(galleryApp.openActivitySaveButton.displayed()); | ||
|
||
client.waitFor(function(){ | ||
return galleryApp.openActivityImage.displayed(); | ||
}); | ||
|
||
// Check if displayed image src is set with blob url | ||
assert.ok(galleryApp.hasSrcImageBlobURL()); | ||
}); | ||
|
||
test('share image using gallery share activity', function() { | ||
galleryApp.launch(); | ||
galleryApp.tapFirstThumbnail(); | ||
galleryApp.shareButton.tap(); | ||
|
||
system.menuOptionButton('Gallery Activity Tester').tap(); | ||
system.switchToApp(GalleryActivityTester.ORIGIN); | ||
|
||
client.waitFor(function(){ | ||
return activityTesterApp.sharedImageName.displayed(); | ||
}); | ||
|
||
// Compare shared blob name, type and size with the | ||
// image loaded in gallery app | ||
var sharedImageName = activityTesterApp.sharedImageName.text(); | ||
assert.strictEqual(sharedImageName, imageInfo.name); | ||
|
||
var sharedImageType = activityTesterApp.sharedImageType.text(); | ||
assert.strictEqual(sharedImageType, imageInfo.type); | ||
|
||
var sharedImageSize = activityTesterApp.sharedImageSize.text(); | ||
assert.strictEqual(sharedImageSize, imageInfo.size); | ||
}); | ||
|
||
|
||
test('open memory backed blob using gallery open activity', function() { | ||
activityTesterApp.launch(); | ||
// Initiate open activity by clicking open image button. | ||
// This will generate memory backed blob using canvas | ||
// and trigger open activity to view the blob | ||
activityTesterApp.tapOpenImageButton(); | ||
|
||
system.switchToApp(Gallery.ORIGIN); | ||
|
||
// Check there is no filename in title bar | ||
var title = galleryApp.openActivityImageTitle.text(); | ||
assert.strictEqual(title, ''); | ||
|
||
// Check save button is not displayed | ||
assert.ok(!galleryApp.openActivitySaveButton.displayed(), | ||
'Save button is not displayed'); | ||
|
||
client.waitFor(function(){ | ||
return galleryApp.openActivityImage.displayed(); | ||
}); | ||
|
||
// Check if displayed image src is set with blob url | ||
assert.ok(galleryApp.hasSrcImageBlobURL()); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
apps/gallery/test/marionette/apps/galleryactivitytester/index.html
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,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Gallery Activity Tester</title> | ||
<script defer src="/js/galleryactivitytester.js"></script> | ||
</head> | ||
|
||
<body> | ||
<div>Gallery Activity Tester</div> | ||
<button id="open-image">Generate Blob and Open Image</button> | ||
<button id="pick-image">Pick Image</button> | ||
<div id="pick-activity-data"> | ||
<span class="name"></span> | ||
<span class="type"></span> | ||
<span class="size"></span> | ||
<img id="picked-image"></img> | ||
</div> | ||
|
||
<div id="share-activity-data"> | ||
<span class="name"></span> | ||
<span class="type"></span> | ||
<span class="size"></span> | ||
<img></img> | ||
</div> | ||
|
||
</body> | ||
</html> |
104 changes: 104 additions & 0 deletions
104
apps/gallery/test/marionette/apps/galleryactivitytester/js/galleryactivitytester.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,104 @@ | ||
/* global MozActivity */ | ||
(function(window) { | ||
'use strict'; | ||
|
||
var image_blob; | ||
|
||
function generateBlob(width, height, type) { | ||
var canvas = document.createElement('canvas'); | ||
var context = canvas.getContext('2d'); | ||
|
||
canvas.width = width; | ||
canvas.height = height; | ||
|
||
context.fillStyle = 'orange'; | ||
context.fillRect (0, 0, width, height); | ||
|
||
return new Promise(function(resolve) { | ||
canvas.toBlob(function(blob) { | ||
canvas.width = canvas.height = 0; | ||
canvas = null; | ||
|
||
resolve(blob); | ||
}, type); | ||
}); | ||
} | ||
|
||
function loadImageData(id, blob) { | ||
var imageUrl = window.URL.createObjectURL(blob); | ||
var img = document.querySelector(id + ' > img'); | ||
img.src = imageUrl; | ||
|
||
document.querySelector(id + ' > span.name').innerHTML = blob.name; | ||
document.querySelector(id + ' > span.type').innerHTML = blob.type; | ||
document.querySelector(id + ' > span.size').innerHTML = blob.size; | ||
} | ||
|
||
window.addEventListener('load', function() { | ||
var pickImageButton = document.getElementById('pick-image'); | ||
|
||
pickImageButton.addEventListener('click', function() { | ||
var activity = new MozActivity({ | ||
name: 'pick', | ||
data: { | ||
type: 'image/*', | ||
} | ||
}); | ||
activity.onsuccess = function() { | ||
image_blob = activity.result.blob; | ||
// Populate test app elements with returned activity data | ||
loadImageData('#pick-activity-data', activity.result.blob); | ||
}; | ||
activity.onerror = function() { | ||
console.warn('pick activity error:', activity.error.name); | ||
}; | ||
}); | ||
|
||
var pickedImage = document.getElementById('picked-image'); | ||
|
||
// Add click event handler to received image to | ||
// trigger gallery app open activity | ||
pickedImage.addEventListener('click', function() { | ||
var activity = new MozActivity({ | ||
name: 'open', | ||
data: { | ||
type: 'image/png', | ||
filename: 'pictures/firefoxOS.png', | ||
blob: image_blob, | ||
allowSave: true | ||
} | ||
}); | ||
activity.onerror = function() { | ||
console.warn('open activity error:', activity.error.name); | ||
}; | ||
}); | ||
|
||
|
||
var openImageButton = document.getElementById('open-image'); | ||
|
||
// Add click event handler to open image button to generate memory | ||
// backed blob and open it using gallery app open activity | ||
openImageButton.addEventListener('click', function() { | ||
generateBlob(100, 100, 'image/jpeg').then(function(blob) { | ||
var activity = new MozActivity({ | ||
name: 'open', | ||
data: { | ||
type: blob.type, | ||
blob: blob | ||
} | ||
}); | ||
activity.onerror = function() { | ||
console.warn('open activity error while opening memory backed blob:', | ||
activity.error.name); | ||
}; | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
window.navigator.mozSetMessageHandler('activity', function(activity) { | ||
// Populate test app elements with shared activity data | ||
loadImageData('#share-activity-data', activity.source.data.blobs[0]); | ||
}); | ||
|
||
})(window); |
20 changes: 20 additions & 0 deletions
20
apps/gallery/test/marionette/apps/galleryactivitytester/manifest.webapp
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,20 @@ | ||
{ | ||
"name": "Gallery Activity Tester", | ||
"description": "Gallery Activity Tester app", | ||
"type": "privileged", | ||
"launch_path": "/index.html", | ||
"developer": { | ||
"name": "The Gaia Team", | ||
"url": "https://github.com/mozilla-b2g/gaia" | ||
}, | ||
"activities": { | ||
"share": { | ||
"href": "/index.html#activity-share", | ||
"filters": { | ||
"type": ["image/*"] | ||
}, | ||
"disposition": "window", | ||
"returnValue": true | ||
} | ||
} | ||
} |
Oops, something went wrong.