Commit 0552b990 authored by Ghazale Hosseinabadi's avatar Ghazale Hosseinabadi Committed by Commit Bot

[Extensions] Add Windows API test coverage

This CL adds test coverage for WINDOWS_GET and WINDOWS_GETCURRENT
APIs.

Bug: 1093066
Change-Id: I8c8535818ffd0b748418c28bb3b4945439ca8593
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2442130
Commit-Queue: Ghazale Hosseinabadi <ghazale@chromium.org>
Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813986}
parent eff20ffa
......@@ -417,6 +417,12 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WindowsBasic) {
EXPECT_EQ(2, histogram_tester.GetBucketCount(
"Extensions.Functions.ExtensionServiceWorkerCalls",
functions::HistogramValue::WINDOWS_GETALL));
EXPECT_EQ(1, histogram_tester.GetBucketCount(
"Extensions.Functions.ExtensionServiceWorkerCalls",
functions::HistogramValue::WINDOWS_GET));
EXPECT_EQ(1, histogram_tester.GetBucketCount(
"Extensions.Functions.ExtensionServiceWorkerCalls",
functions::HistogramValue::WINDOWS_GETCURRENT));
}
// Tests chrome.webRequest APIs.
......
......@@ -5,9 +5,7 @@
var createWindowUtil = function(urlToLoad, createdCallback) {
try {
chrome.windows.create({ 'url': urlToLoad, 'type': 'normal',
'width': 600, 'height': 400 }, function(window) {
createdCallback({width: window.width, height: window.height});
});
'width': 600, 'height': 400 }, createdCallback);
} catch (e) {
chrome.test.fail(e);
}
......@@ -15,9 +13,23 @@ var createWindowUtil = function(urlToLoad, createdCallback) {
var getAllWindowUtil = function(populateValue, getAllCallback) {
try {
chrome.windows.getAll({populate: populateValue}, function(window) {
getAllCallback({length: window.length});
});
chrome.windows.getAll({populate: populateValue}, getAllCallback);
} catch (e) {
chrome.test.fail(e);
}
}
var getWindowUtil = function(windowId, getCallback) {
try {
chrome.windows.get(windowId, getCallback);
} catch (e) {
chrome.test.fail(e);
}
}
var getCurrentWindowUtil = function(getCurrentCallback) {
try {
chrome.windows.getCurrent(getCurrentCallback);
} catch (e) {
chrome.test.fail(e);
}
......@@ -25,27 +37,38 @@ var getAllWindowUtil = function(populateValue, getAllCallback) {
chrome.test.runTests([
// Get the window that was automatically created.
function testWindowGetBeforeCreate() {
function testWindowGetAllBeforeCreate() {
var populateValue = true;
getAllWindowUtil(populateValue, function(windowData) {
chrome.test.assertEq(1, windowData.length);
getAllWindowUtil(populateValue, function(allWindowsData) {
chrome.test.assertEq(1, allWindowsData.length);
chrome.test.succeed();
});
},
// Create a new window.
function testWindowCreate() {
createWindowUtil('blank.html', function(windowData) {
chrome.test.assertEq(600, windowData.width);
chrome.test.assertEq(400, windowData.height);
createWindowUtil('blank.html', function(createdWindowData) {
chrome.test.assertEq(600, createdWindowData.width);
chrome.test.assertEq(400, createdWindowData.height);
chrome.test.succeed();
});
},
// Check that the created window exists.
function testWindowGetAfterCreate() {
function testWindowGetAllAfterCreate() {
var populateValue = true;
getAllWindowUtil(populateValue, function(windowData) {
chrome.test.assertEq(2, windowData.length);
getAllWindowUtil(populateValue, function(allWindowsData) {
chrome.test.assertEq(2, allWindowsData.length);
var createdWindowId = allWindowsData[allWindowsData.length - 1].id;
getWindowUtil(createdWindowId, function(windowData) {
chrome.test.assertEq(600, windowData.width);
chrome.test.assertEq(400, windowData.height);
chrome.test.succeed();
});
// Check that the created window is the current window.
getCurrentWindowUtil(function(currentWindowData) {
chrome.test.assertEq(createdWindowId, currentWindowData.id);
chrome.test.succeed();
});
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