summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/activity_log/google_cs.js2
-rw-r--r--chrome/test/data/extensions/activity_log/manifest.json8
-rw-r--r--chrome/test/data/extensions/activity_log/options.js615
-rw-r--r--chrome/test/data/extensions/api_test/activity_log_private/README56
-rw-r--r--chrome/test/data/extensions/api_test/activity_log_private/friend/google_cs.js5
-rw-r--r--chrome/test/data/extensions/api_test/activity_log_private/friend/manifest.json14
-rw-r--r--chrome/test/data/extensions/api_test/activity_log_private/friend/options.html (renamed from chrome/test/data/extensions/activity_log/options.html)2
-rw-r--r--chrome/test/data/extensions/api_test/activity_log_private/friend/reply.js604
-rw-r--r--chrome/test/data/extensions/api_test/activity_log_private/test/test.js356
9 files changed, 1021 insertions, 641 deletions
diff --git a/chrome/test/data/extensions/activity_log/google_cs.js b/chrome/test/data/extensions/activity_log/google_cs.js
index 7c1bdbb..7c7a258 100644
--- a/chrome/test/data/extensions/activity_log/google_cs.js
+++ b/chrome/test/data/extensions/activity_log/google_cs.js
@@ -2,4 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-console.log("g o o g l e");
+console.log('g o o g l e');
diff --git a/chrome/test/data/extensions/activity_log/manifest.json b/chrome/test/data/extensions/activity_log/manifest.json
index c5fe350..35a2657 100644
--- a/chrome/test/data/extensions/activity_log/manifest.json
+++ b/chrome/test/data/extensions/activity_log/manifest.json
@@ -1,12 +1,8 @@
{
- "name": "Activity Log Test Extension",
+ "name": "Prerender Test Extension",
"version": "0.1",
- "description": "Testing the Activity Log",
- "permissions": [ "cookies", "tabs", "webRequest", "webRequestBlocking",
- "http://*/*", "https://*/*", "storage" ],
- "options_page": "options.html",
+ "description": "Testing the prerender",
"manifest_version": 2,
- "omnibox": { "keyword" : "hello" },
"content_scripts": [
{
"matches": ["http://www.google.com.bo/*"],
diff --git a/chrome/test/data/extensions/activity_log/options.js b/chrome/test/data/extensions/activity_log/options.js
deleted file mode 100644
index 8afe8db..0000000
--- a/chrome/test/data/extensions/activity_log/options.js
+++ /dev/null
@@ -1,615 +0,0 @@
-// 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.
-
-/**
- * Every test needs:
- * - a button in options.html
- * - a function that runs the test & calls setCompletedChrome or
- setCompetedDOM when done
- * - a listener registered in setupEvents
-**/
-
-// UTILITY METHODS
-////////////////////////////////////////////////////////////////////////////////
-
-var robot = false;
-var completed = 0;
-var testButtons = [];
-var defaultUrl = 'http://www.google.com';
-// Lets us know that we're running in the test suite and should notify the
-// browser about the test status.
-function setRunningAsRobot() {
- robot = true;
-}
-
-// set the testButtons array to the current set of test cases.
-function setTestButtons(buttonsArray) {
- testButtons = buttonsArray;
-}
-
-// Clicks the first button from the array 'testButtons'. If robot is true
-// then the next test button automatically gets clicked on once
-// 'setCompleted' gets called. ('setCompleted' gets invoked
-// when a test completes successfully.)
-function beginClickingTestButtons() {
- if (testButtons.length > 0) {
- completed = 0;
- testButtons[0].click();
- } else {
- console.log("testButtons array is empty, somehting is wrong");
- }
-}
-
-// Convenience.
-function $(o) {
- return document.getElementById(o);
-}
-
-// Track how many tests have finished. If there are pending tests,
-// then automatically trigger them by clicking the next test button
-// from the array 'testButtons'.
-function setCompleted(str) {
- completed++;
- $('status').innerText = "Completed " + str;
- console.log("[SUCCESS] " + str);
- if (robot) {
- if (completed === testButtons.length) {
- // Done with clicking all buttons in the array 'testButtons'.
- chrome.test.notifyPass();
- } else {
- // Click the next button from the array 'testButtons'.
- testButtons[completed].click();
- }
- }
-}
-
-// CHROME API TEST METHODS -- PUT YOUR TESTS BELOW HERE
-////////////////////////////////////////////////////////////////////////////////
-
-// Makes an API call.
-function makeApiCall() {
- chrome.cookies.set({
- 'url': 'https://www.cnn.com',
- 'name': 'activity_log_test_cookie',
- 'value': 'abcdefg'
- });
- setCompleted('makeApiCall');
-}
-
-// Makes an API call that has a custom binding.
-function makeSpecialApiCalls() {
- var url = chrome.extension.getURL("image/cat.jpg");
- var noparam = chrome.extension.getViews();
- setCompleted('makeSpecialApiCalls');
-}
-
-// Checks that we don't double-log calls that go through setHandleRequest
-// *and* the ExtensionFunction machinery.
-function checkNoDoubleLogging() {
- chrome.omnibox.setDefaultSuggestion({description: 'hello world'});
- setCompleted('checkNoDoubleLogging');
-}
-
-// Check whether we log calls to chrome.app.*;
-function checkAppCalls() {
- var callback = function () {};
- chrome.app.getDetails();
- var b = chrome.app.isInstalled;
- var c = chrome.app.installState(callback);
- setCompleted('checkAppCalls');
-}
-
-// Makes an API call that the extension doesn't have permission for.
-// Don't add the management permission or this test won't test the code path.
-function makeBlockedApiCall() {
- try {
- var all_extensions = chrome.management.getAll();
- } catch(err) { }
- setCompleted('makeBlockedApiCall');
-}
-
-// Injects a content script.
-function injectContentScript() {
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'file': 'google_cs.js'},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('injectContentScript');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Injects a blob of script into a page.
-function injectScriptBlob() {
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete"
- && tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': 'document.write("g o o g l e");'},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('injectScriptBlob');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Modifies the headers sent and received in an HTTP request using the
-// webRequest API.
-function doWebRequestModifications() {
- // Install a webRequest handler that will add an HTTP header to the outgoing
- // request for the main page.
- function doModifyHeaders(details) {
- var response = {};
-
- var headers = details.requestHeaders;
- if (headers === undefined) {
- headers = [];
- }
- headers.push({'name': 'X-Test-Activity-Log-Send',
- 'value': 'Present'});
- response['requestHeaders'] = headers;
-
- headers = details.responseHeaders;
- if (headers === undefined) {
- headers = [];
- }
- headers = headers.filter(
- function(x) {return x["name"] != "Cache-Control"});
- headers.push({'name': 'X-Test-Response-Header',
- 'value': 'Inserted'});
- headers.push({'name': 'Set-Cookie',
- 'value': 'ActivityLog=InsertedCookie'});
- response['responseHeaders'] = headers;
-
- return response;
- }
- chrome.webRequest.onBeforeSendHeaders.addListener(
- doModifyHeaders,
- {'urls': ['http://*/*'], 'types': ['main_frame']},
- ['blocking', 'requestHeaders']);
- chrome.webRequest.onHeadersReceived.addListener(
- doModifyHeaders,
- {'urls': ['http://*/*'], 'types': ['main_frame']},
- ['blocking', 'responseHeaders']);
-
- // Open a tab, then close it when it has finished loading--this should give
- // the webRequest handler a chance to run.
- chrome.tabs.onUpdated.addListener(
- function closeTab(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders);
- chrome.tabs.onUpdated.removeListener(closeTab);
- chrome.tabs.remove(tabId);
- setCompleted('doWebRequestModifications');
- }
- }
- );
- window.open(defaultUrl);
-}
-
-function getSetObjectProperties() {
- chrome.tabs.onUpdated.addListener(
- function getTabProperties(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete"
- && tab.url.match(/google\.com/g)) {
- console.log(tab.id + " " + tab.index + " " + tab.url);
- tab.index = 3333333333333333333;
- chrome.tabs.remove(tabId);
- chrome.tabs.onUpdated.removeListener(getTabProperties);
- setCompleted('getSetObjectProperties');
- }
- }
- );
- window.open(defaultUrl);
-}
-
-function callObjectMethod() {
- var storageArea = chrome.storage.sync;
- storageArea.clear();
- setCompleted('callObjectMethod()');
-}
-
-function sendMessageToCS() {
- chrome.tabs.onUpdated.addListener(
- function messageCS(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete"
- && tab.url.match(/google\.com/g)) {
- chrome.tabs.sendMessage(tabId, "hellooooo!");
- chrome.tabs.remove(tabId);
- chrome.tabs.onUpdated.removeListener(messageCS);
- setCompleted('sendMessageToCS');
- }
- }
- );
- window.open(defaultUrl);
-}
-
-function sendMessageToSelf() {
- chrome.runtime.sendMessage("hello hello");
- setCompleted('sendMessageToSelf');
-}
-
-function sendMessageToOther() {
- chrome.runtime.sendMessage("ocacnieaapoflmkebkeaidpgfngocapl",
- "knock knock",
- function response() {
- console.log("who's there?");
- });
- setCompleted('sendMessageToOther');
-}
-
-function connectToOther() {
- chrome.runtime.connect("ocacnieaapoflmkebkeaidpgfngocapl");
- setCompleted('connectToOther');
-}
-
-function tabIdTranslation() {
- var tabIds = [-1, -1];
-
- // Test the case of a single int
- chrome.tabs.onUpdated.addListener(
- function testSingleInt(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.executeScript(
- tab.id,
- {'file': 'google_cs.js'},
- function() {
- chrome.tabs.onUpdated.removeListener(testSingleInt);
- tabIds[0] = tabId;
- window.open('http://www.google.be');
- });
- }
- }
- );
-
- // Test the case of arrays
- chrome.tabs.onUpdated.addListener(
- function testArray(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" && tab.url.match(/google\.be/g)) {
- chrome.tabs.move(tabId, {"index": -1});
- tabIds[1] = tabId;
- chrome.tabs.remove(tabIds);
- chrome.tabs.onUpdated.removeListener(testArray);
- setCompleted('tabIdTranslation');
- }
- }
- );
-
- window.open(defaultUrl);
-}
-
-// DOM API TEST METHODS -- PUT YOUR TESTS BELOW HERE
-////////////////////////////////////////////////////////////////////////////////
-
-// Does an XHR from this [privileged] context.
-function doBackgroundXHR() {
- var request = new XMLHttpRequest();
- request.open('POST', defaultUrl, false);
- request.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
- try {
- request.send();
- } catch(err) {
- // doesn't matter if it works or not; should be recorded either way
- }
- setCompleted('doBackgroundXHR');
-}
-
-// Does an XHR from inside a content script.
-function doContentScriptXHR() {
- var code = 'var request = new XMLHttpRequest(); ' +
- 'request.open("POST", "http://www.cnn.com", false); ' +
- 'request.setRequestHeader("Content-type", ' +
- ' "text/plain;charset=UTF-8"); ' +
- 'request.send(); ' +
- 'document.write("sent an XHR");';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doContentScriptXHR');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Accesses the Location object from inside a content script.
-function doLocationAccess() {
- var code = 'window.location = "http://www.google.com/#foo"; ' +
- 'document.location = "http://www.google.com/#bar"; ' +
- 'var loc = window.location; ' +
- 'loc.assign("http://www.google.com/#foo"); ' +
- 'loc.replace("http://www.google.com/#bar");';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doLoctionAccess');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Mutates the DOM tree from inside a content script.
-function doDOMMutation1() {
- var code = 'var d1 = document.createElement("div"); ' +
- 'var d2 = document.createElement("div"); ' +
- 'document.body.appendChild(d1); ' +
- 'document.body.insertBefore(d2, d1); ' +
- 'document.body.replaceChild(d1, d2);';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doDOMMutation1');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-function doDOMMutation2() {
- var code = 'document.write("Hello using document.write"); ' +
- 'document.writeln("Hello using document.writeln"); ' +
- 'document.body.innerHTML = "Hello using innerHTML";';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doDOMMutation2');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Accesses the HTML5 Navigator API from inside a content script.
-function doNavigatorAPIAccess() {
- var code = 'var geo = navigator.geolocation; ' +
- 'var successCallback = function(x) { }; ' +
- 'var errorCallback = function(x) { }; ' +
- 'geo.getCurrentPosition(successCallback, errorCallback); ';
- 'var id = geo.watchPosition(successCallback, errorCallback);';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doNavigatorAPIAccess');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Accesses the HTML5 WebStorage API from inside a content script.
-function doWebStorageAPIAccess1() {
- var code = 'var store = window.sessionStorage; ' +
- 'store.setItem("foo", 42); ' +
- 'var val = store.getItem("foo"); ' +
- 'store.removeItem("foo"); ' +
- 'store.clear();';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doWebStorageAPIAccess1');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-function doWebStorageAPIAccess2() {
- var code = 'var store = window.localStorage; ' +
- 'store.setItem("foo", 42); ' +
- 'var val = store.getItem("foo"); ' +
- 'store.removeItem("foo"); ' +
- 'store.clear();';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doWebStorageAPIAccess2');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Accesses the HTML5 Notification API from inside a content script.
-function doNotificationAPIAccess() {
- var code = 'try {' +
- ' webkitNotifications.createNotification("myIcon.png", ' +
- ' "myTitle", ' +
- ' "myContent");' +
- '} catch (e) {}';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doNotifcationAPIAccess');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Accesses the HTML5 ApplicationCache API from inside a content script.
-function doApplicationCacheAPIAccess() {
- var code = 'var appCache = window.applicationCache;';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doApplictionCacheAPIAccess');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Accesses the HTML5 WebDatabase API from inside a content script.
-function doWebDatabaseAPIAccess() {
- var code = 'var db = openDatabase("testdb", "1.0", "test database", ' +
- ' 1024 * 1024);';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doWebDatabaseAPIAccess');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// Accesses the HTML5 Canvas API from inside a content script.
-function doCanvasAPIAccess() {
- var code = 'var test_canvas = document.createElement("canvas"); ' +
- 'var test_context = test_canvas.getContext("2d");';
- chrome.tabs.onUpdated.addListener(
- function callback(tabId, changeInfo, tab) {
- if (changeInfo['status'] === "complete" &&
- tab.url.match(/google\.com/g)) {
- chrome.tabs.onUpdated.removeListener(callback);
- chrome.tabs.executeScript(
- tab.id,
- {'code': code},
- function () {
- chrome.tabs.remove(tabId);
- setCompleted('doCanvasAPIAccess');
- });
- }
- }
- );
- window.open(defaultUrl);
-}
-
-// REGISTER YOUR TESTS HERE
-// Attach the tests to buttons.
-function setupEvents() {
- $('api_call').addEventListener('click', makeApiCall);
- $('special_call').addEventListener('click', makeSpecialApiCalls);
- $('blocked_call').addEventListener('click', makeBlockedApiCall);
- $('inject_cs').addEventListener('click', injectContentScript);
- $('inject_blob').addEventListener('click', injectScriptBlob);
- $('webrequest').addEventListener('click', doWebRequestModifications);
- $('double').addEventListener('click', checkNoDoubleLogging);
- $('app_bindings').addEventListener('click', checkAppCalls);
- $('object_properties').addEventListener('click', getSetObjectProperties);
- $('object_methods').addEventListener('click', callObjectMethod);
- $('message_cs').addEventListener('click', sendMessageToCS);
- $('message_self').addEventListener('click', sendMessageToSelf);
- $('message_other').addEventListener('click', sendMessageToOther);
- $('connect_other').addEventListener('click', connectToOther);
- $('tab_ids').addEventListener('click', tabIdTranslation);
- $('background_xhr').addEventListener('click', doBackgroundXHR);
- $('cs_xhr').addEventListener('click', doContentScriptXHR);
- $('location_access').addEventListener('click', doLocationAccess);
- $('dom_mutation1').addEventListener('click', doDOMMutation1);
- $('dom_mutation2').addEventListener('click', doDOMMutation2);
- $('navigator_access').addEventListener('click', doNavigatorAPIAccess);
- $('web_storage_access1').addEventListener('click',
- doWebStorageAPIAccess1);
- $('web_storage_access2').addEventListener('click',
- doWebStorageAPIAccess2);
- $('notification_access').addEventListener('click', doNotificationAPIAccess);
- $('application_cache_access').addEventListener(
- 'click',
- doApplicationCacheAPIAccess);
- $('web_database_access').addEventListener('click', doWebDatabaseAPIAccess);
- $('canvas_access').addEventListener('click', doCanvasAPIAccess);
- completed = 0;
-}
-
-document.addEventListener('DOMContentLoaded', setupEvents);
-
diff --git a/chrome/test/data/extensions/api_test/activity_log_private/README b/chrome/test/data/extensions/api_test/activity_log_private/README
new file mode 100644
index 0000000..a3bf77e
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/activity_log_private/README
@@ -0,0 +1,56 @@
+This directory contains tests for chrome extension activity logging.
+
+The tests use two chrome extensions:
+ -test : sends messages to the friend extension and listens for activity
+ logged by the friend extension. Checks the activity has been logged
+ correctly.
+ -friend: recieves messages from the extension and runs a function based on
+ the contents of the message.
+
+
+Adding a new test:
+
+ In friend/reply.js:
+ (1) Add a function to call the chrome api calls you want to test.
+ NOTE: The function should clean up any changes it made (e.g. listeners
+ it added) before finishing. If they are not cleaned up then unexpected
+ behavior can happen in test cases that run after this function.
+ (2) Add the name of the new function to the function map (fnMap).
+
+ In friend/options.html:
+ (1) Add a button to allow the new function to be called in manual mode.
+
+ You may need also to modify the manifest.json and other files in the
+ friend extension directory.
+
+ In test/test.js:
+ (1) Add the test to the testcase array.
+
+ You will need to define the function that sends a message to the
+ friend extension and define the expected activity logging. Example:
+
+ testCases.push({
+ func: function triggerMyFunctionCall() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'my_function_call_id',
+ function response() { });
+ },
+ expected_activity: ['api.call1', 'api.call2', 'api.call3']
+ });
+
+ where 'my_function_call_id' is the key you added to the fn_map in
+ reply.js.
+
+
+Running the tests:
+
+ > out/Debug/browser_tests --gtest_filter=ActivityLogApiTest.TriggerEvent
+
+
+Running in manual mode:
+
+ (1) Start chrome with out/Debug/chrome
+ (2) Navigate to chrome://extensions
+ (3) Install the friend and test extensions from your chrome src folder
+ (4) Click on the "options" link under the friend extension
+ (5) You should see the options page the buttons to run the functions manually
diff --git a/chrome/test/data/extensions/api_test/activity_log_private/friend/google_cs.js b/chrome/test/data/extensions/api_test/activity_log_private/friend/google_cs.js
new file mode 100644
index 0000000..b8e3804
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/activity_log_private/friend/google_cs.js
@@ -0,0 +1,5 @@
+// Copyright 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.
+
+console.log('g o o g l e');
diff --git a/chrome/test/data/extensions/api_test/activity_log_private/friend/manifest.json b/chrome/test/data/extensions/api_test/activity_log_private/friend/manifest.json
index a14619f..fa11e51 100644
--- a/chrome/test/data/extensions/api_test/activity_log_private/friend/manifest.json
+++ b/chrome/test/data/extensions/api_test/activity_log_private/friend/manifest.json
@@ -6,5 +6,15 @@
"background": {
"scripts": ["reply.js"]
},
- "permissions": ["cookies", "https://www.cnn.com/"]
-} \ No newline at end of file
+ "omnibox": { "keyword" : "hello" },
+ "options_page": "options.html",
+ "permissions": ["cookies", "storage", "tabs", "webRequest",
+ "webRequestBlocking", "http://*/*", "https://*/*"],
+ "content_scripts": [
+ {
+ "matches": ["http://www.google.com.bo/*"],
+ "js": ["google_cs.js"],
+ "run_at": "document_start"
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/activity_log/options.html b/chrome/test/data/extensions/api_test/activity_log_private/friend/options.html
index 6c7453f..d7afb4b 100644
--- a/chrome/test/data/extensions/activity_log/options.html
+++ b/chrome/test/data/extensions/api_test/activity_log_private/friend/options.html
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <script src="options.js"></script>
+ <script src="reply.js"></script>
</head>
<body>
<h1>Chrome API calls</h1>
diff --git a/chrome/test/data/extensions/api_test/activity_log_private/friend/reply.js b/chrome/test/data/extensions/api_test/activity_log_private/friend/reply.js
index 9249a1f..8490da9 100644
--- a/chrome/test/data/extensions/api_test/activity_log_private/friend/reply.js
+++ b/chrome/test/data/extensions/api_test/activity_log_private/friend/reply.js
@@ -2,8 +2,604 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-chrome.runtime.onMessageExternal.addListener(
- function(message, sender, response) {
- console.log("received");
+var defaultUrl = 'http://www.google.com';
+
+// CHROME API TEST METHODS -- PUT YOUR TESTS BELOW HERE
+////////////////////////////////////////////////////////////////////////////////
+
+// Makes an API call.
+function makeApiCall() {
+ chrome.cookies.set({
+ 'url': 'https://www.cnn.com',
+ 'name': 'activity_log_test_cookie',
+ 'value': 'abcdefg'
+ });
+ setCompleted('makeApiCall');
+}
+
+// Makes an API call that has a custom binding.
+function makeSpecialApiCalls() {
+ var url = chrome.extension.getURL('image/cat.jpg');
+ var noparam = chrome.extension.getViews();
+ setCompleted('makeSpecialApiCalls');
+}
+
+// Checks that we don't double-log calls that go through setHandleRequest
+// *and* the ExtensionFunction machinery.
+function checkNoDoubleLogging() {
+ chrome.omnibox.setDefaultSuggestion({description: 'hello world'});
+ setCompleted('checkNoDoubleLogging');
+}
+
+// Check whether we log calls to chrome.app.*;
+function checkAppCalls() {
+ var callback = function() {};
+ chrome.app.getDetails();
+ var b = chrome.app.isInstalled;
+ var c = chrome.app.installState(callback);
+ setCompleted('checkAppCalls');
+}
+
+// Makes an API call that the extension doesn't have permission for.
+// Don't add the management permission or this test won't test the code path.
+function makeBlockedApiCall() {
+ try {
+ var allExtensions = chrome.management.getAll();
+ } catch (err) { }
+ setCompleted('makeBlockedApiCall');
+}
+
+// Injects a content script.
+function injectContentScript() {
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'file': 'google_cs.js'},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('injectContentScript');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Injects a blob of script into a page.
+function injectScriptBlob() {
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': 'document.write("g o o g l e");'},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('injectScriptBlob');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Modifies the headers sent and received in an HTTP request using the
+// webRequest API.
+function doWebRequestModifications() {
+ // Install a webRequest handler that will add an HTTP header to the outgoing
+ // request for the main page.
+ function doModifyHeaders(details) {
+ var response = {};
+
+ var headers = details.requestHeaders;
+ if (headers === undefined) {
+ headers = [];
+ }
+ headers.push({'name': 'X-Test-Activity-Log-Send',
+ 'value': 'Present'});
+ response['requestHeaders'] = headers;
+
+ headers = details.responseHeaders;
+ if (headers === undefined) {
+ headers = [];
+ }
+ headers = headers.filter(
+ function(x) {return x['name'] != 'Cache-Control'});
+ headers.push({'name': 'X-Test-Response-Header',
+ 'value': 'Inserted'});
+ headers.push({'name': 'Set-Cookie',
+ 'value': 'ActivityLog=InsertedCookie'});
+ response['responseHeaders'] = headers;
+
+ return response;
+ }
+ chrome.webRequest.onBeforeSendHeaders.addListener(
+ doModifyHeaders,
+ {'urls': ['http://*/*'], 'types': ['main_frame']},
+ ['blocking', 'requestHeaders']);
+ chrome.webRequest.onHeadersReceived.addListener(
+ doModifyHeaders,
+ {'urls': ['http://*/*'], 'types': ['main_frame']},
+ ['blocking', 'responseHeaders']);
+
+ // Open a tab, then close it when it has finished loading--this should give
+ // the webRequest handler a chance to run.
+ chrome.tabs.onUpdated.addListener(
+ function closeTab(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.webRequest.onBeforeSendHeaders.removeListener(doModifyHeaders);
+ // TODO(karenlees): you added this line in debugging, make sure it is
+ // really needed.
+ chrome.webRequest.onHeadersReceived.removeListener(doModifyHeaders);
+ chrome.tabs.onUpdated.removeListener(closeTab);
+ chrome.tabs.remove(tabId);
+ setCompleted('doWebRequestModifications');
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+function getSetObjectProperties() {
+ chrome.tabs.onUpdated.addListener(
+ function getTabProperties(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ console.log(tab.id + ' ' + tab.index + ' ' + tab.url);
+ tab.index = 3333333333333333333;
+ chrome.tabs.onUpdated.removeListener(getTabProperties);
+ chrome.tabs.remove(tabId);
+ setCompleted('getSetObjectProperties');
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+function callObjectMethod() {
+ var storageArea = chrome.storage.sync;
+ storageArea.clear();
+ setCompleted('callObjectMethod()');
+}
+
+function sendMessageToCS() {
+ chrome.tabs.onUpdated.addListener(
+ function messageCS(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.sendMessage(tabId, 'hellooooo!');
+ chrome.tabs.onUpdated.removeListener(messageCS);
+ chrome.tabs.remove(tabId);
+ setCompleted('sendMessageToCS');
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+function sendMessageToSelf() {
+ try {
+ chrome.runtime.sendMessage('hello hello');
+ setCompleted('sendMessageToSelf');
+ } catch (err) {
+ setError(err + ' in function: sendMessageToSelf');
+ }
+}
+
+function sendMessageToOther() {
+ try {
+ chrome.runtime.sendMessage('ocacnieaapoflmkebkeaidpgfngocapl',
+ 'knock knock',
+ function response() {
+ console.log("who's there?");
+ });
+ setCompleted('sendMessageToOther');
+ } catch (err) {
+ setError(err + ' in function: sendMessageToOther');
+ }
+}
+
+function connectToOther() {
+ try {
+ chrome.runtime.connect('ocacnieaapoflmkebkeaidpgfngocapl');
+ setCompleted('connectToOther');
+ } catch (err) {
+ setError(err + ' in function:connectToOther');
+ }
+}
+
+function tabIdTranslation() {
+ var tabIds = [-1, -1];
+
+ // Test the case of a single int
+ chrome.tabs.onUpdated.addListener(
+ function testSingleInt(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.executeScript(
+ //tab.id,
+ {'file': 'google_cs.js'},
+ function() {
+ chrome.tabs.onUpdated.removeListener(testSingleInt);
+ tabIds[0] = tabId;
+ window.open('http://www.google.be');
+ });
+ }
+ }
+ );
+
+ // Test the case of arrays
+ chrome.tabs.onUpdated.addListener(
+ function testArray(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' && tab.url.match(/google\.be/g)) {
+ //chrome.tabs.move(tabId, {'index': -1});
+ tabIds[1] = tabId;
+ chrome.tabs.onUpdated.removeListener(testArray);
+ chrome.tabs.remove(tabIds);
+ setCompleted('tabIdTranslation');
+ }
+ }
+ );
+
+ window.open(defaultUrl);
+}
+
+// DOM API TEST METHODS -- PUT YOUR TESTS BELOW HERE
+////////////////////////////////////////////////////////////////////////////////
+
+// Does an XHR from this [privileged] context.
+function doBackgroundXHR() {
+ var request = new XMLHttpRequest();
+ request.open('POST', defaultUrl, false);
+ request.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
+ try {
+ request.send();
+ } catch (err) {
+ // doesn't matter if it works or not; should be recorded either way
+ }
+ setCompleted('doBackgroundXHR');
+}
+
+// Does an XHR from inside a content script.
+function doContentScriptXHR() {
+ var code = 'var request = new XMLHttpRequest(); ' +
+ 'request.open("POST", "http://www.cnn.com", false); ' +
+ 'request.setRequestHeader("Content-type", ' +
+ ' "text/plain;charset=UTF-8"); ' +
+ 'request.send(); ' +
+ 'document.write("sent an XHR");';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doContentScriptXHR');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Accesses the Location object from inside a content script.
+function doLocationAccess() {
+ var code = 'window.location = "http://www.google.com/#foo"; ' +
+ 'document.location = "http://www.google.com/#bar"; ' +
+ 'var loc = window.location; ' +
+ 'loc.assign("http://www.google.com/#fo"); ' +
+ 'loc.replace("http://www.google.com/#bar");';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doLoctionAccess');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Mutates the DOM tree from inside a content script.
+function doDOMMutation1() {
+ var code = 'var d1 = document.createElement("div"); ' +
+ 'var d2 = document.createElement("div"); ' +
+ 'document.body.appendChild(d1); ' +
+ 'document.body.insertBefore(d2, d1); ' +
+ 'document.body.replaceChild(d1, d2);';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doDOMMutation1');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+function doDOMMutation2() {
+ var code = 'document.write("Hello using document.write"); ' +
+ 'document.writeln("Hello using document.writeln"); ' +
+ 'document.body.innerHTML = "Hello using innerHTML";';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doDOMMutation2');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Accesses the HTML5 Navigator API from inside a content script.
+function doNavigatorAPIAccess() {
+ var code = 'var geo = navigator.geolocation; ' +
+ 'var successCallback = function(x) { }; ' +
+ 'var errorCallback = function(x) { }; ' +
+ 'geo.getCurrentPosition(successCallback, errorCallback); ';
+ 'var id = geo.watchPosition(successCallback, errorCallback);';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doNavigatorAPIAccess');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Accesses the HTML5 WebStorage API from inside a content script.
+function doWebStorageAPIAccess1() {
+ var code = 'var store = window.sessionStorage; ' +
+ 'store.setItem("foo", 42); ' +
+ 'var val = store.getItem("foo"); ' +
+ 'store.removeItem("foo"); ' +
+ 'store.clear();';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doWebStorageAPIAccess1');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+function doWebStorageAPIAccess2() {
+ var code = 'var store = window.sessionStorage; ' +
+ 'store.setItem("foo", 42); ' +
+ 'var val = store.getItem("foo"); ' +
+ 'store.removeItem("foo"); ' +
+ 'store.clear();';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doWebStorageAPIAccess2');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Accesses the HTML5 Notification API from inside a content script.
+function doNotificationAPIAccess() {
+ var code = 'try {' +
+ ' webkitNotifications.createNotification("myIcon.png", ' +
+ ' "myTitle", ' +
+ ' "myContent");' +
+ '} catch (e) {}';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doNotifcationAPIAccess');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Accesses the HTML5 ApplicationCache API from inside a content script.
+function doApplicationCacheAPIAccess() {
+ var code = 'var appCache = window.applicationCache;';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doApplictionCacheAPIAccess');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Accesses the HTML5 WebDatabase API from inside a content script.
+function doWebDatabaseAPIAccess() {
+ var code = 'var db = openDatabase("testdb", "1.0", "test database", ' +
+ ' 1024 * 1024);';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doWebDatabaseAPIAccess');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// Accesses the HTML5 Canvas API from inside a content script.
+function doCanvasAPIAccess() {
+ var code = 'var testCanvas = document.createElement("canvas"); ' +
+ 'var testContext = testCanvas.getContext("2d");';
+ chrome.tabs.onUpdated.addListener(
+ function callback(tabId, changeInfo, tab) {
+ if (changeInfo['status'] === 'complete' &&
+ tab.url.match(/google\.com/g)) {
+ chrome.tabs.onUpdated.removeListener(callback);
+ chrome.tabs.executeScript(
+ tab.id,
+ {'code': code},
+ function() {
+ chrome.tabs.remove(tabId);
+ setCompleted('doCanvasAPIAccess');
+ });
+ }
+ }
+ );
+ window.open(defaultUrl);
+}
+
+// ADD TESTS CASES TO THE MAP HERE.
+var fnMap = {};
+fnMap['api_call'] = makeApiCall;
+fnMap['special_call'] = makeSpecialApiCalls;
+fnMap['blocked_call'] = makeBlockedApiCall;
+fnMap['inject_cs'] = injectContentScript;
+fnMap['inject_blob'] = injectScriptBlob;
+fnMap['webrequest'] = doWebRequestModifications;
+fnMap['double'] = checkNoDoubleLogging;
+fnMap['app_bindings'] = checkAppCalls;
+fnMap['object_properties'] = getSetObjectProperties;
+fnMap['object_methods'] = callObjectMethod;
+fnMap['message_cs'] = sendMessageToCS;
+fnMap['message_self'] = sendMessageToSelf;
+fnMap['message_other'] = sendMessageToOther;
+fnMap['connect_other'] = connectToOther;
+fnMap['tab_ids'] = tabIdTranslation;
+fnMap['background_xhr'] = doBackgroundXHR;
+fnMap['cs_xhr'] = doContentScriptXHR;
+fnMap['location_access'] = doLocationAccess;
+fnMap['dom_mutation1'] = doDOMMutation1;
+fnMap['dom_mutation2'] = doDOMMutation2;
+fnMap['navigator_access'] = doNavigatorAPIAccess;
+fnMap['web_storage_access1'] = doWebStorageAPIAccess1;
+fnMap['web_storage_access2'] = doWebStorageAPIAccess2;
+fnMap['notification_access'] = doNotificationAPIAccess;
+fnMap['application_cache_access'] = doApplicationCacheAPIAccess;
+fnMap['web_database_access'] = doWebDatabaseAPIAccess;
+fnMap['canvas_access'] = doCanvasAPIAccess;
+
+// Setup function mapping for the automated tests.
+try {
+ chrome.runtime.onMessageExternal.addListener(
+ function(message, sender, response) {
+ if (fnMap.hasOwnProperty(message)) {
+ fnMap[message]();
+ } else {
+ console.log('UNKNOWN METHOD: ' + message);
+ }
+ }
+ );
+} catch (err) {
+ console.log('Error while adding listeners: ' + err);
+}
+
+// Convenience functions for the manual run mode.
+function $(o) {
+ return document.getElementById(o);
+}
+
+var completed = 0;
+function setCompleted(str) {
+ completed++;
+ if ($('status') != null) {
+ $('status').innerText = 'Completed ' + str;
+ }
+ console.log('[SUCCESS] ' + str);
+}
+
+function setError(str) {
+ $('status').innerText = 'Error: ' + str;
+}
+
+// Set up the event listeners for use in manual run mode.
+function setupEvents() {
+ for (var key in fnMap) {
+ if (fnMap.hasOwnProperty(key) && key != '' && $(key) != null) {
+ $(key).addEventListener('click', fnMap[key]);
}
-);
+ }
+ setCompleted('setup events');
+ completed = 0;
+}
+document.addEventListener('DOMContentLoaded', setupEvents);
diff --git a/chrome/test/data/extensions/api_test/activity_log_private/test/test.js b/chrome/test/data/extensions/api_test/activity_log_private/test/test.js
index 3119f0c..5113e2b 100644
--- a/chrome/test/data/extensions/api_test/activity_log_private/test/test.js
+++ b/chrome/test/data/extensions/api_test/activity_log_private/test/test.js
@@ -2,21 +2,353 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// Setup the test cases.
+var testCases = [];
+testCases.push({
+ func: function triggerApiCall() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'api_call', function response() { });
+ },
+ expected_activity: ['cookies.set']
+});
+testCases.push({
+ func: function triggerSpecialCall() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'special_call', function response() { });
+ },
+ expected_activity: [
+ 'extension.getURL',
+ 'extension.getViews'
+ ]
+});
+testCases.push({
+ func: function triggerBlockedCall() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'blocked_call', function response() { });
+ },
+ expected_activity: []
+});
+testCases.push({
+ func: function triggerInjectCS() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'inject_cs', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerInsertBlob() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'inject_blob', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove']
+});
+testCases.push({
+ func: function triggerDouble() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'double', function response() {});
+ },
+ expected_activity: ['omnibox.setDefaultSuggestion']
+});
+testCases.push({
+ func: function triggerAppBindings() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'app_bindings', function response() { });
+ },
+ expected_activity: [
+ 'app.GetDetails',
+ 'app.GetIsInstalled',
+ 'app.getInstallState'
+ ]
+});
+testCases.push({
+ func: function triggerObjectProperties() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'object_properties', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.remove']
+});
+testCases.push({
+ func: function triggerObjectMethods() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'object_methods', function response() { });
+ },
+ expected_activity: ['storage.clear']
+});
+testCases.push({
+ func: function triggerMessageCS() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'message_cs', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.connect',
+ 'tabs.sendMessage',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerMessageSelf() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'message_self', function response() { });
+ },
+ expected_activity: [
+ 'runtime.connect',
+ 'runtime.sendMessage'
+ ]
+});
+testCases.push({
+ func: function triggerMessageOther() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'message_other', function response() { });
+ },
+ expected_activity: [
+ 'runtime.connect',
+ 'runtime.sendMessage'
+ ]
+});
+testCases.push({
+ func: function triggerConnectOther() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'connect_other', function response() { });
+ },
+ expected_activity: ['runtime.connect']
+});
+testCases.push({
+ func: function triggerLocationAccess() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'location_access', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerDomMutation1() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'dom_mutation1', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerDomMutation2() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'dom_mutation2', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerNavigatorAccess() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'navigator_access', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerWebStorageAccess1() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'web_storage_access1', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerWebStorageAccess2() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'web_storage_access2', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerNotificationAccess() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'notification_access', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerApplicationCacheAccess() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'application_cache_access',
+ function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerWebDatabaseAccess() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'web_database_access',
+ function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ func: function triggerCanvasAccess() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'canvas_access', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+testCases.push({
+ name: 'tab_ids',
+ func: function triggerTabIds() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'tab_ids', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.remove'
+ ]
+});
+
+testCases.push({
+ func: function triggerWebRequest() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'webrequest', function response() { });
+ },
+ expected_activity: [
+ 'webRequestInternal.addEventListener',
+ 'webRequestInternal.addEventListener',
+ 'webRequest.onBeforeSendHeaders/1',
+ 'webRequestInternal.eventHandled',
+ 'webRequest.onBeforeSendHeaders',
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.remove'
+ ]
+});
+
+testCases.push({
+ func: function triggerBackgroundXHR() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'cs_xhr', function response() { });
+ },
+ expected_activity: [
+ 'tabs.onUpdated',
+ 'tabs.onUpdated',
+ 'tabs.executeScript',
+ 'tabs.remove'
+ ]
+});
+
+testCases.push({
+ func: function triggerBackgroundXHR() {
+ chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
+ 'background_xhr', function response() { });
+ },
+ expected_activity: [
+ 'XMLHttpRequest.open',
+ 'XMLHttpRequest.setRequestHeader'
+ ]
+});
+
+// Listener to check the expected logging is done in the test cases.
+var testCaseIndx = 0;
+var callIndx = -1;
chrome.activityLogPrivate.onExtensionActivity.addListener(
function(activity) {
- var activityId = activity["extensionId"];
- chrome.test.assertEq("pknkgggnfecklokoggaggchhaebkajji", activityId);
- var apiCall = activity["chromeActivityDetail"]["apiCall"];
- chrome.test.assertEq("runtime.onMessageExternal", apiCall);
- chrome.test.succeed();
+ var activityId = activity['extensionId'];
+ chrome.test.assertEq('pknkgggnfecklokoggaggchhaebkajji', activityId);
+
+ // Get the api call info from either the chrome activity or dom activity.
+ var activityType = activity['activityType'];
+ var activityDetailName = 'chromeActivityDetail';
+ if (activity['activityType'] == 'dom') {
+ activityDetailName = 'domActivityDetail';
+ }
+
+ // Check the api call is the one we expected next.
+ var apiCall = activity[activityDetailName]['apiCall'];
+ expectedCall = 'runtime.onMessageExternal';
+ if (callIndx > -1) {
+ expectedCall = testCases[testCaseIndx].expected_activity[callIndx];
+ }
+ console.log('Logged:' + apiCall + 'Expected:' + expectedCall);
+ chrome.test.assertEq(expectedCall, apiCall);
+
+ // If all the expected calls have been logged for this test case then
+ // mark as suceeded and move to the next. Otherwise look for the next
+ // expected api call.
+ if (callIndx == testCases[testCaseIndx].expected_activity.length - 1) {
+ chrome.test.succeed();
+ callIndx = -1;
+ testCaseIndx++;
+ } else {
+ callIndx++;
+ }
}
);
-chrome.test.runTests([
- function triggerAnActivity() {
- chrome.runtime.sendMessage("pknkgggnfecklokoggaggchhaebkajji",
- "knock knock",
- function response() { });
+function getTestCasesToRun() {
+ var tests = [];
+ for (var i = 0; i < testCases.length; i++) {
+ if (testCases[i].func != undefined) {
+ tests.push(testCases[i].func);
+ }
}
-]);
-
+ return tests;
+}
+chrome.test.runTests(getTestCasesToRun());