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) { ...@@ -417,6 +417,12 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WindowsBasic) {
EXPECT_EQ(2, histogram_tester.GetBucketCount( EXPECT_EQ(2, histogram_tester.GetBucketCount(
"Extensions.Functions.ExtensionServiceWorkerCalls", "Extensions.Functions.ExtensionServiceWorkerCalls",
functions::HistogramValue::WINDOWS_GETALL)); 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. // Tests chrome.webRequest APIs.
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
var createWindowUtil = function(urlToLoad, createdCallback) { var createWindowUtil = function(urlToLoad, createdCallback) {
try { try {
chrome.windows.create({ 'url': urlToLoad, 'type': 'normal', chrome.windows.create({ 'url': urlToLoad, 'type': 'normal',
'width': 600, 'height': 400 }, function(window) { 'width': 600, 'height': 400 }, createdCallback);
createdCallback({width: window.width, height: window.height});
});
} catch (e) { } catch (e) {
chrome.test.fail(e); chrome.test.fail(e);
} }
...@@ -15,9 +13,23 @@ var createWindowUtil = function(urlToLoad, createdCallback) { ...@@ -15,9 +13,23 @@ var createWindowUtil = function(urlToLoad, createdCallback) {
var getAllWindowUtil = function(populateValue, getAllCallback) { var getAllWindowUtil = function(populateValue, getAllCallback) {
try { try {
chrome.windows.getAll({populate: populateValue}, function(window) { chrome.windows.getAll({populate: populateValue}, getAllCallback);
getAllCallback({length: window.length}); } 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) { } catch (e) {
chrome.test.fail(e); chrome.test.fail(e);
} }
...@@ -25,27 +37,38 @@ var getAllWindowUtil = function(populateValue, getAllCallback) { ...@@ -25,27 +37,38 @@ var getAllWindowUtil = function(populateValue, getAllCallback) {
chrome.test.runTests([ chrome.test.runTests([
// Get the window that was automatically created. // Get the window that was automatically created.
function testWindowGetBeforeCreate() { function testWindowGetAllBeforeCreate() {
var populateValue = true; var populateValue = true;
getAllWindowUtil(populateValue, function(windowData) { getAllWindowUtil(populateValue, function(allWindowsData) {
chrome.test.assertEq(1, windowData.length); chrome.test.assertEq(1, allWindowsData.length);
chrome.test.succeed(); chrome.test.succeed();
}); });
}, },
// Create a new window. // Create a new window.
function testWindowCreate() { function testWindowCreate() {
createWindowUtil('blank.html', function(windowData) { createWindowUtil('blank.html', function(createdWindowData) {
chrome.test.assertEq(600, windowData.width); chrome.test.assertEq(600, createdWindowData.width);
chrome.test.assertEq(400, windowData.height); chrome.test.assertEq(400, createdWindowData.height);
chrome.test.succeed(); chrome.test.succeed();
}); });
}, },
// Check that the created window exists. // Check that the created window exists.
function testWindowGetAfterCreate() { function testWindowGetAllAfterCreate() {
var populateValue = true; var populateValue = true;
getAllWindowUtil(populateValue, function(windowData) { getAllWindowUtil(populateValue, function(allWindowsData) {
chrome.test.assertEq(2, windowData.length); 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(); 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