Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: chrome/test/data/extensions/api_test/windows/events/test.js

Issue 1099553002: extensions: windows: list all windows from the current profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var results = {
6 filtered: {},
7 unfiltered: {}
8 };
9
10 function recordEvents(category, name, windowId, windowType) {
11 if (!results[category][windowId])
12 results[category][windowId] = { id: windowId, type: windowType };
13 results[category][windowId][name] = true
14 }
15
16 chrome.windows.onCreated.addListener(function(win) {
17 recordEvents('filtered', 'create', win.id, win.type);
18 });
19 chrome.windows.onRemoved.addListener(function(id) {
20 recordEvents('filtered', 'remove', id, null);
21 });
22 chrome.windows.onFocusChanged.addListener(function(id) {
23 recordEvents('filtered', 'focus', id, null);
24 });
25
26 var noFilter = { windowTypes: ['app', 'devtools', 'normal', 'panel', 'popup'] };
27 chrome.windows.onCreated.addListener(function(win) {
28 recordEvents('unfiltered', 'create', win.id, win.type);
29 }, noFilter);
30 chrome.windows.onRemoved.addListener(function(id) {
31 recordEvents('unfiltered', 'remove', id, null);
32 }, noFilter);
33 chrome.windows.onFocusChanged.addListener(function(id) {
34 recordEvents('unfiltered', 'focus', id, null);
35 }, noFilter);
36
37 chrome.test.sendMessage('ready', function (message) {
38 chrome.windows.getCurrent(function(currentWindow) {
39 var filteredCount = 0;
40 for (var i in results.filtered) {
41 var win = results.filtered[i];
42 if (win.id == currentWindow.id || win.id == -1)
43 continue;
44 filteredCount++;
45 chrome.test.assertFalse(win.type == 'app' || win.type == 'devtools',
46 'Unexpected window type "' +
47 win.type + '" in filtered events');
48 chrome.test.assertTrue(win.create == true,
49 'Missing create event for ' + win.type);
50 chrome.test.assertTrue(win.remove == true,
51 'Missing remove event for ' + win.type);
52 chrome.test.assertTrue(win.focus == true,
53 'Missing focus event for ' + win.type);
54 }
55 chrome.test.assertEq(1, filteredCount);
56
57 var unfilteredCount = 0;
58 var includes_app = false, includes_devtools = false;
59 for (var i in results.unfiltered) {
60 var win = results.unfiltered[i];
61 if (win.id == currentWindow.id || win.id == -1)
62 continue;
63 unfilteredCount++;
64 if (win.type == 'app')
65 includes_app = true;
66 if (win.type == 'devtools')
67 includes_devtools = true;
68 chrome.test.assertTrue(win.create == true,
69 'Missing create event for ' + win.type);
70 chrome.test.assertTrue(win.remove == true,
71 'Missing remove event for ' + win.type);
72 if (message == 'focus')
73 chrome.test.assertTrue(win.focus == true,
74 'Missing focus event for ' + win.type);
75 }
76 chrome.test.assertEq(3, unfilteredCount);
77 chrome.test.assertTrue(includes_app && includes_devtools,
78 'Could not find app or devtools windows');
79
80 chrome.test.notifyPass();
81 });
82 });
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/windows/events/manifest.json ('k') | extensions/common/event_filtering_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698