2010-09-10 10:20:38 -07:00
|
|
|
var rootDir = getRootDirectory(gTestPath);
|
|
|
|
const gTestRoot = rootDir;
|
2008-10-30 12:21:23 -07:00
|
|
|
|
|
|
|
var gTestBrowser = null;
|
|
|
|
var gNextTest = null;
|
|
|
|
|
|
|
|
function get_test_plugin() {
|
2010-04-02 00:20:42 -07:00
|
|
|
var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
2009-11-09 13:11:58 -08:00
|
|
|
var tags = ph.getPluginTags();
|
2010-04-29 10:19:17 -07:00
|
|
|
|
2008-10-30 12:21:23 -07:00
|
|
|
// Find the test plugin
|
|
|
|
for (var i = 0; i < tags.length; i++) {
|
|
|
|
if (tags[i].name == "Test Plug-in")
|
|
|
|
return tags[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-29 10:19:17 -07:00
|
|
|
// This listens for the next opened tab and checks it is of the right url.
|
|
|
|
// opencallback is called when the new tab is fully loaded
|
|
|
|
// closecallback is called when the tab is closed
|
|
|
|
function TabOpenListener(url, opencallback, closecallback) {
|
2008-10-30 12:21:23 -07:00
|
|
|
this.url = url;
|
|
|
|
this.opencallback = opencallback;
|
|
|
|
this.closecallback = closecallback;
|
|
|
|
|
2010-04-29 10:19:17 -07:00
|
|
|
gBrowser.tabContainer.addEventListener("TabOpen", this, false);
|
2008-10-30 12:21:23 -07:00
|
|
|
}
|
|
|
|
|
2010-04-29 10:19:17 -07:00
|
|
|
TabOpenListener.prototype = {
|
2008-10-30 12:21:23 -07:00
|
|
|
url: null,
|
|
|
|
opencallback: null,
|
|
|
|
closecallback: null,
|
2010-04-29 10:19:17 -07:00
|
|
|
tab: null,
|
|
|
|
browser: null,
|
2008-10-30 12:21:23 -07:00
|
|
|
|
|
|
|
handleEvent: function(event) {
|
2010-04-29 10:19:17 -07:00
|
|
|
if (event.type == "TabOpen") {
|
|
|
|
gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
|
|
|
|
this.tab = event.originalTarget;
|
|
|
|
this.browser = this.tab.linkedBrowser;
|
2010-06-15 11:40:05 -07:00
|
|
|
gBrowser.addEventListener("pageshow", this, false);
|
|
|
|
} else if (event.type == "pageshow") {
|
|
|
|
if (event.target.location.href != this.url)
|
|
|
|
return;
|
|
|
|
gBrowser.removeEventListener("pageshow", this, false);
|
2010-04-29 10:19:17 -07:00
|
|
|
this.tab.addEventListener("TabClose", this, false);
|
|
|
|
var url = this.browser.contentDocument.location.href;
|
|
|
|
is(url, this.url, "Should have opened the correct tab");
|
2010-06-15 11:40:05 -07:00
|
|
|
this.opencallback(this.tab, this.browser.contentWindow);
|
2010-04-29 10:19:17 -07:00
|
|
|
} else if (event.type == "TabClose") {
|
|
|
|
if (event.originalTarget != this.tab)
|
|
|
|
return;
|
|
|
|
this.tab.removeEventListener("TabClose", this, false);
|
|
|
|
this.opencallback = null;
|
|
|
|
this.tab = null;
|
|
|
|
this.browser = null;
|
|
|
|
// Let the window close complete
|
|
|
|
executeSoon(this.closecallback);
|
|
|
|
this.closecallback = null;
|
|
|
|
}
|
2008-10-30 12:21:23 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
var newTab = gBrowser.addTab();
|
|
|
|
gBrowser.selectedTab = newTab;
|
|
|
|
gTestBrowser = gBrowser.selectedBrowser;
|
|
|
|
gTestBrowser.addEventListener("load", pageLoad, true);
|
|
|
|
prepareTest(test1, gTestRoot + "plugin_unknown.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
function finishTest() {
|
|
|
|
gTestBrowser.removeEventListener("load", pageLoad, true);
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
window.focus();
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
function pageLoad() {
|
|
|
|
// The plugin events are async dispatched and can come after the load event
|
|
|
|
// This just allows the events to fire before we then go on to test the states
|
|
|
|
executeSoon(gNextTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareTest(nextTest, url) {
|
|
|
|
gNextTest = nextTest;
|
|
|
|
gTestBrowser.contentWindow.location = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a page with an unknown plugin in it.
|
|
|
|
function test1() {
|
|
|
|
var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
|
|
|
|
ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 1, Should have displayed the missing plugin notification");
|
|
|
|
ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 1, Should not have displayed the blocked plugin notification");
|
|
|
|
ok(gTestBrowser.missingPlugins, "Test 1, Should be a missing plugin list");
|
|
|
|
ok("application/x-unknown" in gTestBrowser.missingPlugins, "Test 1, Should know about application/x-unknown");
|
|
|
|
ok(!("application/x-test" in gTestBrowser.missingPlugins), "Test 1, Should not know about application/x-test");
|
|
|
|
|
|
|
|
var plugin = get_test_plugin();
|
|
|
|
ok(plugin, "Should have a test plugin");
|
|
|
|
plugin.disabled = false;
|
|
|
|
plugin.blocklisted = false;
|
|
|
|
prepareTest(test2, gTestRoot + "plugin_test.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a page with a working plugin in it.
|
|
|
|
function test2() {
|
|
|
|
var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
|
|
|
|
ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 2, Should not have displayed the missing plugin notification");
|
|
|
|
ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 2, Should not have displayed the blocked plugin notification");
|
|
|
|
ok(!gTestBrowser.missingPlugins, "Test 2, Should not be a missing plugin list");
|
|
|
|
|
|
|
|
var plugin = get_test_plugin();
|
|
|
|
ok(plugin, "Should have a test plugin");
|
|
|
|
plugin.disabled = true;
|
|
|
|
prepareTest(test3, gTestRoot + "plugin_test.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a page with a disabled plugin in it.
|
|
|
|
function test3() {
|
|
|
|
var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
|
|
|
|
ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 3, Should not have displayed the missing plugin notification");
|
|
|
|
ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 3, Should not have displayed the blocked plugin notification");
|
|
|
|
ok(!gTestBrowser.missingPlugins, "Test 3, Should not be a missing plugin list");
|
|
|
|
|
2010-04-29 10:19:17 -07:00
|
|
|
new TabOpenListener("about:addons", test4, prepareTest5);
|
2008-10-30 12:21:23 -07:00
|
|
|
|
2011-05-22 18:46:33 -07:00
|
|
|
var pluginNode = gTestBrowser.contentDocument.getElementById("test");
|
|
|
|
ok(pluginNode, "Test 3, Found plugin in page");
|
|
|
|
var manageLink = gTestBrowser.contentDocument.getAnonymousElementByAttribute(pluginNode, "class", "managePluginsLink");
|
|
|
|
ok(manageLink, "Test 3, found 'manage' link in plugin-problem binding");
|
|
|
|
|
|
|
|
EventUtils.synthesizeMouse(manageLink,
|
2010-08-21 17:55:55 -07:00
|
|
|
5, 5, {}, gTestBrowser.contentWindow);
|
2008-10-30 12:21:23 -07:00
|
|
|
}
|
|
|
|
|
2010-04-29 10:19:17 -07:00
|
|
|
function test4(tab, win) {
|
2010-06-15 11:40:05 -07:00
|
|
|
is(win.wrappedJSObject.gViewController.currentViewId, "addons://list/plugin", "Should have displayed the plugins pane");
|
2010-04-29 10:19:17 -07:00
|
|
|
gBrowser.removeTab(tab);
|
2008-10-30 12:21:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepareTest5() {
|
|
|
|
var plugin = get_test_plugin();
|
|
|
|
plugin.disabled = false;
|
|
|
|
plugin.blocklisted = true;
|
|
|
|
prepareTest(test5, gTestRoot + "plugin_test.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a page with a blocked plugin in it.
|
|
|
|
function test5() {
|
|
|
|
var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
|
|
|
|
ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 5, Should not have displayed the missing plugin notification");
|
|
|
|
ok(notificationBox.getNotificationWithValue("blocked-plugins"), "Test 5, Should have displayed the blocked plugin notification");
|
|
|
|
ok(gTestBrowser.missingPlugins, "Test 5, Should be a missing plugin list");
|
|
|
|
ok("application/x-test" in gTestBrowser.missingPlugins, "Test 5, Should know about application/x-test");
|
|
|
|
ok(!("application/x-unknown" in gTestBrowser.missingPlugins), "Test 5, Should not know about application/x-unknown");
|
|
|
|
|
|
|
|
prepareTest(test6, gTestRoot + "plugin_both.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a page with a blocked and unknown plugin in it.
|
|
|
|
function test6() {
|
|
|
|
var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
|
|
|
|
ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 6, Should have displayed the missing plugin notification");
|
|
|
|
ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 6, Should not have displayed the blocked plugin notification");
|
|
|
|
ok(gTestBrowser.missingPlugins, "Test 6, Should be a missing plugin list");
|
|
|
|
ok("application/x-unknown" in gTestBrowser.missingPlugins, "Test 6, Should know about application/x-unknown");
|
|
|
|
ok("application/x-test" in gTestBrowser.missingPlugins, "Test 6, Should know about application/x-test");
|
|
|
|
|
|
|
|
prepareTest(test7, gTestRoot + "plugin_both2.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a page with a blocked and unknown plugin in it (alternate order to above).
|
|
|
|
function test7() {
|
|
|
|
var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
|
|
|
|
ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 7, Should have displayed the missing plugin notification");
|
|
|
|
ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 7, Should not have displayed the blocked plugin notification");
|
|
|
|
ok(gTestBrowser.missingPlugins, "Test 7, Should be a missing plugin list");
|
|
|
|
ok("application/x-unknown" in gTestBrowser.missingPlugins, "Test 7, Should know about application/x-unknown");
|
|
|
|
ok("application/x-test" in gTestBrowser.missingPlugins, "Test 7, Should know about application/x-test");
|
|
|
|
|
|
|
|
var plugin = get_test_plugin();
|
|
|
|
plugin.disabled = false;
|
|
|
|
plugin.blocklisted = false;
|
|
|
|
finishTest();
|
|
|
|
}
|