зеркало из https://github.com/mozilla/pjs.git
Bug 578580: Add category utilities for add-ons manager browser tests. r=dtownsend
This commit is contained in:
Родитель
8ef041030c
Коммит
e0e423ebc7
|
@ -10,6 +10,7 @@ Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
|
||||||
const xpi = "browser/toolkit/mozapps/extensions/test/browser/browser_installssl.xpi";
|
const xpi = "browser/toolkit/mozapps/extensions/test/browser/browser_installssl.xpi";
|
||||||
|
|
||||||
var gManagerWindow;
|
var gManagerWindow;
|
||||||
|
var gCategoryUtilities;
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
waitForExplicitFinish();
|
waitForExplicitFinish();
|
||||||
|
@ -23,6 +24,7 @@ function test() {
|
||||||
|
|
||||||
open_manager(null, function(aWindow) {
|
open_manager(null, function(aWindow) {
|
||||||
gManagerWindow = aWindow;
|
gManagerWindow = aWindow;
|
||||||
|
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
|
||||||
run_next_test();
|
run_next_test();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -39,26 +41,21 @@ function end_test() {
|
||||||
add_test(function() {
|
add_test(function() {
|
||||||
var themeCount = null;
|
var themeCount = null;
|
||||||
var pluginCount = null;
|
var pluginCount = null;
|
||||||
var themeItem = gManagerWindow.document.getElementById("category-themes");
|
var themeItem = gCategoryUtilities.get("theme");
|
||||||
var pluginItem = gManagerWindow.document.getElementById("category-plugins");
|
var pluginItem = gCategoryUtilities.get("plugin");
|
||||||
var list = gManagerWindow.document.getElementById("addon-list");
|
var list = gManagerWindow.document.getElementById("addon-list");
|
||||||
|
|
||||||
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
|
gCategoryUtilities.open(themeItem, function() {
|
||||||
|
|
||||||
wait_for_view_load(gManagerWindow, function() {
|
|
||||||
themeCount = list.childNodes.length;
|
themeCount = list.childNodes.length;
|
||||||
ok(themeCount > 0, "Test is useless if there are no themes");
|
ok(themeCount > 0, "Test is useless if there are no themes");
|
||||||
|
|
||||||
EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow);
|
gCategoryUtilities.open(pluginItem, function() {
|
||||||
|
|
||||||
wait_for_view_load(gManagerWindow, function() {
|
|
||||||
pluginCount = list.childNodes.length;
|
pluginCount = list.childNodes.length;
|
||||||
ok(pluginCount > 0, "Test is useless if there are no plugins");
|
ok(pluginCount > 0, "Test is useless if there are no plugins");
|
||||||
|
|
||||||
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
|
gCategoryUtilities.open(themeItem);
|
||||||
EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow);
|
|
||||||
|
|
||||||
wait_for_view_load(gManagerWindow, function() {
|
gCategoryUtilities.open(pluginItem, function() {
|
||||||
is(list.childNodes.length, pluginCount, "Should only see the plugins");
|
is(list.childNodes.length, pluginCount, "Should only see the plugins");
|
||||||
|
|
||||||
var item = list.firstChild;
|
var item = list.firstChild;
|
||||||
|
@ -70,11 +67,9 @@ add_test(function() {
|
||||||
// Tests that switching to, from, to the same pane in quick succession
|
// Tests that switching to, from, to the same pane in quick succession
|
||||||
// still only shows the right number of results
|
// still only shows the right number of results
|
||||||
|
|
||||||
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
|
gCategoryUtilities.open(themeItem);
|
||||||
EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow);
|
gCategoryUtilities.open(pluginItem);
|
||||||
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
|
gCategoryUtilities.open(themeItem, function() {
|
||||||
|
|
||||||
wait_for_view_load(gManagerWindow, function() {
|
|
||||||
is(list.childNodes.length, themeCount, "Should only see the theme");
|
is(list.childNodes.length, themeCount, "Should only see the theme");
|
||||||
|
|
||||||
var item = list.firstChild;
|
var item = list.firstChild;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
// installed but some are pending install
|
// installed but some are pending install
|
||||||
|
|
||||||
var gManagerWindow;
|
var gManagerWindow;
|
||||||
|
var gCategoryUtilities;
|
||||||
var gProvider;
|
var gProvider;
|
||||||
var gInstallProperties = [{
|
var gInstallProperties = [{
|
||||||
name: "Locale Category Test",
|
name: "Locale Category Test",
|
||||||
|
@ -41,6 +42,7 @@ function test() {
|
||||||
|
|
||||||
open_manager(null, function(aWindow) {
|
open_manager(null, function(aWindow) {
|
||||||
gManagerWindow = aWindow;
|
gManagerWindow = aWindow;
|
||||||
|
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
|
||||||
run_next_test();
|
run_next_test();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -52,8 +54,8 @@ function end_test() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_hidden(aExpectedHidden) {
|
function check_hidden(aExpectedHidden) {
|
||||||
var category = gManagerWindow.gCategories.get("addons://list/locale");
|
var hidden = !gCategoryUtilities.isTypeVisible("locale");
|
||||||
is(category.hidden, aExpectedHidden, "Should have correct hidden state");
|
is(hidden, aExpectedHidden, "Should have correct hidden state");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that a non-active install does not make the locale category show
|
// Tests that a non-active install does not make the locale category show
|
||||||
|
@ -70,6 +72,7 @@ add_test(function() {
|
||||||
add_test(function() {
|
add_test(function() {
|
||||||
restart_manager(gManagerWindow, null, function(aWindow) {
|
restart_manager(gManagerWindow, null, function(aWindow) {
|
||||||
gManagerWindow = aWindow;
|
gManagerWindow = aWindow;
|
||||||
|
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
|
||||||
check_hidden(true);
|
check_hidden(true);
|
||||||
run_next_test();
|
run_next_test();
|
||||||
});
|
});
|
||||||
|
@ -85,6 +88,7 @@ add_test(function() {
|
||||||
add_test(function() {
|
add_test(function() {
|
||||||
restart_manager(gManagerWindow, null, function(aWindow) {
|
restart_manager(gManagerWindow, null, function(aWindow) {
|
||||||
gManagerWindow = aWindow;
|
gManagerWindow = aWindow;
|
||||||
|
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
|
||||||
check_hidden(false);
|
check_hidden(false);
|
||||||
|
|
||||||
gExpectedCancel = true;
|
gExpectedCancel = true;
|
||||||
|
|
|
@ -107,6 +107,79 @@ function restart_manager(aManagerWindow, aView, aCallback) {
|
||||||
close_manager(aManagerWindow, function() { open_manager(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) {
|
function CertOverrideListener(host, bits) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.bits = bits;
|
this.bits = bits;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче