Bug 691389 - Error: win is null when performing drag&drop of a XPI file to Add-ons Manager tab. r=dtownsend
authorBlair McBride <bmcbride@mozilla.com>
Thu, 05 Jan 2012 01:17:52 +1300
changeset 85023 52d25037c272a62341f3cd988f2f289585216be3
parent 85022 50c9e7757aa5a045a998fa27f6ae27d7744f3ebc
child 85024 93e89c2fd0964403d910f7b6df968e4f4e1c3220
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend
bugs691389
milestone12.0a1
Bug 691389 - Error: win is null when performing drag&drop of a XPI file to Add-ons Manager tab. r=dtownsend
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser_dragdrop.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -3287,18 +3287,18 @@ var gDragDrop = {
 
     var pos = 0;
     var installs = [];
 
     function buildNextInstall() {
       if (pos == urls.length) {
         if (installs.length > 0) {
           // Display the normal install confirmation for the installs
-          AddonManager.installAddonsFromWebpage("application/x-xpinstall", this,
-                                                null, installs);
+          AddonManager.installAddonsFromWebpage("application/x-xpinstall",
+                                                window, null, installs);
         }
         return;
       }
 
       AddonManager.getInstallForURL(urls[pos++], function(aInstall) {
         installs.push(aInstall);
         buildNextInstall();
       }, "application/x-xpinstall");
--- a/toolkit/mozapps/extensions/test/browser/browser_dragdrop.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_dragdrop.js
@@ -70,16 +70,27 @@ WindowOpenListener.prototype = {
     this.domwindow = null;
 
     // Let the window close complete
     executeSoon(this.closecallback);
     this.closecallback = null;
   }
 };
 
+var gSawInstallNotification = false;
+var gInstallNotificationObserver = {
+  observe: function(aSubject, aTopic, aData) {
+    var installInfo = aSubject.QueryInterface(Ci.amIWebInstallInfo);
+    isnot(installInfo.originatingWindow, null, "Notification should have non-null originatingWindow");
+    gSawInstallNotification = true;
+    Services.obs.removeObserver(this, "addon-install-started");
+  }
+};
+
+
 function test() {
   waitForExplicitFinish();
 
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
     run_next_test();
   });
 }
@@ -108,84 +119,114 @@ function test_confirmation(aWindow, aExp
 
   aWindow.document.documentElement.cancelDialog();
 }
 
 // Simulates dropping a URL onto the manager
 add_test(function() {
   var url = TESTROOT + "addons/browser_dragdrop1.xpi";
 
+  Services.obs.addObserver(gInstallNotificationObserver,
+                           "addon-install-started", false);
+
   new WindowOpenListener(INSTALL_URI, function(aWindow) {
     test_confirmation(aWindow, [url]);
-  }, run_next_test);
+  }, function() {
+    is(gSawInstallNotification, true, "Should have seen addon-install-started notification.");
+    run_next_test();
+  });
 
   var viewContainer = gManagerWindow.document.getElementById("view-port");
   var effect = chromeUtils.synthesizeDrop(viewContainer, viewContainer,
                [[{type: "text/x-moz-url", data: url}]],
                "copy", gManagerWindow, EventUtils);
   is(effect, "copy", "Drag should be accepted");
 });
 
 // Simulates dropping a file onto the manager
 add_test(function() {
   var fileurl = get_addon_file_url("browser_dragdrop1.xpi");
 
+  Services.obs.addObserver(gInstallNotificationObserver,
+                           "addon-install-started", false);
+
   new WindowOpenListener(INSTALL_URI, function(aWindow) {
     test_confirmation(aWindow, [fileurl.spec]);
-  }, run_next_test);
+  }, function() {
+    is(gSawInstallNotification, true, "Should have seen addon-install-started notification.");
+    run_next_test();
+  });
 
   var viewContainer = gManagerWindow.document.getElementById("view-port");
   var effect = chromeUtils.synthesizeDrop(viewContainer, viewContainer,
                [[{type: "application/x-moz-file", data: fileurl.file}]],
                "copy", gManagerWindow, EventUtils);
   is(effect, "copy", "Drag should be accepted");
 });
 
 // Simulates dropping two urls onto the manager
 add_test(function() {
   var url1 = TESTROOT + "addons/browser_dragdrop1.xpi";
   var url2 = TESTROOT2 + "addons/browser_dragdrop2.xpi";
 
+  Services.obs.addObserver(gInstallNotificationObserver,
+                           "addon-install-started", false);
+
   new WindowOpenListener(INSTALL_URI, function(aWindow) {
     test_confirmation(aWindow, [url1, url2]);
-  }, run_next_test);
+  }, function() {
+    is(gSawInstallNotification, true, "Should have seen addon-install-started notification.");
+    run_next_test();
+  });
 
   var viewContainer = gManagerWindow.document.getElementById("view-port");
   var effect = chromeUtils.synthesizeDrop(viewContainer, viewContainer,
                [[{type: "text/x-moz-url", data: url1}],
                 [{type: "text/x-moz-url", data: url2}]],
                "copy", gManagerWindow, EventUtils);
   is(effect, "copy", "Drag should be accepted");
 });
 
 // Simulates dropping two files onto the manager
 add_test(function() {
   var fileurl1 = get_addon_file_url("browser_dragdrop1.xpi");
   var fileurl2 = get_addon_file_url("browser_dragdrop2.xpi");
 
+  Services.obs.addObserver(gInstallNotificationObserver,
+                           "addon-install-started", false);
+
   new WindowOpenListener(INSTALL_URI, function(aWindow) {
     test_confirmation(aWindow, [fileurl1.spec, fileurl2.spec]);
-  }, run_next_test);
+  }, function() {
+    is(gSawInstallNotification, true, "Should have seen addon-install-started notification.");
+    run_next_test();
+  });
 
   var viewContainer = gManagerWindow.document.getElementById("view-port");
   var effect = chromeUtils.synthesizeDrop(viewContainer, viewContainer,
                [[{type: "application/x-moz-file", data: fileurl1.file}],
                 [{type: "application/x-moz-file", data: fileurl2.file}]],
                "copy", gManagerWindow, EventUtils);
   is(effect, "copy", "Drag should be accepted");
 });
 
 // Simulates dropping a file and a url onto the manager (weird, but should still work)
 add_test(function() {
   var url = TESTROOT + "addons/browser_dragdrop1.xpi";
   var fileurl = get_addon_file_url("browser_dragdrop2.xpi");
 
+  Services.obs.addObserver(gInstallNotificationObserver,
+                           "addon-install-started", false);
+
   new WindowOpenListener(INSTALL_URI, function(aWindow) {
     test_confirmation(aWindow, [url, fileurl.spec]);
-  }, run_next_test);
+  }, function() {
+    is(gSawInstallNotification, true, "Should have seen addon-install-started notification.");
+    run_next_test();
+  });
 
   var viewContainer = gManagerWindow.document.getElementById("view-port");
   var effect = chromeUtils.synthesizeDrop(viewContainer, viewContainer,
                [[{type: "text/x-moz-url", data: url}],
                 [{type: "application/x-moz-file", data: fileurl.file}]],
                "copy", gManagerWindow, EventUtils);
   is(effect, "copy", "Drag should be accepted");
 });