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 #30054 from gaye/bug-1164686
Browse files Browse the repository at this point in the history
Bug 1164686 - Move marionette-js-logger into gaia
  • Loading branch information
Gareth Aye committed May 13, 2015
2 parents 1eedfcc + 9980ae9 commit b717c8e
Show file tree
Hide file tree
Showing 30 changed files with 1,234 additions and 11 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Expand Up @@ -62,3 +62,4 @@ tv_apps/smart-system/bower_components/**
tv_apps/tv-deck/bower_components/**
tests/atoms/remote_date.js
tests/atoms/screenshot.js
tests/jsmarionette/marionette-js-logger/lib/log_grabber.js
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -802,6 +802,10 @@ test-integration-test: b2g
--reporter $(REPORTER) \
--buildapp $(BUILDAPP)

.PHONY: test-marionette-logger
test-marionette-logger: b2g node_modules
./node_modules/.bin/marionette-mocha $(wildcard tests/jsmarionette/marionette-js-logger/test/*.js)

.PHONY: caldav-server-install
caldav-server-install:
source tests/ci/venv.sh; \
Expand Down
Expand Up @@ -2,7 +2,7 @@

var Dialer = require('./lib/dialer');
var ReflowHelper =
require('../../../../../tests/js-marionette/reflow_helper.js');
require('../../../../../tests/jsmarionette/reflow_helper.js');

marionette('Dialer > Keypad', function() {
var assert = require('assert');
Expand Down
2 changes: 1 addition & 1 deletion apps/communications/dialer/test/marionette/keypad_test.js
Expand Up @@ -2,7 +2,7 @@

var Dialer = require('./lib/dialer');
var ReflowHelper =
require('../../../../../tests/js-marionette/reflow_helper.js');
require('../../../../../tests/jsmarionette/reflow_helper.js');

marionette('Dialer > Keypad', function() {
var assert = require('assert');
Expand Down
2 changes: 1 addition & 1 deletion apps/system/test/marionette/edges_gesture_test.js
@@ -1,7 +1,7 @@
'use strict';

var ReflowHelper =
require('../../../../tests/js-marionette/reflow_helper.js');
require('../../../../tests/jsmarionette/reflow_helper.js');

var assert = require('assert');

Expand Down
2 changes: 1 addition & 1 deletion apps/system/test/marionette/font_utils_test.js
Expand Up @@ -2,7 +2,7 @@

marionette('FontSizeUtils >', function() {
var ReflowHelper =
require('../../../../tests/js-marionette/reflow_helper.js');
require('../../../../tests/jsmarionette/reflow_helper.js');

var assert = require('assert');

Expand Down
2 changes: 1 addition & 1 deletion apps/system/test/marionette/homescreen_navigation_test.js
Expand Up @@ -2,7 +2,7 @@

marionette('Homescreen navigation >', function() {
var ReflowHelper =
require('../../../../tests/js-marionette/reflow_helper.js');
require('../../../../tests/jsmarionette/reflow_helper.js');

var assert = require('assert');

Expand Down
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert');
var appUrl = 'app://fullscreen_layout.gaiamobile.org';

var ReflowHelper =
require('../../../../tests/js-marionette/reflow_helper.js');
require('../../../../tests/jsmarionette/reflow_helper.js');

marionette('Software Home Button - Fullscreen Layout', function() {

Expand Down
2 changes: 1 addition & 1 deletion apps/system/test/marionette/statusbar_icon_color_test.js
Expand Up @@ -2,7 +2,7 @@

var Rocketbar = require('../../../system/test/marionette/lib/rocketbar');
var Bookmark = require('../../../system/test/marionette/lib/bookmark');
var helper = require('../../../../tests/js-marionette/helper.js');
var helper = require('../../../../tests/jsmarionette/helper.js');
var SETTINGS_APP = 'app://settings.gaiamobile.org';
var Server = require('../../../../shared/test/integration/server');
var UtilityTray = require('./lib/utility_tray');
Expand Down
2 changes: 1 addition & 1 deletion apps/system/test/marionette/task_manager_test.js
Expand Up @@ -4,7 +4,7 @@ var TaskManager = require('./lib/task_manager');
var FakeApp = require('./lib/fakeapp');
var assert = require('assert');
var ReflowHelper =
require('../../../../tests/js-marionette/reflow_helper.js');
require('../../../../tests/jsmarionette/reflow_helper.js');

marionette('Task Manager', function() {
var firstAppOrigin = 'fakeapp.gaiamobile.org';
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -54,7 +54,8 @@
"watch": "~0.9.0",
"archiver": "^0.10.0",
"mime": "^1.2.11",
"slugid": "^1.0.2"
"slugid": "^1.0.2",
"websocket": "1.0.x"
},
"dependencies": {
"diveSync": "^0.2.1",
Expand Down
3 changes: 1 addition & 2 deletions tests/.jshintrc
Expand Up @@ -9,7 +9,6 @@
"marionetteScriptFinished",
"module",
"require",
"requireGaia",
"process"
]
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/jsmarionette/marionette-js-logger/.jshintrc
@@ -0,0 +1,12 @@
{
"extends": "../../.jshintrc",
"node": true,

"predef": [
"suite",
"suiteSetup",
"suiteTeardown",
"teardown",
"test"
]
}
90 changes: 90 additions & 0 deletions tests/jsmarionette/marionette-js-logger/README.md
@@ -0,0 +1,90 @@
# Marionette JS Console plugin

[![Build
Status](https://travis-ci.org/mozilla-b2g/marionette-js-logger.png)](https://travis-ci.org/mozilla-b2g/marionette-js-logger)

Installs code into the client to buffer all of the logged console messages.
Because of the presumed synchronous operation of marionette-js-runner, Messages
are retrieved when explicitly requested or as an implict byproduct of waiting
for specific log messages.



## Usage

```js

// create the plugin. This must run before startSession.
client.plugin('logger', require('marionette-js-logger'));

client.startSession(function() {
logGrabber = client.logger;

// You can listen for the 'message' event, it will be fired when calls cause
// logs to be retrieved from the server.
logGrabber.on('message', function(msg) {
msg.window; // The URI of the document/window the log happened in
msg.level; // log/info/warn/error/exception/debug
msg.message; // raw string of message
msg.filename; // source file log call was made from
msg.lineNumber; // line number where call was made
msg.functionName; // function name where call was made
msg.timeStamp; // standard JS timestamp; milliseconds since the epoch (UTC)
};

// Explicitly fetch all available logs from the server, emitting 'message'
// events.
logGrabber.grabLogMessages();

// Fetch all available logs from the server, but if there aren't any there
// yet, wait for at least one new message to be logged. This will wait for
// at least one turn of the event loop before returning for efficiency reasons
// and to avoid mistaken understandings of the state of the device. Do not
// depend on this to leave certain messages on the device.
logGrabber.grabAtLeastOneNewMessage();

// Keep fetching logs from the server and calling the provided method until
// it returns true indicating it found the log message it wanted. 'message'
// events will still be emitted for all logs retrieved as a result of these
// calls. While the function will only be called on messages until it returns
// true and will not be called for any messages retrieved after the first call
// that returns true, 'message' events will be emitted for ALL retrieved logs.
// Also, subsequent calls to waitForLogMessage will only call the function
// for newly retrieved logs.
logGrabber.waitForLogMessage(function checksEveryNewMessage(msg) {
return /my car keys/.test(msg.message);
});

client.executeScript(function() {
// this works too but more importantly all other console.log's in content work too
console.log(document.location.href);
});

client.deleteSession();
});
```
## LICENSE
Copyright (c) 2013 Mozilla Foundation
Contributors: Sahaja James Lal jlal@mozilla.com
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 changes: 33 additions & 0 deletions tests/jsmarionette/marionette-js-logger/index.js
@@ -0,0 +1,33 @@
'use strict';
var LogGrabber = require('./lib/log_grabber').LogGrabber;

/**
* How many log entries should be buffered in the device for our retrieval? The
* obvious trade-off here is between memory and losing log entries. And the
* underlying variables are rate of log generation and how often we poll for new
* logs.
*/
var DEFAULT_LOG_LIMIT = 10000;

function setup(client, options) {
if (!options) {
options = {};
}

var grabber = new LogGrabber(client, options.logLimit || DEFAULT_LOG_LIMIT);

// Note! marionette-js-runner's createHost method uses resetWithDriver every
// time it goes to instantiate us. As a byproduct of this call, all hooks are
// reset, and this is why we don't need to worry about these addHook calls
// redundantly stacking up.
client.addHook('startSession', function(done) {
grabber._connect(done);
});

// deleteSession's hook runs after the session is already torn down, so we
// can't actually do anything at this point.

return grabber;
}

exports.setup = setup;

0 comments on commit b717c8e

Please sign in to comment.