diff options
author | lionel.g.landwerlin <lionel.g.landwerlin@intel.com> | 2015-08-05 17:04:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-06 00:04:39 +0000 |
commit | 56b2a727992f8caf2141f89bf0073793f5cbe3d8 (patch) | |
tree | 7b5e2e7b355bbac1bb4de5c3d8c5281386fe731c /chrome/test/data | |
parent | 123ef4fe9ba98342fcb6bd6f5437a10592d0ed2f (diff) | |
download | chromium_src-56b2a727992f8caf2141f89bf0073793f5cbe3d8.zip chromium_src-56b2a727992f8caf2141f89bf0073793f5cbe3d8.tar.gz chromium_src-56b2a727992f8caf2141f89bf0073793f5cbe3d8.tar.bz2 |
extensions: windows: list all windows from the current profile
This change allows extensions to get access to a broader set of
chromium windows (namely windows created by other
applications/extensions) as long as they belong to the same profile.
BUG=394341
TEST=browser_tests --gtest_filter=ExtensionTabsTest.*
Review URL: https://codereview.chromium.org/1099553002
Cr-Commit-Position: refs/heads/master@{#342016}
Diffstat (limited to 'chrome/test/data')
3 files changed, 97 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/api_test/windows/events/background.html b/chrome/test/data/extensions/api_test/windows/events/background.html new file mode 100644 index 0000000..6ada66a --- /dev/null +++ b/chrome/test/data/extensions/api_test/windows/events/background.html @@ -0,0 +1,6 @@ +<!-- + * Copyright 2015 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="test.js"></script> diff --git a/chrome/test/data/extensions/api_test/windows/events/manifest.json b/chrome/test/data/extensions/api_test/windows/events/manifest.json new file mode 100644 index 0000000..cac457b --- /dev/null +++ b/chrome/test/data/extensions/api_test/windows/events/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "chrome.tabs test", + "version": "0.1", + "manifest_version": 2, + "description": "end-to-end browser test for chrome.windows events API", + "background": { + "page": "background.html" + } +} diff --git a/chrome/test/data/extensions/api_test/windows/events/test.js b/chrome/test/data/extensions/api_test/windows/events/test.js new file mode 100644 index 0000000..a10aaf72 --- /dev/null +++ b/chrome/test/data/extensions/api_test/windows/events/test.js @@ -0,0 +1,82 @@ +// Copyright 2015 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 results = { + filtered: {}, + unfiltered: {} +}; + +function recordEvents(category, name, windowId, windowType) { + if (!results[category][windowId]) + results[category][windowId] = { id: windowId, type: windowType }; + results[category][windowId][name] = true +} + +chrome.windows.onCreated.addListener(function(win) { + recordEvents('filtered', 'create', win.id, win.type); +}); +chrome.windows.onRemoved.addListener(function(id) { + recordEvents('filtered', 'remove', id, null); +}); +chrome.windows.onFocusChanged.addListener(function(id) { + recordEvents('filtered', 'focus', id, null); +}); + +var noFilter = { windowTypes: ['app', 'devtools', 'normal', 'panel', 'popup'] }; +chrome.windows.onCreated.addListener(function(win) { + recordEvents('unfiltered', 'create', win.id, win.type); +}, noFilter); +chrome.windows.onRemoved.addListener(function(id) { + recordEvents('unfiltered', 'remove', id, null); +}, noFilter); +chrome.windows.onFocusChanged.addListener(function(id) { + recordEvents('unfiltered', 'focus', id, null); +}, noFilter); + +chrome.test.sendMessage('ready', function (message) { + chrome.windows.getCurrent(function(currentWindow) { + var filteredCount = 0; + for (var i in results.filtered) { + var win = results.filtered[i]; + if (win.id == currentWindow.id || win.id == -1) + continue; + filteredCount++; + chrome.test.assertFalse(win.type == 'app' || win.type == 'devtools', + 'Unexpected window type "' + + win.type + '" in filtered events'); + chrome.test.assertTrue(win.create == true, + 'Missing create event for ' + win.type); + chrome.test.assertTrue(win.remove == true, + 'Missing remove event for ' + win.type); + chrome.test.assertTrue(win.focus == true, + 'Missing focus event for ' + win.type); + } + chrome.test.assertEq(1, filteredCount); + + var unfilteredCount = 0; + var includes_app = false, includes_devtools = false; + for (var i in results.unfiltered) { + var win = results.unfiltered[i]; + if (win.id == currentWindow.id || win.id == -1) + continue; + unfilteredCount++; + if (win.type == 'app') + includes_app = true; + if (win.type == 'devtools') + includes_devtools = true; + chrome.test.assertTrue(win.create == true, + 'Missing create event for ' + win.type); + chrome.test.assertTrue(win.remove == true, + 'Missing remove event for ' + win.type); + if (message == 'focus') + chrome.test.assertTrue(win.focus == true, + 'Missing focus event for ' + win.type); + } + chrome.test.assertEq(3, unfilteredCount); + chrome.test.assertTrue(includes_app && includes_devtools, + 'Could not find app or devtools windows'); + + chrome.test.notifyPass(); + }); +}); |