Commit 4d7c149f authored by David Bertoni's avatar David Bertoni Committed by Commit Bot

[Extensions] Remove obsolete service worker tests.

These tests were replaced by ServiceWorkerBasedBackgroundTest.TabsEvents
tests and will no longer work when extension API bindings are restricted
to the service worker script specified in the manifest.

Bug: 961836
Change-Id: I2f28ee669038f7dad1d24d5e44c55551db9ddeba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1612558Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662226}
parent 85930550
......@@ -1128,29 +1128,6 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesFetch) {
"service_worker/web_accessible_resources/fetch/", "page.html"));
}
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, TabsCreate) {
// Extensions APIs from SW are only enabled on trunk.
ScopedCurrentChannel current_channel_override(version_info::Channel::UNKNOWN);
const Extension* extension = LoadExtensionWithFlags(
test_data_dir_.AppendASCII("service_worker/tabs_create"), kFlagNone);
ASSERT_TRUE(extension);
ui_test_utils::NavigateToURL(browser(),
extension->GetResourceURL("page.html"));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
int starting_tab_count = browser()->tab_strip_model()->count();
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
web_contents, "window.runServiceWorker()", &result));
ASSERT_EQ("chrome.tabs.create callback", result);
EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count());
// Check extension shutdown path.
UnloadExtension(extension->id());
EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count());
}
// Tests that updating a packed extension with modified scripts works
// properly -- we expect that the new script will execute, rather than the
// previous one.
......@@ -1296,22 +1273,6 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, UpdateUnpackedExtension) {
}
}
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, Events) {
// Extensions APIs from SW are only enabled on trunk.
ScopedCurrentChannel current_channel_override(version_info::Channel::UNKNOWN);
const Extension* extension = LoadExtensionWithFlags(
test_data_dir_.AppendASCII("service_worker/events"), kFlagNone);
ASSERT_TRUE(extension);
ui_test_utils::NavigateToURL(browser(),
extension->GetResourceURL("page.html"));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
web_contents, "window.runEventTest()", &result));
ASSERT_EQ("chrome.tabs.onUpdated callback", result);
}
IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, EventsToStoppedWorker) {
// Extensions APIs from SW are only enabled on trunk.
ScopedCurrentChannel current_channel_override(version_info::Channel::UNKNOWN);
......
{
"name": "Service worker events test (chrome.tabs.onUpdated)",
"version": "1.0",
"manifest_version": 2,
"permissions": [ "tabs" ]
}
<!DOCTYPE html>
<!--
Copyright 2017 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>
<script src="on_updated.js"></script>
</head>
</html>
// Copyright 2017 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.
window.onload = function() {
setTimeout(function() {
document.title = 'foo';
setTimeout(function() {
document.title = 'bar';
}, 0);
}, 0);
}
<!DOCTYPE html>
<!--
Copyright 2017 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="page.js"></script>
// Copyright 2017 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 getWorkerPromise = function() {
return new Promise(function(resolve, reject) {
navigator.serviceWorker.register('sw.js').then(function() {
return navigator.serviceWorker.ready;
}).then(function(registration) {
var sw = registration.active;
var channel = new MessageChannel();
channel.port1.onmessage = function(e) {
var data = e.data;
if (data == 'listener-added') {
var url = chrome.extension.getURL('on_updated.html');
chrome.tabs.create({url: url});
} else if (data == 'chrome.tabs.onUpdated callback') {
resolve(data);
} else {
reject(data);
}
};
sw.postMessage('addOnUpdatedListener', [channel.port2]);
}).catch(function(err) {
reject(err);
});
});
};
window.runEventTest = function() {
getWorkerPromise().then(function(message) {
window.domAutomationController.send(message);
}).catch(function(err) {
window.domAutomationController.send('FAILURE');
});
};
// Copyright 2017 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 expectedEventData;
var capturedEventData;
function expect(data) {
expectedEventData = data;
capturedEventData = [];
}
var messagePort = null;
function sendMessage(msg) { messagePort.postMessage(msg); }
function checkExpectations() {
if (capturedEventData.length < expectedEventData.length) {
return;
}
var passed = JSON.stringify(expectedEventData) ==
JSON.stringify(capturedEventData);
if (passed) {
sendMessage('chrome.tabs.onUpdated callback');
} else {
sendMessage('FAILURE');
}
}
self.onmessage = function(e) {
var data = e.data;
messagePort = e.ports[0];
if (data == 'addOnUpdatedListener') {
addOnUpdatedListener();
e.ports[0].postMessage('listener-added');
}
};
function addOnUpdatedListener() {
chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
console.log('onUpdated, tabId: ' + tabId + ', info: ' +
JSON.stringify(info) + ', tab: ' + JSON.stringify(tab));
capturedEventData.push(info);
checkExpectations();
});
var url = chrome.extension.getURL('on_updated.html');
expect([
{status: 'loading', 'url': url},
{status: 'complete'},
{title: 'foo'},
{title: 'bar'}
]);
};
{
"name": "Service worker with chrome.tabs.create",
"version": "1.0",
"manifest_version": 2
}
// Copyright 2016 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 getServiceWorkerPromise = function() {
return new Promise(function(resolve, reject) {
navigator.serviceWorker.register('sw.js').then(function() {
return navigator.serviceWorker.ready;
}).then(function(registration) {
var sw = registration.active;
var channel = new MessageChannel();
channel.port1.onmessage = function(e) {
if (e.data == 'chrome.tabs.create callback') {
resolve(e.data);
} else {
reject(e.data);
}
};
sw.postMessage('createTab', [channel.port2]);
}).catch(function(err) {
reject(err);
});
});
};
window.runServiceWorker = function() {
getServiceWorkerPromise().then(function(message) {
window.domAutomationController.send(message);
}).catch(function(err) {
window.domAutomationController.send('FAILURE');
});
};
// Copyright 2016 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.
self.onmessage = function(e) {
if (e.data == 'createTab') {
try {
chrome.tabs.create({'url': 'http://www.google.com'}, function(tabs) {
e.ports[0].postMessage('chrome.tabs.create callback');
});
} catch (e) {
e.ports[0].postMessage('FAILURE');
}
} else {
e.ports[0].postMessage('FAILURE');
}
};
......@@ -41,15 +41,20 @@ chrome.test.runTests([
chrome.test.fail(e);
}
},
// Test the chrome.tabs.onUpdated listener.
// Test the chrome.tabs.onUpdated listener through the loading cycle.
function testTabOnUpdatedListener() {
var newUrl = 'chrome://version/';
var gotLoading = false;
chrome.tabs.onUpdated.addListener(function localListener(
tabId, changeInfo, tab) {
if (changeInfo.status === 'loading') {
chrome.tabs.onUpdated.removeListener(localListener);
chrome.test.assertFalse(gotLoading);
gotLoading = true;
chrome.test.assertEq(tabProps[1].id, tabId);
chrome.test.assertEq(newUrl, changeInfo.url);
} else if (changeInfo.status === 'complete') {
chrome.test.assertTrue(gotLoading);
chrome.tabs.onUpdated.removeListener(localListener);
chrome.test.succeed();
}
});
......
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