forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addons.js
1284 lines (1129 loc) · 40.5 KB
/
addons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http:https://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is MozMill Test code.
*
* The Initial Developer of the Original Code is the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Henrik Skupin <[email protected]>
* Geo Mealer <[email protected]>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Include required modules
var domUtils = require("dom-utils");
var prefs = require("prefs");
var tabs = require("tabs");
var utils = require("utils");
const TIMEOUT = 5000;
const TIMEOUT_DOWNLOAD = 15000;
const TIMEOUT_SEARCH = 30000;
var pm = Cc["@mozilla.org/permissionmanager;1"].
getService(Ci.nsIPermissionManager);
// AMO Preview site
const AMO_PREVIEW_DOMAIN = "addons.allizom.org";
const AMO_PREVIEW_SITE = "https://" + AMO_PREVIEW_DOMAIN;
// Available search filters
const SEARCH_FILTER = [
"local",
"remote"
];
// Preferences which have to be changed to make sure we do not interact with the
// official AMO page but the preview site instead
const AMO_PREFERENCES = [
{name: "extensions.getAddons.browseAddons", old: "addons.mozilla.org", new: AMO_PREVIEW_DOMAIN},
{name: "extensions.getAddons.recommended.browseURL", old: "addons.mozilla.org", new: AMO_PREVIEW_DOMAIN},
{name: "extensions.getAddons.recommended.url", old: "services.addons.mozilla.org", new: AMO_PREVIEW_DOMAIN},
{name: "extensions.getAddons.search.browseURL", old: "addons.mozilla.org", new: AMO_PREVIEW_DOMAIN},
{name: "extensions.getAddons.search.url", old: "services.addons.mozilla.org", new: AMO_PREVIEW_DOMAIN},
{name: "extensions.getMoreThemesURL", old: "addons.mozilla.org", new: AMO_PREVIEW_DOMAIN}
];
/**
* Constructor
*/
function addonsManager(aController) {
this._controller = aController;
this._tabBrowser = new tabs.tabBrowser(this._controller);
}
/**
* Addons Manager class
*/
addonsManager.prototype = {
///////////////////////////////
// Global section
///////////////////////////////
/**
* Get the controller of the window
*
* @returns Mozmill Controller
* @type {MozMillController}
*/
get controller() {
return this._controller;
},
/**
* Gets all the needed external DTD urls as an array
*
* @returns URL's of external DTD files
* @type {array of string}
*/
get dtds() {
var dtds = [
"chrome:https://mozapps/locale/extensions/extensions.dtd",
"chrome:https://browser/locale/browser.dtd"
];
return dtds;
},
/**
* Open the Add-ons Manager
*
* @param {object} aSpec
* Information how to open the Add-ons Manager
* Elements: type - Event, can be menu, or shortcut
* [optional - default: menu]
* waitFor - Wait until the Add-ons Manager has been opened
* [optional - default: true]
*
*
* @returns Reference the tab with the Add-ons Manager open
* @type {object}
* Elements: controller - Mozmill Controller of the window
* index - Index of the tab
*/
open : function addonsManager_open(aSpec) {
var spec = aSpec || { };
var type = (spec.type == undefined) ? "menu" : spec.type;
var waitFor = (spec.waitFor == undefined) ? true : spec.waitFor;
switch (type) {
case "menu":
var menuItem = new elementslib.Elem(this._controller.
menus["tools-menu"].menu_openAddons);
this._controller.click(menuItem);
break;
case "shortcut":
var cmdKey = utils.getEntity(this.dtds, "addons.commandkey");
this._controller.keypress(null, cmdKey, {accelKey: true, shiftKey: true});
break;
default:
throw new Error(arguments.callee.name + ": Unknown event type - " +
event.type);
}
return waitFor ? this.waitForOpened() : null;
},
/**
* Check if the Add-ons Manager is open
*
* @returns True if the Add-ons Manager is open
* @type {boolean}
*/
get isOpen() {
return (this.getTabs().length > 0);
},
/**
* Waits until the Addons Manager has been opened and returns its controller
*
* @param {object} aSpec
* Object with parameters for customization
* Elements: timeout - Duration to wait for the target state
* [optional - default: 5s]
*
* @returns Currently selected tab
*/
waitForOpened : function addonsManager_waitforOpened(aSpec) {
var spec = aSpec || { };
var timeout = (spec.timeout == undefined) ? TIMEOUT : spec.timeout;
// TODO: restore after 1.5.1 has landed
// var self = this;
//
// mozmill.utils.waitFor(function() {
// return self.isOpen;
// }, timeout, 100, "Add-ons Manager has been opened");
mozmill.utils.waitForEval("subject.isOpen", timeout, 100, this);
// The first tab found will be the selected one
var tab = this.getTabs()[0];
tab.controller.waitForPageLoad();
return tab;
},
/**
* Close the Addons Manager
*
* @param {object} aSpec
* Information about the event to send
* Elements: type - Event type (closeButton, menu, middleClick, shortcut)
*/
close : function addonsManager_close(aSpec) {
this._tabBrowser.closeTab(aSpec);
},
/**
* Retrieves the list of open add-ons manager tabs
*
* @returns List of open tabs
* @type {array of object}
* Elements: controller - MozMillController
* index - Index of the tab
*/
getTabs : function addonsManager_getTabs() {
return tabs.getTabsWithURL("about:addons");
},
/**
* Opens the utils button menu and clicks the specified menu entry
*
* @param {object} aSpec
* Information about the menu
* Elements: item - menu item to click (updateNow, viewUpdates,
* installFromFile, autoUpdateDefault,
* resetAddonUpdatesToAutomatic,
* resetAddonUpdatesToManual)
*/
handleUtilsButton : function addonsManager_handleUtilsButton(aSpec) {
var spec = aSpec || { };
var item = spec.item;
if (!item)
throw new Error(arguments.callee.name + ": Menu item not specified.");
var button = this.getElement({type: "utilsButton"});
var menu = this.getElement({type: "utilsButton_menu"});
try {
this._controller.click(button);
// Click the button and wait until menu has been opened
// TODO: restore after 1.5.1 has landed
// mozmill.utils.waitFor(function() {
// return menu.getNode() && menu.getNode().state == "open";
// }, TIMEOUT, 100, "Menu of utils button has been opened.");
mozmill.utils.waitForEval("subject && subject.state == 'open'",
TIMEOUT, 100, menu.getNode());
// Click the given menu entry and make sure the
var menuItem = this.getElement({
type: "utilsButton_menuItem",
value: "#utils-" + item
});
this._controller.click(menuItem);
} finally {
// Make sure the menu has been closed
this._controller.keypress(menu, "VK_ESCAPE", {});
// TODO: restore after 1.5.1 has landed
// mozmill.utils.waitFor(function() {
// return menu.getNode() && menu.getNode().state == "closed";
// }, TIMEOUT, 100, "Menu of utils button has been closed.");
mozmill.utils.waitForEval("subject && subject.state == 'closed'",
TIMEOUT, 100, menu.getNode());
}
},
///////////////////////////////
// Add-on section
///////////////////////////////
/**
* Check if the specified add-on is compatible
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
*
* @returns True if the add-on is compatible
* @type {ElemBase}
*/
isAddonCompatible : function addonsManager_isAddonCompatible(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
if (!addon)
throw new Error(arguments.callee.name + ": Add-on not specified.");
// XXX: Bug 599702 doens't give enough information which type of notification
return addon.getNode().getAttribute("notification") != "warning";
},
/**
* Check if the specified add-on is enabled
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
*
* @returns True if the add-on is enabled
* @type {ElemBase}
*/
isAddonEnabled : function addonsManager_isAddonEnabled(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
if (!addon)
throw new Error(arguments.callee.name + ": Add-on not specified.");
return addon.getNode().getAttribute("active") == "true";
},
/**
* Check if the specified add-on is installed
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
*
* @returns True if the add-on is installed
* @type {ElemBase}
*/
isAddonInstalled : function addonsManager_isAddonInstalled(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
if (!addon)
throw new Error(arguments.callee.name + ": Add-on not specified.");
// Bug 600502 : Add-ons in search view are not initialized correctly
return addon.getNode().getAttribute("remote") == "false" &&
addon.getNode().getAttribute("status") == "installed";
},
/**
* Enables the specified add-on
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
*/
enableAddon : function addonsManager_enableAddon(aSpec) {
var spec = aSpec || { };
spec.button = "enable";
var button = this.getAddonButton(spec);
this._controller.click(button);
},
/**
* Disables the specified add-on
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
*/
disableAddon : function addonsManager_disableAddon(aSpec) {
var spec = aSpec || { };
spec.button = "disable";
var button = this.getAddonButton(spec);
this._controller.click(button);
},
/**
* Installs the specified add-on
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
* waitFor - Wait until the category has been selected
* [optional - default: true]
* timeout - Duration to wait for the download
* [optional - default: 15s]
*/
installAddon : function addonsManager_installAddon(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
var timeout = spec.timeout;
var button = "install";
var waitFor = (spec.waitFor == undefined) ? true : spec.waitFor;
var button = this.getAddonButton({addon: addon, button: button});
this._controller.click(button);
if (waitFor)
this.waitForDownloaded({addon: addon, timeout: timeout});
},
/**
* Removes the specified add-on
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
*/
removeAddon : function addonsManager_removeAddon(aSpec) {
var spec = aSpec || { };
spec.button = "remove";
var button = this.getAddonButton(spec);
this._controller.click(button);
},
/**
* Undo the last action performed for the given add-on
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
*/
undo : function addonsManager_undo(aSpec) {
var spec = aSpec || { };
spec.link = "undo";
var link = this.getAddonLink(spec);
this._controller.click(link);
},
/**
* Returns the addons from the currently selected view which match the
* filter criteria
*
* @param {object} aSpec
* Information about the filter to apply
* Elements: attribute - DOM attribute of the wanted addon
* [optional - default: ""]
* value - Value of the DOM attribute
* [optional - default: ""]
*
* @returns List of addons
* @type {array of ElemBase}
*/
getAddons : function addonsManager_addons(aSpec) {
var spec = aSpec || {};
return this.getElements({
type: "addons",
subtype: spec.attribute,
value: spec.value,
parent: this.selectedView
});
},
/**
* Returns the element of the specified add-ons button
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
* button - Button (disable, enable, preferences, remove)
*
* @returns Add-on button
* @type {ElemBase}
*/
getAddonButton : function addonsManager_getAddonButton(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
var button = spec.button;
if (!button)
throw new Error(arguments.callee.name + ": Button not specified.");
return this.getAddonChildElement({addon: addon, type: button + "Button"});
},
/**
* Returns the element of the specified add-ons link
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
* link - Link
* List view (more, restart, undo)
* Detail view (findUpdates, restart, undo)
*
* @return Add-on link
* @type {ElemBase}
*/
getAddonLink : function addonsManager_getAddonLink(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
var link = spec.link;
if (!link)
throw new Error(arguments.callee.name + ": Link not specified.");
return this.getAddonChildElement({addon: addon, type: link + "Link"});
},
/**
* Returns the element of the specified add-ons radio group
*
* @param {object} aSpec
* Information on which add-on to operate on
* Elements: addon - Add-on element
* radiogroup - Radiogroup
* Detail View (autoUpdate)
*
* @returns Add-on radiogroup
* @type {ElemBase}
*/
getAddonRadiogroup : function addonsManager_getAddonRadiogroup(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
var radiogroup = spec.radiogroup;
if (!radiogroup)
throw new Error(arguments.callee.name + ": Radiogroup not specified.");
return this.getAddonChildElement({addon: addon, type: radiogroup + "Radiogroup"});
},
/**
* Retrieve the given child element of the specified add-on
*
* @param {object} aSpec
* Information for getting the add-ons child node
* Elements: addon - Add-on element
* type - Type of the element
* [optional - default: use attribute/value]
* attribute - DOM attribute of the node
* value - Value of the DOM attribute
*
* @returns Element
* @type {ElemBase}
*/
getAddonChildElement : function addonsManager_getAddonChildElement(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
var attribute = spec.attribute;
var value = spec.value;
var type = spec.type;
if (!addon)
throw new Error(arguments.callee.name + ": Add-on not specified.");
// If no type has been set retrieve a general element which needs an
// attribute and value
if (!type) {
type = "element";
if (!attribute)
throw new Error(arguments.callee.name + ": DOM attribute not specified.");
if (!value)
throw new Error(arguments.callee.name + ": Value not specified.");
}
// For the details view the elements don't have anonymous nodes
if (this.selectedView.getNode().id == "detail-view") {
return this.getElement({
type: "detailView_" + type,
subtype: attribute,
value: value
});
} else {
return this.getElement({
type: "listView_" + type,
subtype: attribute,
value: value,
parent: addon
});
}
},
/**
* Wait until the specified add-on has been downloaded
*
* @param {object} aSpec
* Object with parameters for customization
* Elements: addon - Add-on element to wait for being downloaded
* timeout - Duration to wait for the target state
* [optional - default: 15s]
*/
waitForDownloaded : function addonsManager_waitForDownloaded(aSpec) {
var spec = aSpec || { };
var addon = spec.addon;
var timeout = (spec.timeout == undefined) ? TIMEOUT_DOWNLOAD : spec.timeout;
if (!addon)
throw new Error(arguments.callee.name + ": Add-on not specified.");
var self = this;
var node = addon.getNode();
// TODO: restore after 1.5.1 has landed
// mozmill.utils.waitFor(function () {
// return node.getAttribute("pending") == "install" &&
// node.getAttribute("status") != "installing";
// }, timeout, 100, "'" + node.getAttribute("name") + "' has been downloaded");
mozmill.utils.waitForEval("subject.getAttribute('pending') == 'install' &&" +
"subject.getAttribute('status') != 'installing'",
timeout, 100, node);
},
///////////////////////////////
// Category section
///////////////////////////////
/**
* Retrieve the currently selected category
*
* @returns Element which represents the currently selected category
* @type {ElemBase}
*/
get selectedCategory() {
return this.getCategories({attribute: "selected", value: "true"})[0];
},
/**
* Returns the categories which match the filter criteria
*
* @param {object} aSpec
* Information about the filter to apply
* Elements: attribute - DOM attribute of the wanted category
* [optional - default: ""]
* value - Value of the DOM attribute
* [optional - default: ""]
*
* @returns List of categories
* @type {array of ElemBase}
*/
getCategories : function addonsManager_categories(aSpec) {
var spec = aSpec || { };
var categories = this.getElements({
type: "categories",
subtype: spec.attribute,
value: spec.value
});
if (categories.length == 0)
throw new Error(arguments.callee.name + ": Categories could not be found.");
return categories;
},
/**
* Get the category element for the specified id
*
* @param {object} aSpec
* Information for getting a category
* Elements: id - Category id (search, discover, languages,
* searchengines, extensions, themes, plugins,
* availableUpdates, recentUpdates)
*
* @returns Category
* @type {ElemBase}
*/
getCategoryById : function addonsManager_getCategoryById(aSpec) {
var spec = aSpec || { };
var id = spec.id;
if (!id)
throw new Error(arguments.callee.name + ": Category ID not specified.");
return this.getCategories({
attribute: "id",
value: "category-" + id
})[0];
},
/**
* Get the ID of the given category element
*
* @param {object} aSpec
* Information for getting a category
* Elements: category - Category to get the id from
*
* @returns Category Id
* @type {string}
*/
getCategoryId : function addonsManager_getCategoryId(aSpec) {
var spec = aSpec || { };
var category = spec.category;
if (!category)
throw new Error(arguments.callee.name + ": Category not specified.");
return category.getNode().id;
},
/**
* Select the given category
*
* @param {object} aSpec
* Information for selecting a category
* Elements: category - Category element
* waitFor - Wait until the category has been selected
* [optional - default: true]
*/
setCategory : function addonsManager_setCategory(aSpec) {
var spec = aSpec || { };
var category = spec.category;
var waitFor = (spec.waitFor == undefined) ? true : spec.waitFor;
if (!category)
throw new Error(arguments.callee.name + ": Category not specified.");
this._controller.click(category);
if (waitFor)
this.waitForCategory({category: category});
},
/**
* Select the category with the given id
*
* @param {object} aSpec
* Information for selecting a category
* Elements: id - Category id (search, discover, languages,
* searchengines, extensions, themes, plugins,
* availableUpdates, recentUpdates)
* waitFor - Wait until the category has been selected
* [optional - default: true]
*/
setCategoryById : function addonsManager_setCategoryById(aSpec) {
var spec = aSpec || { };
var id = spec.id;
var waitFor = (spec.waitFor == undefined) ? true : spec.waitFor;
if (!id)
throw new Error(arguments.callee.name + ": Category ID not specified.");
// Retrieve the category and set it as active
var category = this.getCategoryById({id: id});
if (category)
this.setCategory({category: category, waitFor: waitFor});
else
throw new Error(arguments.callee.name + ": Category '" + id + " not found.");
},
/**
* Wait until the specified category has been selected
*
* @param {object} aSpec
* Object with parameters for customization
* Elements: category - Category element to wait for
* timeout - Duration to wait for the target state
* [optional - default: 5s]
*/
waitForCategory : function addonsManager_waitForCategory(aSpec) {
var spec = aSpec || { };
var category = spec.category;
var timeout = (spec.timeout == undefined) ? TIMEOUT : spec.timeout;
if (!category)
throw new Error(arguments.callee.name + ": Category not specified.");
// TODO: restore after 1.5.1 has landed
// var self = this;
// mozmill.utils.waitFor(function () {
// return self.selectedCategory.getNode() == category.getNode();
// }, timeout, 100, "Category '" + category.getNode().id + "' has been set");
mozmill.utils.waitForEval("subject.self.selectedCategory.getNode() == subject.aCategory.getNode()",
timeout, 100,
{self: this, aCategory: category});
},
///////////////////////////////
// Search section
///////////////////////////////
/**
* Clear the search field
*/
clearSearchField : function addonsManager_clearSearchField() {
var textbox = this.getElement({type: "search_textbox"});
var cmdKey = utils.getEntity(this.dtds, "selectAllCmd.key");
this._controller.keypress(textbox, cmdKey, {accelKey: true});
this._controller.keypress(textbox, 'VK_DELETE', {});
},
/**
* Search for a specified add-on
*
* @param {object} aSpec
* Information to execute the search
* Elements: value - Search term
* timeout - Duration to wait for search results
* [optional - default: 30s]
* waitFor - Wait until the search has been finished
* [optional - default: true]
*/
search : function addonsManager_search(aSpec) {
var spec = aSpec || { };
var value = spec.value;
var timeout = (spec.timeout == undefined) ? TIMEOUT_SEARCH : spec.timeout;
var waitFor = (spec.waitFor == undefined) ? true : spec.waitFor;
if (!value)
throw new Error(arguments.callee.name + ": Search term not specified.");
var textbox = this.getElement({type: "search_textbox"});
this.clearSearchField();
this._controller.type(textbox, value);
this._controller.keypress(textbox, "VK_RETURN", {});
if (waitFor)
this.waitForSearchFinished();
},
/**
* Check if a search is active
*
* @returns State of the search
* @type {boolean}
*/
get isSearching() {
var throbber = this.getElement({type: "search_throbber"});
return throbber.getNode().hasAttribute("active");
},
/**
* Retrieve the currently selected search filter
*
* @returns Element which represents the currently selected search filter
* @type {ElemBase}
*/
get selectedSearchFilter() {
var filter = this.getSearchFilter({attribute: "selected", value: "true"});
return (filter.length > 0) ? filter[0] : undefined;
},
/**
* Set the currently selected search filter status
*
* @param {string} aValue
* Filter for the search results (local, remote)
*/
set selectedSearchFilter(aValue) {
var filter = this.getSearchFilter({attribute: "value", value: aValue});
if (SEARCH_FILTER.indexOf(aValue) == -1)
throw new Error(arguments.callee.name + ": '" + aValue +
"' is not a valid search filter");
if (filter.length > 0) {
this._controller.click(filter[0]);
this.waitForSearchFilter({filter: filter[0]});
}
},
/**
* Returns the available search filters which match the filter criteria
*
* @param {object} aSpec
* Information about the filter to apply
* Elements: attribute - DOM attribute of the wanted filter
* [optional - default: ""]
* value - Value of the DOM attribute
* [optional - default: ""]
*
* @returns List of search filters
* @type {array of ElemBase}
*/
getSearchFilter : function addonsManager_getSearchFilter(aSpec) {
var spec = aSpec || { };
return this.getElements({
type: "search_filterRadioButtons",
subtype: spec.attribute,
value: spec.value
});
},
/**
* Get the search filter element for the specified value
*
* @param {string} aValue
* Search filter value (local, remote)
*
* @returns Search filter element
* @type {ElemBase}
*/
getSearchFilterByValue : function addonsManager_getSearchFilterByValue(aValue) {
if (!aValue)
throw new Error(arguments.callee.name + ": Search filter value not specified.");
return this.getElement({
type: "search_filterRadioGroup",
subtype: "value",
value: aValue
});
},
/**
* Get the value of the given search filter element
*
* @param {object} aSpec
* Information for getting the views matched by the criteria
* Elements: filter - Filter element
*
* @returns Value of the search filter
* @type {string}
*/
getSearchFilterValue : function addonsManager_getSearchFilterValue(aSpec) {
var spec = aSpec || { };
var filter = spec.filter;
if (!filter)
throw new Error(arguments.callee.name + ": Search filter not specified.");
return filter.getNode().value;
},
/**
* Waits until the specified search filter has been selected
*
* @param {object} aSpec
* Object with parameters for customization
* Elements: filter - Filter element to wait for
* timeout - Duration to wait for the target state
* [optional - default: 5s]
*/
waitForSearchFilter : function addonsManager_waitForSearchFilter(aSpec) {
var spec = aSpec || { };
var filter = spec.filter;
var timeout = (spec.timeout == undefined) ? TIMEOUT : spec.timeout;
if (!filter)
throw new Error(arguments.callee.name + ": Search filter not specified.");
// TODO: restore after 1.5.1 has landed
// var self = this;
//
// mozmill.utils.waitFor(function () {
// return self.selectedSearchFilter.getNode() == filter.getNode();
// }, timeout, 100, "Search filter '" + filter.getNode().value + "' has been set");
mozmill.utils.waitForEval("subject.self.selectedSearchFilter.getNode() == subject.aFilter.getNode()",
timeout, 100,
{self: this, aFilter: filter});
},
/**
* Returns the list of add-ons found by the selected filter
*
* @returns List of add-ons
* @type {ElemBase}
*/
getSearchResults : function addonsManager_getSearchResults() {
var filterValue = this.getSearchFilterValue({
filter: this.selectedSearchFilter
});
switch (filterValue) {
case "local":
return this.getAddons({attribute: "status", value: "installed"});
case "remote":
return this.getAddons({attribute: "remote", value: "true"});
default:
throw new Error(arguments.callee.name + ": Unknown search filter '" +
filterValue + "' selected");
}
},
/**
* Waits until the active search has been finished
*
* @param {object} aSpec
* Object with parameters for customization
* Elements: timeout - Duration to wait for the target state
*/
waitForSearchFinished : function addonsManager_waitForSearchFinished(aSpec) {
var spec = aSpec || { };
var timeout = (spec.timeout == undefined) ? TIMEOUT_SEARCH : spec.timeout;
// TODO: restore after 1.5.1 has landed
// var self = this;
//
// mozmill.utils.waitFor(function () {
// return self.isSearching == false;
// }, timeout, 100, "Search has been finished");
mozmill.utils.waitForEval("subject.isSearching == false",
timeout, 100, this);
},
///////////////////////////////
// View section
///////////////////////////////
/**
* Returns the views which match the filter criteria
*
* @param {object} aSpec
* Information for getting the views matched by the criteria
* Elements: attribute - DOM attribute of the node
* [optional - default: ""]