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

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

Issue 2105033003: tabId support to chrome.extensions.getViews() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [Updated] Addressed code review Created 4 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // API test for chrome.extension.getViews. 5 // API test for chrome.extension.getViews.
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.GetViews 6 // browser_tests.exe --gtest_filter=ExtensionApiTest.GetViews
7 7
8 const assertEq = chrome.test.assertEq; 8 const assertEq = chrome.test.assertEq;
9 const assertTrue = chrome.test.assertTrue; 9 const assertTrue = chrome.test.assertTrue;
10 10
11 // We need to remember the popupWindowId to be able to find it later. 11 // We need to remember the popupWindowId to be able to find it later.
12 var popupWindowId = 0; 12 var popupWindowId = 0;
13 13
14 // Updated and used later to check getViews() tabId tag for the options tab.
15 var optionsTabId = 0;
16
14 // This function is called by the popup during the test run. 17 // This function is called by the popup during the test run.
15 function popupCallback() { 18 function popupCallback() {
16 // We have now added an popup so the total count goes up one. 19 // We have now added a popup so the total count goes up one.
17 assertEq(2, chrome.extension.getViews().length); 20 assertEq(2, chrome.extension.getViews().length);
18 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); 21 assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length);
19 22 chrome.tabs.create({url: chrome.extension.getURL("options.html")},
Devlin 2016/07/13 16:22:59 nitty nit: argument parameters should line up with
catmullings 2016/07/13 22:07:06 Done.
20 chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); 23 function(tab) {
24 optionsTabId = tab.id;
25 });
21 } 26 }
22 27
23 function optionsPageCallback() { 28 function optionsPageCallback() {
24 assertEq(3, chrome.extension.getViews().length); 29 assertEq(3, chrome.extension.getViews().length);
25 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); 30 assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length);
26 assertEq(2, chrome.extension.getViews( 31 assertEq(2,
27 {"type": "tab", "windowId": window.id}).length); 32 chrome.extension.getViews({type: "tab", windowId: window.id}).length);
Devlin 2016/07/13 16:22:59 ditto re parameter line-up: assertEq( 2, chrom
catmullings 2016/07/13 22:07:06 Done.
33
34 chrome.tabs.query({windowId: window.id}, function(tabs) {
35 // Assert 3 to account for new tab page, web popup, & new tab options.html
Devlin 2016/07/13 16:22:59 need to end this comment in a '.'
catmullings 2016/07/13 22:07:06 Done.
36 assertEq(3, tabs.length);
37
38 // Check that only 2 tabs belong to the extension
Devlin 2016/07/13 16:22:59 ditto, though here this comment just describes the
catmullings 2016/07/13 22:07:06 Yeah, I did address this before, but it didn't get
catmullings 2016/07/13 22:07:06 Done.
39 assertEq(2, chrome.extension.getViews({type:"tab"}).length);
40
41 for (var i = 0; i < tabs.length; i++) {
42 if (tabs[i].windowId == popupWindowId) {
43 assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length);
44 // Test tabId tag with other parameters
Devlin 2016/07/13 16:22:59 end in a '.'
catmullings 2016/07/13 22:07:06 Done.
45 assertEq(1, chrome.extension.getViews({windowId: popupWindowId,
46 tabId: tabs[i].id}).length);
47 assertEq(1, chrome.extension.getViews({type: "tab",
48 tabId: tabs[i].id}).length);
49 } else if (tabs[i].id == optionsTabId) {
50 assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length);
51 }
52 }
53 });
54
28 chrome.test.notifyPass(); 55 chrome.test.notifyPass();
29 } 56 }
30 57
31 var tests = [ 58 var tests = [
32 function getViews() { 59 function getViews() {
33 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); 60 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined");
34 assertEq(1, chrome.extension.getViews().length); 61 assertEq(1, chrome.extension.getViews().length);
35 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); 62 assertEq(0, chrome.extension.getViews({type: "tab"}).length);
36 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); 63 assertEq(0, chrome.extension.getViews({type: "popup"}).length);
37 64
38 chrome.windows.getAll({populate: true}, function(windows) { 65 chrome.windows.getAll({populate: true}, function(windows) {
39 assertEq(1, windows.length); 66 assertEq(1, windows.length);
40 67
41 // Create a popup window. 68 // Create a popup window.
42 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), 69
43 "type": "popup"}, function(window) { 70 // TODO (catmullings): Fix potential race condition when/if
71 // popupCallback() is called before popupWindowId is set below
72 chrome.windows.create({url: chrome.extension.getURL("popup.html"),
73 type: "popup"}, function(window) {
44 assertTrue(window.id > 0); 74 assertTrue(window.id > 0);
45 popupWindowId = window.id; 75 popupWindowId = window.id;
46 // The popup will call back to us through popupCallback (above). 76 // The popup will call back to us through popupCallback (above).
47 }); 77 });
48 }); 78 });
49 } 79 }
50 ]; 80 ];
51 81
52 chrome.test.runTests(tests); 82 chrome.test.runTests(tests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698