<commit_before>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var NOTIFICATION_ALARM_NAME = 'NOTIFICATION_ALARM1';
var numIds = 0;

function createNotification(options, callback) {
  var notificationId = 'id' + numIds;
  numIds++;
  if (!('iconUrl' in options)) {
    options.iconUrl = 'assets/inbox-64x64.png';
  }
  options.message = options.message || 'notificationId = ' + notificationId;
  chrome.notifications.create(notificationId, options, function(notificationId) {
    if (callback) callback(notificationId);
  });
}

console.log('Notifications test registered for alarms');

chrome.alarms.onAlarm.addListener(function(alarm) {
  if (alarm.name === NOTIFICATION_ALARM_NAME) {
    console.log("Received alarm: " + alarm.name);
    createNotification({
      type:'basic',
      title:'Alarm notification',
    });
  }
});

chrome.notifications.onClosed.addListener(function(notificationId, byUser) {
  logger('onClosed fired. notificationId = ' + notificationId + ', byUser = ' + byUser);
});

chrome.notifications.onClicked.addListener(function(notificationId) {
  logger('onClicked fired. notificationId = ' + notificationId);
  chrome.notifications.clear(notificationId, function(wasCleared) {});
  logger('Showing window.');
  var wnd = chrome.app.window.getAll()[0];
  if (wnd) {
    wnd.show();
  } else {
    logger('Creating Ui Window & showing');
    createUiWindow(function(appWnd) {
      // Todo: figure out how to navigate to notifications manual test page.
    });
  }
});

chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex) {
  logger('onButtonClicked fired. notificationId = ' + notificationId + ', buttonIndex = ' + buttonIndex);
});


exports.defineManualTests = function(rootEl, addButton) {
  addButton('Basic Notification', function() {
    createNotification({
      type:'basic',
      title:'Basic Notification',
    });
  });
<commit_msg>Run tests script at startup - Wrap logic to run at startup in a handler for device ready - Do not use custom logger (it isn't yet available at startup)<commit_after>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var NOTIFICATION_ALARM_NAME = 'NOTIFICATION_ALARM1';
var numIds = 0;

function createNotification(options, callback) {
  var notificationId = 'id' + numIds;
  numIds++;
  if (!('iconUrl' in options)) {
    options.iconUrl = 'assets/inbox-64x64.png';
  }
  options.message = options.message || 'notificationId = ' + notificationId;
  chrome.notifications.create(notificationId, options, function(notificationId) {
    if (callback) callback(notificationId);
  });
}

// As this file is run at app startup, wait for deviceready before
// using any plugin APIs
document.addEventListener("deviceready", function() {

  console.log('Notifications test registered for alarms');

  chrome.alarms.onAlarm.addListener(function(alarm) {
    if (alarm.name === NOTIFICATION_ALARM_NAME) {
      console.log("Received alarm: " + alarm.name);
      createNotification({
        type:'basic',
        title:'Alarm notification',
      });
    }
  });

  chrome.notifications.onClosed.addListener(function(notificationId, byUser) {
    console.log('onClosed fired. notificationId = ' + notificationId + ', byUser = ' + byUser);
  });

  chrome.notifications.onClicked.addListener(function(notificationId) {
    console.log('onClicked fired. notificationId = ' + notificationId);
    chrome.notifications.clear(notificationId, function(wasCleared) {});
    console.log('Showing window.');
    var wnd = chrome.app.window.getAll()[0];
    if (wnd) {
      wnd.show();
    } else {
      console.log('Creating Ui Window & showing');
      createUiWindow(function(appWnd) {
        // Todo: figure out how to navigate to notifications manual test page.
      });
    }
  });

  chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex) {
    console.log('onButtonClicked fired. notificationId = ' + notificationId + ', buttonIndex = ' + buttonIndex);
  });
});

exports.defineManualTests = function(rootEl, addButton) {
  addButton('Basic Notification', function() {
    createNotification({
      type:'basic',
      title:'Basic Notification',
    });
  });

{'fraction_non_alphanumeric': 0.12852311161217586, 'fraction_numerical': 0.00496054114994363, 'mean_word_length': 4.1342592592592595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6109296', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1276, 'n_words': 311}