Bug 1281952 - Fix addon manager tests to work with async popstate. draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 26 Aug 2016 15:23:16 -0700
changeset 407716 62c752776bc70705d5aaeedc9e2aa379ccc72d15
parent 407715 0299942614ee26e783ad0423e56dacede1e5b273
child 408861 e63d143643a35724813c28ba2c6177d9916cef03
child 409512 0c1942f069ac2fd8c5d716d7fdc64f78c640ec50
push id28025
push userbmo:continuation@gmail.com
push dateTue, 30 Aug 2016 21:19:59 +0000
bugs1281952
milestone51.0a1
Bug 1281952 - Fix addon manager tests to work with async popstate. Make the FakeHistory forward/back equivalents async to match the new popstate behavior. Also, wait_for_view_load normally immediately checks if aManagerWindow.gViewController.isLoading has been set, but with async popstate it won't have been set until return to the event loop again, so pass in aForceWait = true in a bunch of places that do navigation. MozReview-Commit-ID: 34NwwdQYThk
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser_bug562797.js
toolkit/mozapps/extensions/test/browser/browser_types.js
toolkit/mozapps/extensions/test/browser/browser_uninstalling.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -353,27 +353,27 @@ var FakeHistory = {
     return (this.pos + 1) < this.states.length;
   },
 
   back: function() {
     if (this.pos == 0)
       throw Components.Exception("Cannot go back from this point");
 
     this.pos--;
-    gViewController.updateState(this.states[this.pos]);
+    setTimeout(() => { gViewController.updateState(this.states[this.pos]); });
     gViewController.updateCommand("cmd_back");
     gViewController.updateCommand("cmd_forward");
   },
 
   forward: function() {
     if ((this.pos + 1) >= this.states.length)
       throw Components.Exception("Cannot go forward from this point");
 
     this.pos++;
-    gViewController.updateState(this.states[this.pos]);
+    setTimeout(() => { gViewController.updateState(this.states[this.pos]); });
     gViewController.updateCommand("cmd_back");
     gViewController.updateCommand("cmd_forward");
   },
 
   pushState: function(aState) {
     this.pos++;
     this.states.splice(this.pos, this.states.length);
     this.states.push(aState);
@@ -385,17 +385,17 @@ var FakeHistory = {
 
   popState: function() {
     if (this.pos == 0)
       throw Components.Exception("Cannot popState from this view");
 
     this.states.splice(this.pos, this.states.length);
     this.pos--;
 
-    gViewController.updateState(this.states[this.pos]);
+    setTimeout(() => { gViewController.updateState(this.states[this.pos]); });
     gViewController.updateCommand("cmd_back");
     gViewController.updateCommand("cmd_forward");
   }
 };
 
 // If the window has a session history then use the HTML5 History wrapper
 // otherwise use our fake history implementation
 if (window.QueryInterface(Ci.nsIInterfaceRequestor)
--- a/toolkit/mozapps/extensions/test/browser/browser_bug562797.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug562797.js
@@ -213,21 +213,21 @@ add_test(function() {
 
               go_back(aManager);
 
               wait_for_view_load(aManager, function(aManager) {
                 info("Part 7");
                 is_in_list(aManager, "addons://list/extension", false, true);
 
                 close_manager(aManager, run_next_test);
-              });
+              }, true);
             });
-          });
-        });
-      });
+          }, true);
+        }, true);
+      }, true);
     });
   });
 });
 
 // Tests that browsing to the add-ons manager from a website and going back works
 // Only relevant for in-content UI
 add_test(function() {
   if (!gUseInContentUI) {
@@ -339,21 +339,21 @@ add_test(function() {
 
               go_back_backspace(aManager);
 
               wait_for_view_load(aManager, function(aManager) {
                 info("Part 7");
                 is_in_list(aManager, "addons://list/extension", false, true);
 
                 close_manager(aManager, run_next_test);
-              });
+              }, true);
             });
-          });
-        });
-      });
+          }, true);
+        }, true);
+      }, true);
     });
   });
 });
 
 
 // Tests that opening a custom first view only stores a single history entry
 add_test(function() {
   open_manager("addons://list/plugin", function(aManager) {
@@ -368,17 +368,17 @@ add_test(function() {
 
       go_back(aManager);
 
       wait_for_view_load(aManager, function(aManager) {
         info("Part 3");
         is_in_list(aManager, "addons://list/plugin", false, true);
 
         close_manager(aManager, run_next_test);
-      });
+      }, true);
     });
   });
 });
 
 
 // Tests that opening a view while the manager is already open adds a new
 // history entry
 add_test(function() {
@@ -400,18 +400,18 @@ add_test(function() {
 
         go_forward(aManager);
 
         wait_for_view_load(aManager, function(aManager) {
           info("Part 4");
           is_in_list(aManager, "addons://list/plugin", true, false);
 
           close_manager(aManager, run_next_test);
-        });
-      });
+        }, true);
+      }, true);
     });
   });
 });
 
 // Tests than navigating to a website and then going back returns to the
 // previous view
 // Only relevant for in-content UI
 add_test(function() {
@@ -529,18 +529,18 @@ add_test(function() {
           check_all_in_list(aManager, ["test2@tests.mozilla.org", "test3@tests.mozilla.org"]);
 
           go_forward(aManager);
           wait_for_view_load(aManager, function(aManager) {
             info("Part 5");
             is_in_detail(aManager, "addons://search/", true, false);
 
             close_manager(aManager, run_next_test);
-          });
-        });
+          }, true);
+        }, true);
       });
     });
   });
 });
 
 // Tests that going back from a webpage to a detail view loaded from a search
 // result works
 // Only relevant for in-content UI
@@ -593,17 +593,17 @@ add_test(function() {
 
                 go_back(aManager);
                 wait_for_view_load(aManager, function(aManager) {
                   info("Part 6");
                   is_in_search(aManager, "bar", true, true);
                   check_all_in_list(aManager, ["test2@tests.mozilla.org", "test3@tests.mozilla.org"]);
 
                   close_manager(aManager, run_next_test);
-                });
+                }, true);
               });
             }, false);
           });
         }, false);
       });
     });
   });
 });
@@ -637,17 +637,17 @@ add_test(function() {
           is_in_list(aManager, "addons://list/plugin", true, false);
 
           go_back(aManager);
           wait_for_view_load(aManager, function(aManager) {
             info("Part 4");
             is_in_list(aManager, "addons://list/extension", false, true);
 
             close_manager(aManager, run_next_test);
-          });
+          }, true);
         });
       }, false);
     });
   });
 });
 
 // Tests that refreshing a detail view does not affect the history
 // Only relevant for in-content UI
@@ -678,17 +678,17 @@ add_test(function() {
           is_in_detail(aManager, "addons://list/extension", true, false);
 
           go_back(aManager);
           wait_for_view_load(aManager, function(aManager) {
             info("Part 4");
             is_in_list(aManager, "addons://list/extension", false, true);
 
             close_manager(aManager, run_next_test);
-          });
+          }, true);
         });
       }, false);
     });
   });
 });
 
 // Tests that removing an extension from the detail view goes back and doesn't
 // allow you to go forward again.
@@ -711,17 +711,17 @@ add_test(function() {
           // TODO until bug 590661 is fixed the back button will be enabled
           // when displaying in content
           is_in_list(aManager, "addons://list/extension", true, false);
         } else {
           is_in_list(aManager, "addons://list/extension", false, false);
         }
 
         close_manager(aManager, run_next_test);
-      });
+      }, true);
     });
   });
 });
 
 // Tests that the back and forward buttons only show up for windowed mode
 add_test(function() {
   open_manager(null, function(aManager) {
     var doc = aManager.document;
@@ -790,17 +790,17 @@ add_test(function() {
 
               go_back(aManager);
 
               waitForLoad(aManager, function() {
                 is_in_discovery(aManager, MAIN_URL, false, true);
 
                 close_manager(aManager, run_next_test);
               });
-            });
+            }, true);
           });
         });
 
         go_forward(aManager);
       });
 
       go_back(aManager);
     });
