Commit 699e7e83 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_CREATE and WINDOWS_GETALL APIs.

Bug: 1093066
Change-Id: I750a4689af252e167bcedf419143deaca712269f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436410
Commit-Queue: Ghazale Hosseinabadi <ghazale@chromium.org>
Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811971}
parent 1cb41b94
...@@ -403,6 +403,22 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsExecuteScript) { ...@@ -403,6 +403,22 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, TabsExecuteScript) {
<< message_; << message_;
} }
// Tests chrome.windows APIs.
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WindowsBasic) {
base::HistogramTester histogram_tester;
ASSERT_TRUE(
RunExtensionTest("service_worker/worker_based_background/windows_basic"))
<< message_;
// Extension should issue one chrome.windows.create call and two
// chrome.windows.getAll, verify that we logged histogram for it.
EXPECT_EQ(1, histogram_tester.GetBucketCount(
"Extensions.Functions.ExtensionServiceWorkerCalls",
functions::HistogramValue::WINDOWS_CREATE));
EXPECT_EQ(2, histogram_tester.GetBucketCount(
"Extensions.Functions.ExtensionServiceWorkerCalls",
functions::HistogramValue::WINDOWS_GETALL));
}
// Tests chrome.webRequest APIs. // Tests chrome.webRequest APIs.
IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WebRequest) { IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WebRequest) {
ASSERT_TRUE( ASSERT_TRUE(
......
{
"name": "Service Worker-based background script",
"version": "0.1",
"manifest_version": 2,
"description": "Test windows APIs for service worker-based background scripts.",
"permissions": ["tabs"],
"background": {"service_worker": "service_worker_background.js"}
}
// Copyright 2020 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 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});
});
} catch (e) {
chrome.test.fail(e);
}
}
var getAllWindowUtil = function(populateValue, getAllCallback) {
try {
chrome.windows.getAll({populate: populateValue}, function(window) {
getAllCallback({length: window.length});
});
} catch (e) {
chrome.test.fail(e);
}
}
chrome.test.runTests([
// Get the window that was automatically created.
function testWindowGetBeforeCreate() {
var populateValue = true;
getAllWindowUtil(populateValue, function(windowData) {
chrome.test.assertEq(1, windowData.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);
chrome.test.succeed();
});
},
// Check that the created window exists.
function testWindowGetAfterCreate() {
var populateValue = true;
getAllWindowUtil(populateValue, function(windowData) {
chrome.test.assertEq(2, windowData.length);
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