B2G/gecko/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
// Complete a search, also testing cancelSearch() and isSearching
Complete a search, also testing cancelSearch() and isSearching
Complete a search also testing cancelSearch () and isSearching
function complete_search(aSearch, aSearchCallback) {
  var failCallback = {
    searchSucceeded: function(addons, length, total) {
      do_throw("failCallback.searchSucceeded should not be called");
      end_test();
    },
    searchFailed: function() {
      do_throw("failCallback.searchFailed should not be called");
      end_test();
    }
  };
  var callbackCalled = false;
  var testCallback = {
    searchSucceeded: function(addons, length, total) {
      do_throw("testCallback.searchSucceeded should not be called");
      end_test();
    },
    searchFailed: function() {
      callbackCalled = true;
    }
  };
  aSearch(failCallback);
  do_check_true(AddonRepository.isSearching);
  AddonRepository.cancelSearch();
  do_check_false(AddonRepository.isSearching);
  aSearch(aSearchCallback);
  do_check_true(AddonRepository.isSearching);
  aSearch(testCallback);
  do_check_true(callbackCalled);
  do_check_true(AddonRepository.isSearching);
}
function complete_search ( aSearch , aSearchCallback ) { var failCallback = { searchSucceeded : function ( addons , length , total ) { do_throw ( "failCallback.searchSucceeded should not be called" ) ; end_test ( ) ; } , searchFailed : function ( ) { do_throw ( "failCallback.searchFailed should not be called" ) ; end_test ( ) ; } } ; var callbackCalled = false ; var testCallback = { searchSucceeded : function ( addons , length , total ) { do_throw ( "testCallback.searchSucceeded should not be called" ) ; end_test ( ) ; } , searchFailed : function ( ) { callbackCalled = true ; } } ; aSearch ( failCallback ) ; do_check_true ( AddonRepository . isSearching ) ; AddonRepository . cancelSearch ( ) ; do_check_false ( AddonRepository . isSearching ) ; aSearch ( aSearchCallback ) ; do_check_true ( AddonRepository . isSearching ) ; aSearch ( testCallback ) ; do_check_true ( callbackCalled ) ; do_check_true ( AddonRepository . isSearching ) ; }
Complete a search, also testing cancelSearch() and isSearching
Complete a search also testing cancelSearch () and isSearching
// Should fail because cancelled it immediately // searchFailed should be called immediately because already searching