@@ -853,20 +853,20 @@ add_test(function() {
 
                       waitForLoad(aManager, function() {
                         is_in_discovery(aManager, SECOND_URL, true, true);
 
                         close_manager(aManager, run_next_test);
                       });
 
                       go_forward(aManager);
-                    });
-                  });
+                    }, true);
+                  }, true);
                 });
-              });
+              }, true);
             });
           });
 
           go_forward(aManager);
         });
 
         go_back(aManager);
       });
@@ -955,17 +955,17 @@ add_test(function() {
                       is_in_discovery(aManager, MAIN_URL, true, false);
 
                       close_manager(aManager, run_next_test);
                     });
                     go_forward(aManager);
                   });
 
                   go_forward(aManager);
-                });
-              });
+                }, true);
+              }, true);
             });
           });
         });
       });
     });
   });
 });
--- a/toolkit/mozapps/extensions/test/browser/browser_types.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_types.js
@@ -177,21 +177,21 @@ add_test(function() {
               check_state(gManagerWindow, true, false);
 
               go_back(gManagerWindow);
               wait_for_view_load(gManagerWindow, function() {
                 is(gCategoryUtilities.selectedCategory, "discover", "Should be back to the default view");
                 check_state(gManagerWindow, true, true);
 
                 close_manager(gManagerWindow, run_next_test);
-              });
-            });
-          });
-        });
-      });
+              }, true);
+            }, true);
+          }, true);
+        }, true);
+      }, true);
     });
   });
 });
 
 // Test that when going back to a now missing category we skip it
 add_test(function() {
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
@@ -210,17 +210,17 @@ add_test(function() {
 
         go_back(gManagerWindow);
 
         wait_for_view_load(gManagerWindow, function() {
           is(gCategoryUtilities.selectedCategory, "extension", "Should be back to the first view");
           check_state(gManagerWindow, false, true);
 
           close_manager(gManagerWindow, run_next_test);
-        });
+        }, true);
       });
     });
   });
 });
 
 // Test that when going forward to a now missing category we skip it
 add_test(function() {
   open_manager("addons://list/extension", function(aWindow) {
@@ -246,21 +246,21 @@ add_test(function() {
 
             go_forward(gManagerWindow);
 
             wait_for_view_load(gManagerWindow, function() {
               is(gCategoryUtilities.selectedCategory, "plugin", "Should be back to the plugin view");
               check_state(gManagerWindow, true, false);
 
               close_manager(gManagerWindow, run_next_test);
-            });
-          });
-        });
+            }, true);
+          }, true);
+        }, true);
       });
