Commit a7b1f0f9 authored by David Bertoni's avatar David Bertoni Committed by Commit Bot

[Extensions] Refactor some browserAction tests for Service Workers.

There are some unit tests that, with a little refactoring, will work
for both legacy background page-based extensions and service worker-
based ones. This CL is a start at refactoring and rewriting any tests
that are appropriate for both.

Bug: 1015136
Change-Id: I65baa3f8fa23ad1b25c067da216224b46925ea35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1922923
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720693}
parent fb2bcb29
......@@ -15,4 +15,4 @@ chrome.browserAction.onClicked.addListener(function(tab) {
chrome.test.notifyPass();
});
chrome.test.notifyPass();
chrome.test.sendMessage('ready');
......@@ -6,7 +6,7 @@
"scripts": ["background.js"]
},
"permissions": [
"http://*/*"
"http://*/*test_file.txt"
],
"browser_action": {
"default_title": "Make this page red",
......
<!--
* Copyright (c) 2011 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.
-->
<script src="update.js"></script>
// Copyright (c) 2011 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.
// Test that we can change various properties of the browser action.
// The C++ verifies.
chrome.browserAction.setTitle({title: "Modified"});
chrome.browserAction.setIcon({path: "icon2.png"});
chrome.browserAction.setBadgeText({text: "badge"});
chrome.browserAction.setBadgeBackgroundColor({color: [255,255,255,255]});
chrome.test.notifyPass();
{
"browser_action": {
"default_icon": "icon.png",
"default_title": "Default"
},
"description": "An extension testing crash http://crbug.com/57536 where cached extension causes browser action container to crash",
"name": "Test crash http://crbug.com/57536",
"manifest_version": 2,
"version": "1.0"
}
// Copyright 2018 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.
<html>
<head>
</head>
<body>
<canvas id="canvas" width="21" height="21">
<script src="background.js"></script>
</body>
</html>
......@@ -3,16 +3,16 @@
// found in the LICENSE file.
// First get an empty canvas.
var invisible = document.getElementById("canvas").getContext('2d').getImageData(
0, 0, 21, 21);
var canvas = new OffscreenCanvas(21, 21);
var invisibleImageData = canvas.getContext('2d').getImageData(0, 0, 21, 21);
// Fill the "canvas" element with some color.
var ctx = document.getElementById("canvas").getContext('2d');
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 42, 42);
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FF0000';
ctx.fillRect(0, 0, 21, 21);
var visible = document.getElementById("canvas").getContext('2d').getImageData(
0, 0, 21, 21);
var visibleImageData = ctx.getImageData(0, 0, 21, 21);
function setIcon(imageData) {
return new Promise(function(resolve) {
......
......@@ -3,7 +3,7 @@
"version": "1.0",
"manifest_version": 2,
"background": {
"page": "background.html"
"scripts": ["background.js"]
},
"browser_action": {
"name": "Set toolbar icon",
......
<!--
* Copyright (c) 2011 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.
-->
<html>
<head>
</head>
<body>
<canvas id="canvas" width="37" height="33">
<script src="background.js"></script>
</body>
</html>
......@@ -2,24 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Fill the "canvas" element with some color.
var ctx = document.getElementById("canvas").getContext('2d');
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 42, 42);
var canvas = new OffscreenCanvas(21, 21);
var canvasHD = new OffscreenCanvas(42, 42);
var canvas = document.getElementById("canvas").getContext('2d').getImageData(
0, 0, 21, 21);
var canvasHD = document.getElementById("canvas").getContext('2d').getImageData(
0, 0, 42, 42);
// Fill the canvases element with some color.
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FF0000';
ctx.fillRect(0, 0, 21, 21);
var ctxHD = canvasHD.getContext('2d');
ctxHD.fillStyle = '#FF0000';
ctxHD.fillRect(0, 0, 42, 42);
var image = ctx.getImageData(0, 0, 21, 21);
var imageHD = ctxHD.getImageData(0, 0, 42, 42);
var setIconParamQueue = [
{imageData: canvas},
{imageData: image},
{path: 'icon.png'},
{imageData: {'21': canvas, '42': canvasHD}},
{imageData: {'21': image, '42': imageHD}},
{path: {'21': 'icon.png', '42': 'icon2.png'}},
{imageData: {'21': canvas}},
{imageData: {'21': image}},
{path: {'21': 'icon.png'}},
{imageData: {'42': canvasHD}},
{imageData: {'42': imageHD}},
{imageData: {}},
{path: {}},
];
......@@ -27,7 +32,7 @@ var setIconParamQueue = [
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(windowId) {
if (setIconParamQueue.length == 0) {
chrome.test.notifyFail("Queue of params for test cases unexpectedly empty");
chrome.test.notifyFail('Queue of params for test cases unexpectedly empty');
return;
}
......
......@@ -3,7 +3,7 @@
"version": "1.0",
"manifest_version": 2,
"background": {
"page": "background.html"
"scripts": ["background.js"]
},
"permissions": [
"tabs", "http://*/*"
......
// Copyright 2019 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.
function updateBrowserAction() {
chrome.browserAction.setTitle({title: 'Modified'});
chrome.browserAction.setIcon({path: 'icon2.png'});
chrome.browserAction.setBadgeText({text: 'badge'});
chrome.browserAction.setBadgeBackgroundColor({color: [255,255,255,255]});
}
chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess) {
if (isAllowedAccess == true) {
chrome.test.sendMessage('incognito ready', function(message) {
if (message == 'incognito update') {
updateBrowserAction();
chrome.test.notifyPass();
}
});
}
});
chrome.test.sendMessage('ready', function(message) {
if (message == 'update') {
updateBrowserAction();
chrome.test.notifyPass();
}
});
{
"name": "A browser action test to verify updates to the icon and title.",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "This is the default title.",
"default_icon": "icon.png"
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment