Skip to content

Commit

Permalink
[Extensions] Convert more tabs API tests to run as service workers. (2)
Browse files Browse the repository at this point in the history
This CL creates separate extensions for the affected tests. Test
files that are shared remain in the parent directory and are
referenced through the pageUrl utility function.

Bug: 1093066
Change-Id: Ie7bfa8c355782a76a8c5e04c7b56decf2914e90d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4234087
Auto-Submit: David Bertoni <dbertoni@chromium.org>
Commit-Queue: Emilia Paz <emiliapaz@chromium.org>
Reviewed-by: Emilia Paz <emiliapaz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1103374}
  • Loading branch information
David Bertoni authored and Chromium LUCI CQ committed Feb 9, 2023
1 parent c07f0a3 commit dae0684
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 66 deletions.
28 changes: 10 additions & 18 deletions chrome/browser/extensions/api/tabs/tabs_apitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,17 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabAudible) {
<< message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabMuted) {
ASSERT_TRUE(RunExtensionTest("tabs/basics", {.extension_url = "muted.html"}))
<< message_;
IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, Muted) {
ASSERT_TRUE(RunExtensionTest("tabs/basics/muted")) << message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, Tabs2) {
ASSERT_TRUE(RunExtensionTest("tabs/basics", {.extension_url = "crud2.html"}))
<< message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabDuplicate) {
ASSERT_TRUE(
RunExtensionTest("tabs/basics", {.extension_url = "duplicate.html"}))
<< message_;
IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, Duplicate) {
ASSERT_TRUE(RunExtensionTest("tabs/basics/duplicate")) << message_;
}

IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, Size) {
Expand Down Expand Up @@ -162,10 +159,8 @@ IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, Events) {
ASSERT_TRUE(RunExtensionTest("tabs/basics/events")) << message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabRelativeURLs) {
ASSERT_TRUE(
RunExtensionTest("tabs/basics", {.extension_url = "relative_urls.html"}))
<< message_;
IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, RelativeURLs) {
ASSERT_TRUE(RunExtensionTest("tabs/basics/relative_urls")) << message_;
}

IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, Query) {
Expand All @@ -188,15 +183,12 @@ IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, Opener) {
ASSERT_TRUE(RunExtensionTest("tabs/basics/opener")) << message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabRemove) {
ASSERT_TRUE(RunExtensionTest("tabs/basics", {.extension_url = "remove.html"}))
<< message_;
IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, Remove) {
ASSERT_TRUE(RunExtensionTest("tabs/basics/remove")) << message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabRemoveMultiple) {
ASSERT_TRUE(RunExtensionTest("tabs/basics",
{.extension_url = "remove-multiple.html"}))
<< message_;
IN_PROC_BROWSER_TEST_P(ExtensionApiTabTestWithContextType, RemoveMultiple) {
ASSERT_TRUE(RunExtensionTest("tabs/basics/remove_multiple")) << message_;
}

IN_PROC_BROWSER_TEST_F(ExtensionApiTabTest, TabGetCurrent) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
var firstTabId;
var firstWindowId;

const scriptUrl = '_test_resources/api_test/tabs/basics/tabs_util.js';
let loadScript = chrome.test.loadScript(scriptUrl);

loadScript.then(async function() {
chrome.test.runTests([
function setupWindow() {
createWindow([pageUrl("a")], {},
Expand Down Expand Up @@ -51,4 +55,4 @@ chrome.test.runTests([
});
}
*/
]);
])});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "chrome.tabs",
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end browser test for chrome.tabs API",
"permissions": ["tabs"],
"background": {
"scripts": ["duplicate.js"],
"persistent": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end browser test for chrome.tabs API",
"permissions": ["storage", "tabs"]
"permissions": ["tabs"]
}
7 changes: 0 additions & 7 deletions chrome/test/data/extensions/api_test/tabs/basics/muted.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "chrome.tabs",
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end browser test for chrome.tabs API",
"permissions": ["tabs"],
"background": {
"scripts": ["muted.js"],
"persistent": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

var testTabId_;

const scriptUrl = '_test_resources/api_test/tabs/basics/tabs_util.js';
let loadScript = chrome.test.loadScript(scriptUrl);

loadScript.then(async function() {
chrome.test.runTests([
function setupWindow() {
chrome.tabs.getCurrent(pass(function(tab) {
function createTab() {
chrome.tabs.create({}, pass(function(tab) {
testTabId_ = tab.id;
}));
},
Expand Down Expand Up @@ -72,4 +76,4 @@ chrome.test.runTests([
chrome.tabs.update(testTabId_, {muted: false});
}

]);
])});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "chrome.tabs",
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end browser test for chrome.tabs API",
"permissions": ["tabs"],
"background": {
"scripts": ["relative_urls.js"],
"persistent": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
var firstWindowId;
var testTabId;

const scriptUrl = '_test_resources/api_test/tabs/basics/tabs_util.js';
let loadScript = chrome.test.loadScript(scriptUrl);

loadScript.then(async function() {
function resolveOnMessage(resolve) {
chrome.runtime.onMessage.addListener(function local(message) {
chrome.runtime.onMessage.removeListener(local);
Expand Down Expand Up @@ -61,4 +65,4 @@ chrome.test.runTests([
Promise.all([onMessagePromise, createPromise]).then(chrome.test.succeed);
}

]);
])});

This file was deleted.

8 changes: 0 additions & 8 deletions chrome/test/data/extensions/api_test/tabs/basics/remove.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "chrome.tabs",
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end browser test for chrome.tabs API",
"permissions": ["storage", "tabs"],
"background": {
"scripts": ["remove.js"],
"persistent": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ function resolveOnStorageChanged(resolve) {
}

var secondTabId;
const scriptUrl = '_test_resources/api_test/tabs/basics/tabs_util.js';
let loadScript = chrome.test.loadScript(scriptUrl);

loadScript.then(async function() {
chrome.test.runTests([
function createSecondTab() {
// Create and switch to a second tab that has an unload handler.
chrome.tabs.create({index: 1, active: true, url: 'unload-storage-1.html'},
chrome.tabs.create({index: 1, active: true,
url: pageUrl('unload-storage-1')},
(tab) => {
secondTabId = tab.id;
assertTrue(tab.active);
Expand All @@ -42,4 +47,4 @@ chrome.test.runTests([

Promise.all([onStoragePromise, removePromise]).then(chrome.test.succeed);
}
]);
])});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "chrome.tabs",
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end browser test for chrome.tabs API",
"permissions": ["storage", "tabs"],
"background": {
"scripts": ["remove-multiple.js"],
"persistent": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function createTab(createParams) {
});
}

const scriptUrl = '_test_resources/api_test/tabs/basics/tabs_util.js';
let loadScript = chrome.test.loadScript(scriptUrl);

loadScript.then(async function() {
chrome.test.runTests([
function getFirstTabId() {
chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT },
Expand All @@ -45,14 +49,14 @@ chrome.test.runTests([
},
function createTabs() {
// Create a second tab that has an unload handler.
createTab({index: 1, active: false, url: 'unload-storage-1.html'})
createTab({index: 1, active: false, url: pageUrl('unload-storage-1')})
.then((tab) => {
secondTabId = tab.id;
assertFalse(tab.active);
assertEq(1, tab.index);
// Create and switch to a third tab that has an unload handler.
return createTab(
{index: 2, active: true, url: 'unload-storage-2.html'});
{index: 2, active: true, url: pageUrl('unload-storage-2')});
}).then((tab) => {
thirdTabId = tab.id;
assertTrue(tab.active);
Expand Down Expand Up @@ -89,4 +93,4 @@ chrome.test.runTests([
Promise.all([onStorageChangedPromise1, onStorageChangedPromise2,
removePromise]).then(chrome.test.succeed);
}
]);
])});

0 comments on commit dae0684

Please sign in to comment.