-    });
+    }, true);
   });
 });
 
 // Test that when going back to a now missing category and we can't go back any
 // any further then we just display the default view
 add_test(function() {
   AddonManagerPrivate.registerProvider(gProvider, gTypes);
 
@@ -279,17 +279,17 @@ add_test(function() {
 
       go_back(gManagerWindow);
 
       wait_for_view_load(gManagerWindow, function() {
         is(gCategoryUtilities.selectedCategory, "discover", "Should be at the default view");
         check_state(gManagerWindow, false, true);
 
         close_manager(gManagerWindow, run_next_test);
-      });
+      }, true);
     });
   });
 });
 
 // Test that when going forward to a now missing category and we can't go
 // forward any further then we just display the default view
 add_test(function() {
   AddonManagerPrivate.registerProvider(gProvider, gTypes);
@@ -313,18 +313,18 @@ add_test(function() {
 
         go_forward(gManagerWindow);
 
         wait_for_view_load(gManagerWindow, function() {
           is(gCategoryUtilities.selectedCategory, "discover", "Should be at the default view");
           check_state(gManagerWindow, true, false);
 
           close_manager(gManagerWindow, run_next_test);
-        });
-      });
+        }, true);
+      }, true);
     });
   });
 });
 
 // Test that when going back we skip multiple missing categories
 add_test(function() {
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
@@ -344,17 +344,17 @@ add_test(function() {
 
           go_back(gManagerWindow);
 
           wait_for_view_load(gManagerWindow, function() {
             is(gCategoryUtilities.selectedCategory, "extension", "Should be back to the first view");
             check_state(gManagerWindow, false, true);
 
             close_manager(gManagerWindow, run_next_test);
-          });
+          }, true);
         });
       });
     });
   });
 });
 
 // Test that when going forward we skip multiple missing categories
 add_test(function() {
@@ -384,20 +384,20 @@ add_test(function() {
 
                 go_forward(gManagerWindow);
 
                 wait_for_view_load(gManagerWindow, function() {
                   is(gCategoryUtilities.selectedCategory, "plugin", "Should be back to the plugin view");
                   check_state(gManagerWindow, true, false);
 
                   close_manager(gManagerWindow, run_next_test);
-                });
-              });
-            });
-          });
+                }, true);
+              }, true);
+            }, true);
+          }, true);
         });
       });
     });
   });
 });
 
 // Test that when going back we skip all missing categories and when we can't go
 // back any any further then we just display the default view
@@ -420,17 +420,17 @@ add_test(function() {
 
         go_back(gManagerWindow);
 
         wait_for_view_load(gManagerWindow, function() {
           is(gCategoryUtilities.selectedCategory, "discover", "Should be at the default view");
           check_state(gManagerWindow, false, true);
 
           close_manager(gManagerWindow, run_next_test);
-        });
+        }, true);
       });
     });
   });
 });
 
 // Test that when going forward we skip all missing categories and when we can't
 // go back any any further then we just display the default view
 add_test(function() {
@@ -459,15 +459,15 @@ add_test(function() {
 
             go_forward(gManagerWindow);
 
             wait_for_view_load(gManagerWindow, function() {
               is(gCategoryUtilities.selectedCategory, "discover", "Should be at the default view");
               check_state(gManagerWindow, true, false);
 
               close_manager(gManagerWindow, run_next_test);
-            });
-          });
-        });
+            }, true);
+          }, true);
+        }, true);
       });
     });
   });
 });
--- a/toolkit/mozapps/extensions/test/browser/browser_uninstalling.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_uninstalling.js
@@ -484,17 +484,17 @@ add_test(function() {
           item.clientTop;
 
           ok(!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should not be pending uninstall");
           button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
           isnot(button, null, "Should have a remove button");
           ok(!button.disabled, "Button should not be disabled");
 
           run_next_test();
-        });
+        }, true);
       });
     });
   });
 });
 
 // Tests that uninstalling a restartless add-on from the details view switches
 // back to the list view and can be undone
 add_test(function() {
@@ -549,17 +549,17 @@ add_test(function() {
           item.clientTop;
 
           ok(aAddon.isActive, "Add-on should be active");
           button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
           isnot(button, null, "Should have a remove button");
           ok(!button.disabled, "Button should not be disabled");
 
           run_next_test();
-        });
+        }, true);
       });
     });
   });
 });
 
 // Tests that uninstalling a restartless add-on from the details view switches
 // back to the list view and can be undone and doesn't re-enable
 add_test(function() {
@@ -619,18 +619,18 @@ add_test(function() {
           button = gDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
           isnot(button, null, "Should have a remove button");
           ok(!button.disabled, "Button should not be disabled");
 
           aAddon.userDisabled = false;
           ok(aAddon.isActive, "Add-on should be active");
 
           run_next_test();
-        });
-      });
+        }, true);
+      }, true);
     });
   });
 });
 
 // Tests that a normal add-on pending uninstall shows up in the list view
 add_test(function() {
   var ID = "addon1@tests.mozilla.org";
   var list = gDocument.getElementById("addon-list");