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

Unified 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: Tests added 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/get_views/test.js
diff --git a/chrome/test/data/extensions/api_test/get_views/test.js b/chrome/test/data/extensions/api_test/get_views/test.js
index 765c4c0fb42605d6414f40e033c306b5609b3342..26acbb4a0bcc7c3516ad807c20888106a38d0935 100644
--- a/chrome/test/data/extensions/api_test/get_views/test.js
+++ b/chrome/test/data/extensions/api_test/get_views/test.js
@@ -11,42 +11,75 @@ const assertTrue = chrome.test.assertTrue;
// We need to remember the popupWindowId to be able to find it later.
var popupWindowId = 0;
+// Updated and used later to check getViews() tabId tag for options tab
Devlin 2016/07/11 17:23:45 We're sticklers for grammar in comments, so there
catmullings 2016/07/12 18:13:47 Done.
+var optionsTabId = 0;
+
// This function is called by the popup during the test run.
function popupCallback() {
// We have now added an popup so the total count goes up one.
assertEq(2, chrome.extension.getViews().length);
assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length);
-
- chrome.tabs.create({"url": chrome.extension.getURL("options.html")});
+ chrome.tabs.create({"url": chrome.extension.getURL("options.html")},
+ function(tab) {
+ // Check if tab returned is defined
Devlin 2016/07/11 17:23:45 indentation for callback functions is always kind
Devlin 2016/07/11 17:23:45 this comment just describes what the code is doing
catmullings 2016/07/12 18:13:47 Done.
catmullings 2016/07/12 18:13:48 Done.
+ optionsTabId = tab.id;
+ });
}
function optionsPageCallback() {
assertEq(3, chrome.extension.getViews().length);
assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length);
assertEq(2, chrome.extension.getViews(
- {"type": "tab", "windowId": window.id}).length);
+ {"type": "tab", "windowId": window.id}).length);
+
+ chrome.tabs.query({"windowId": window.id}, function(tabs) {
Devlin 2016/07/11 17:23:45 I know you're just following the style from the re
catmullings 2016/07/12 18:13:47 Done.
catmullings 2016/07/12 18:13:48 I'll go ahead and update the rest of the test with
+ // Assert 3 to account for new tab page, web popup, & new tab options.html
Devlin 2016/07/11 17:23:45 2-space indent here.
catmullings 2016/07/12 18:13:48 Done.
+ assertEq(3, tabs.length);
+
+ // Check that only 2 tabs belong to the extension
Devlin 2016/07/11 17:23:45 Here, use a comment to describe why, not what. Th
catmullings 2016/07/12 18:13:47 Done.
Devlin 2016/07/12 18:35:57 Was this actually done?
+ assertEq(2, chrome.extension.getViews({"type":"tab"}).length);
+
+ for (var i = 0; i < tabs.length; i++) {
+ if (tabs[i].windowId == popupWindowId) {
+ assertEq(1, chrome.extension.getViews({"tabId": tabs[i].id}).length);
+ // Test tabId tag with other parameters
+ assertEq(1, chrome.extension.getViews({"windowId": popupWindowId,
+ "tabId": tabs[i].id}).length);
+ assertEq(1, chrome.extension.getViews({"type": "tab",
+ "tabId": tabs[i].id}).length);
+ } else if (tabs[i].id == optionsTabId) {
+ assertEq(1, chrome.extension.getViews({"tabId": tabs[i].id}).length);
+ }
+ }
+
+ });
+
chrome.test.notifyPass();
}
var tests = [
- function getViews() {
Devlin 2016/07/11 17:23:45 this indentation was probably more correct before.
- assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined");
- assertEq(1, chrome.extension.getViews().length);
- assertEq(0, chrome.extension.getViews({"type": "tab"}).length);
- assertEq(0, chrome.extension.getViews({"type": "popup"}).length);
+function getViews() {
+ //printf("Other fn");
Devlin 2016/07/11 17:23:45 Don't forget to remove debugging code.
catmullings 2016/07/12 18:13:47 Done.
Devlin 2016/07/12 18:35:57 Ditto
+ assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined");
+ assertEq(1, chrome.extension.getViews().length);
+ assertEq(0, chrome.extension.getViews({"type": "tab"}).length);
+ assertEq(0, chrome.extension.getViews({"type": "popup"}).length);
- chrome.windows.getAll({populate: true}, function(windows) {
+ chrome.windows.getAll({populate: true}, function(windows) {
assertEq(1, windows.length);
// Create a popup window.
+
+ // TODO (catmullings): Fix potential race condition when/if
+ // popupCallback() is called before popupWindowId is set below
chrome.windows.create({"url": chrome.extension.getURL("popup.html"),
- "type": "popup"}, function(window) {
+ "type": "popup"}, function(window) {
Devlin 2016/07/11 17:23:45 here, too, indentation was probably right before.
catmullings 2016/07/12 18:13:47 Done.
Devlin 2016/07/12 18:35:57 Ditto
assertTrue(window.id > 0);
popupWindowId = window.id;
// The popup will call back to us through popupCallback (above).
+ });
});
- });
- }
+}
];
chrome.test.runTests(tests);

Powered by Google App Engine
This is Rietveld 408576698