From e0e423ebc778cae44747e8c22187abf5900d9746 Mon Sep 17 00:00:00 2001 From: Ben Parr Date: Fri, 16 Jul 2010 11:17:35 -0700 Subject: [PATCH] Bug 578580: Add category utilities for add-ons manager browser tests. r=dtownsend --- .../test/browser/browser_bug562899.js | 27 +++---- .../test/browser/browser_bug572561.js | 8 +- .../mozapps/extensions/test/browser/head.js | 73 +++++++++++++++++++ 3 files changed, 90 insertions(+), 18 deletions(-) diff --git a/toolkit/mozapps/extensions/test/browser/browser_bug562899.js b/toolkit/mozapps/extensions/test/browser/browser_bug562899.js index 1d83ec17f22..bfe81b5e108 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_bug562899.js +++ b/toolkit/mozapps/extensions/test/browser/browser_bug562899.js @@ -10,6 +10,7 @@ Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); const xpi = "browser/toolkit/mozapps/extensions/test/browser/browser_installssl.xpi"; var gManagerWindow; +var gCategoryUtilities; function test() { waitForExplicitFinish(); @@ -23,6 +24,7 @@ function test() { open_manager(null, function(aWindow) { gManagerWindow = aWindow; + gCategoryUtilities = new CategoryUtilities(gManagerWindow); run_next_test(); }); } @@ -39,26 +41,21 @@ function end_test() { add_test(function() { var themeCount = null; var pluginCount = null; - var themeItem = gManagerWindow.document.getElementById("category-themes"); - var pluginItem = gManagerWindow.document.getElementById("category-plugins"); + var themeItem = gCategoryUtilities.get("theme"); + var pluginItem = gCategoryUtilities.get("plugin"); var list = gManagerWindow.document.getElementById("addon-list"); - EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow); - - wait_for_view_load(gManagerWindow, function() { + gCategoryUtilities.open(themeItem, function() { themeCount = list.childNodes.length; ok(themeCount > 0, "Test is useless if there are no themes"); - EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow); - - wait_for_view_load(gManagerWindow, function() { + gCategoryUtilities.open(pluginItem, function() { pluginCount = list.childNodes.length; ok(pluginCount > 0, "Test is useless if there are no plugins"); - EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow); - EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow); + gCategoryUtilities.open(themeItem); - wait_for_view_load(gManagerWindow, function() { + gCategoryUtilities.open(pluginItem, function() { is(list.childNodes.length, pluginCount, "Should only see the plugins"); var item = list.firstChild; @@ -70,11 +67,9 @@ add_test(function() { // Tests that switching to, from, to the same pane in quick succession // still only shows the right number of results - EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow); - EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow); - EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow); - - wait_for_view_load(gManagerWindow, function() { + gCategoryUtilities.open(themeItem); + gCategoryUtilities.open(pluginItem); + gCategoryUtilities.open(themeItem, function() { is(list.childNodes.length, themeCount, "Should only see the theme"); var item = list.firstChild; diff --git a/toolkit/mozapps/extensions/test/browser/browser_bug572561.js b/toolkit/mozapps/extensions/test/browser/browser_bug572561.js index 75aae1b80ef..033b59292fa 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_bug572561.js +++ b/toolkit/mozapps/extensions/test/browser/browser_bug572561.js @@ -6,6 +6,7 @@ // installed but some are pending install var gManagerWindow; +var gCategoryUtilities; var gProvider; var gInstallProperties = [{ name: "Locale Category Test", @@ -41,6 +42,7 @@ function test() { open_manager(null, function(aWindow) { gManagerWindow = aWindow; + gCategoryUtilities = new CategoryUtilities(gManagerWindow); run_next_test(); }); } @@ -52,8 +54,8 @@ function end_test() { } function check_hidden(aExpectedHidden) { - var category = gManagerWindow.gCategories.get("addons://list/locale"); - is(category.hidden, aExpectedHidden, "Should have correct hidden state"); + var hidden = !gCategoryUtilities.isTypeVisible("locale"); + is(hidden, aExpectedHidden, "Should have correct hidden state"); } // Tests that a non-active install does not make the locale category show @@ -70,6 +72,7 @@ add_test(function() { add_test(function() { restart_manager(gManagerWindow, null, function(aWindow) { gManagerWindow = aWindow; + gCategoryUtilities = new CategoryUtilities(gManagerWindow); check_hidden(true); run_next_test(); }); @@ -85,6 +88,7 @@ add_test(function() { add_test(function() { restart_manager(gManagerWindow, null, function(aWindow) { gManagerWindow = aWindow; + gCategoryUtilities = new CategoryUtilities(gManagerWindow); check_hidden(false); gExpectedCancel = true; diff --git a/toolkit/mozapps/extensions/test/browser/head.js b/toolkit/mozapps/extensions/test/browser/head.js index 01e7c7ab7de..9e50959f8ac 100644 --- a/toolkit/mozapps/extensions/test/browser/head.js +++ b/toolkit/mozapps/extensions/test/browser/head.js @@ -107,6 +107,79 @@ function restart_manager(aManagerWindow, aView, aCallback) { close_manager(aManagerWindow, function() { open_manager(aView, aCallback); }); } +function CategoryUtilities(aManagerWindow) { + this.window = aManagerWindow; + + var self = this; + this.window.addEventListener("unload", function() { + self.removeEventListener("unload", arguments.callee, false); + self.window = null; + }, false); +} + +CategoryUtilities.prototype = { + window: null, + + get selectedCategory() { + isnot(this.window, null, "Should not get selected category when manager window is not loaded"); + var selectedItem = this.window.document.getElementById("categories").selectedItem; + isnot(selectedItem, null, "A category should be selected"); + var view = this.window.gViewController.parseViewId(selectedItem.value); + return (view.type == "list") ? view.param : view.type; + }, + + get: function(aCategoryType) { + isnot(this.window, null, "Should not get category when manager window is not loaded"); + var categories = this.window.document.getElementById("categories"); + + var viewId = "addons://list/" + aCategoryType; + var items = categories.getElementsByAttribute("value", viewId); + if (items.length) + return items[0]; + + viewId = "addons://" + aCategoryType + "/"; + items = categories.getElementsByAttribute("value", viewId); + if (items.length) + return items[0]; + + ok(false, "Should have found a category with type " + aCategoryType); + return null; + }, + + getViewId: function(aCategoryType) { + isnot(this.window, null, "Should not get view id when manager window is not loaded"); + return this.get(aCategoryType).value; + }, + + isVisible: function(aCategory) { + isnot(this.window, null, "Should not check visible state when manager window is not loaded"); + if (aCategory.hasAttribute("disabled") && + aCategory.getAttribute("disabled") == "true") + return false; + + var style = this.window.document.defaultView.getComputedStyle(aCategory, ""); + return style.display != "none" && style.visibility == "visible"; + }, + + isTypeVisible: function(aCategoryType) { + return this.isVisible(this.get(aCategoryType)); + }, + + open: function(aCategory, aCallback) { + isnot(this.window, null, "Should not open category when manager window is not loaded"); + ok(this.isVisible(aCategory), "Category should be visible if attempting to open it"); + + EventUtils.synthesizeMouse(aCategory, 2, 2, { }, this.window); + + if (aCallback) + wait_for_view_load(this.window, aCallback); + }, + + openType: function(aCategoryType, aCallback) { + this.open(this.get(aCategoryType), aCallback); + }, +} + function CertOverrideListener(host, bits) { this.host = host; this.bits = bits;