~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/tests/pluginhost/tests/plugins.html

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-15 18:14:08 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120315181408-zgl94hzo0x4n99an
Tags: 0.1+bzr295+dfsg-0ubuntu2
* debian/patches:
  - 01-fix-database-settings.patch: Update to set PSERV_URL.
  - 02-pserv-config.patch: Set port to 8001.
* debian/maas.postinst: Run maas-import-isos on install.
* debian/control: Depends on rabbitmq-server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
2
<html>
 
3
<head>
 
4
    <title>PluginHost Tests</title>
 
5
 
 
6
</head>
 
7
<body class="yui3-skin-sam">
 
8
 
 
9
    <script type="text/javascript" src="../../../build/yui/yui.js"></script>
 
10
 
 
11
    <style type="text/css">
 
12
        #console .yui3-console-entry {
 
13
            padding:2px;
 
14
            margin:0px;
 
15
            min-height:0;
 
16
        }
 
17
 
 
18
        #console .yui3-console-entry-fail .yui3-console-entry-cat {
 
19
            background-color:red;
 
20
        }
 
21
 
 
22
        #console .yui3-console-entry-pass .yui3-console-entry-cat {
 
23
            background-color:green;
 
24
        }
 
25
 
 
26
        #console .yui3-console-entry-perf .yui3-console-entry-cat {
 
27
            background-color:blue;
 
28
        }
 
29
 
 
30
        #console {
 
31
            position:static;
 
32
        }
 
33
 
 
34
        html, body {
 
35
            height:100%;
 
36
        }
 
37
    </style>
 
38
 
 
39
    <script type="text/javascript">
 
40
        YUI({
 
41
            useBrowserConsole:false,
 
42
            filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'
 
43
        }).use("basebase", "base-pluginhost", "console", "plugin", "test", function(Y) {
 
44
 
 
45
            function PluginOne() {
 
46
                PluginOne.superclass.constructor.apply(this, arguments);
 
47
            }
 
48
            PluginOne.NS = "one";
 
49
            PluginOne.NAME = "pluginOne";
 
50
            PluginOne.ATTRS = {
 
51
                a: {
 
52
                    value:1
 
53
                }
 
54
            };
 
55
 
 
56
            Y.extend(PluginOne, Y.Plugin.Base, {
 
57
                initializer: function() {
 
58
                },
 
59
                method : function() {
 
60
                }
 
61
            });
 
62
 
 
63
            function PluginTwo() {
 
64
                PluginTwo.superclass.constructor.apply(this, arguments);
 
65
            }
 
66
            PluginTwo.NS = "two";
 
67
            PluginTwo.NAME = "pluginTwo";
 
68
            PluginTwo.ATTRS = {
 
69
                b: {
 
70
                    value:2
 
71
                }
 
72
            };
 
73
            Y.extend(PluginTwo, Y.Plugin.Base, {
 
74
                initializer: function() {
 
75
                },
 
76
                method : function() {
 
77
                }
 
78
            });
 
79
 
 
80
            function PluginThree() {
 
81
                PluginThree.superclass.constructor.apply(this, arguments);
 
82
            }
 
83
            PluginThree.NS = "three";
 
84
            PluginThree.NAME = "pluginThree";
 
85
            PluginThree.ATTRS = {
 
86
                c: {
 
87
                    value:3
 
88
                }
 
89
            };
 
90
            Y.extend(PluginThree, Y.Plugin.Base, {
 
91
                initializer: function() {
 
92
                },
 
93
                method : function() {
 
94
                }
 
95
            });
 
96
 
 
97
            function PluginFour() {
 
98
                PluginFour.superclass.constructor.apply(this, arguments);
 
99
            }
 
100
            PluginFour.NS = "four";
 
101
            PluginFour.NAME = "pluginFour";
 
102
            PluginFour.ATTRS = {
 
103
                d: {
 
104
                    value:4
 
105
                }
 
106
            };
 
107
 
 
108
            Y.extend(PluginFour, Y.Plugin.Base, {
 
109
                initializer: function(cfg) {
 
110
                    this.doBefore("methodA", this._methodA, this);
 
111
                    this.doAfter("methodB", this._methodB, this);
 
112
                    this.doBefore("mainAChange", this._onAChange);
 
113
                    this.doAfter("mainBChange", this._afterBChange);
 
114
                },
 
115
 
 
116
                _methodA : function(stack) {
 
117
                    stack.push("PluginFour.methodA");
 
118
                },
 
119
 
 
120
                _methodB : function(stack) {
 
121
                    stack.push("PluginFour.methodB");
 
122
                },
 
123
 
 
124
                _onAChange : function(e) {
 
125
                    if (e.stack) {
 
126
                        e.stack.push("PluginFour._onAChange");
 
127
                    }
 
128
                },
 
129
 
 
130
                _afterBChange : function(e) {
 
131
                    if (e.stack) {
 
132
                        e.stack.push("PluginFour._afterBChange");
 
133
                    }
 
134
                }
 
135
            });
 
136
 
 
137
            function Host(config) {
 
138
                Host.superclass.constructor.apply(this, arguments);
 
139
            }
 
140
 
 
141
            Host.NAME = "host";
 
142
            Host.ATTRS = {
 
143
                mainA : {
 
144
                    value: "mainA"
 
145
                },
 
146
                mainB : {
 
147
                    value: "mainB"
 
148
                }
 
149
            };
 
150
 
 
151
            Y.extend(Host, Y.Base, {
 
152
                methodA : function(stack) {
 
153
                    if (stack) {
 
154
                        stack.push("Host.methodA");
 
155
                    }
 
156
                },
 
157
 
 
158
                methodB : function(stack) {
 
159
                    if (stack) {
 
160
                        stack.push("Host.methodB");
 
161
                    }
 
162
                },
 
163
 
 
164
                initializer : function() {
 
165
                }
 
166
            });
 
167
 
 
168
            function ExtendedHost() {
 
169
                ExtendedHost.superclass.constructor.apply(this, arguments);
 
170
            }
 
171
 
 
172
            Y.extend(ExtendedHost, Host, {
 
173
                methodC : function() {},
 
174
                initializer : function() {}
 
175
            });
 
176
 
 
177
            var basicTemplate = {
 
178
 
 
179
                name: "Basic Tests",
 
180
 
 
181
                testPlugDuringConstruction : function() {
 
182
                    var h1 = new Host({
 
183
                        plugins:[PluginOne, {fn:PluginTwo, cfg:{two:4}}, {fn:PluginThree, cfg:{three:6}}]
 
184
                    });
 
185
 
 
186
                    Y.ObjectAssert.ownsKey("one", h1);
 
187
                    Y.Assert.isInstanceOf(PluginOne, h1.one);
 
188
                    Y.ObjectAssert.ownsKey("two", h1);
 
189
                    Y.Assert.isInstanceOf(PluginTwo, h1.two);
 
190
                    Y.ObjectAssert.ownsKey("three", h1);
 
191
                    Y.Assert.isInstanceOf(PluginThree, h1.three);
 
192
 
 
193
                    var h2 = new Host({
 
194
                        plugins:[PluginOne, PluginTwo]
 
195
                    });
 
196
 
 
197
                    Y.ObjectAssert.ownsKey("one", h2);
 
198
                    Y.Assert.isInstanceOf(PluginOne, h2.one);
 
199
                    Y.ObjectAssert.ownsKey("two", h2);
 
200
                    Y.Assert.isInstanceOf(PluginTwo, h2.two);
 
201
                    Y.Assert.isUndefined(h2.three);
 
202
                },
 
203
 
 
204
                testPlugUsingPlug : function() {
 
205
                    var h1 = new Host();
 
206
 
 
207
                    h1.plug(PluginOne);
 
208
                    h1.plug(PluginTwo, {two:4});
 
209
                    h1.plug({fn:PluginThree, cfg:{three:6}});
 
210
 
 
211
                    Y.ObjectAssert.ownsKey("one", h1);
 
212
                    Y.Assert.isInstanceOf(PluginOne, h1.one);
 
213
 
 
214
                    Y.ObjectAssert.ownsKey("two", h1);
 
215
                    Y.Assert.isInstanceOf(PluginTwo, h1.two);
 
216
 
 
217
                    Y.ObjectAssert.ownsKey("three", h1);
 
218
                    Y.Assert.isInstanceOf(PluginThree, h1.three);
 
219
 
 
220
                    var h2 = new Host();
 
221
                    h2.plug([PluginOne, {fn:PluginTwo, cfg:{two:8}}]);
 
222
 
 
223
                    Y.ObjectAssert.ownsKey("one", h2);
 
224
                    Y.Assert.isInstanceOf(PluginOne, h2.one);
 
225
 
 
226
                    Y.ObjectAssert.ownsKey("two", h2);
 
227
                    Y.Assert.isInstanceOf(PluginTwo, h2.two);
 
228
 
 
229
                    Y.Assert.isUndefined(h2.three);
 
230
                },
 
231
 
 
232
                testUnplug : function() {
 
233
 
 
234
                    var h1 = new Host({
 
235
                        plugins:[PluginOne, PluginTwo]
 
236
                    });
 
237
 
 
238
                    Y.ObjectAssert.ownsKey("one", h1);
 
239
                    Y.Assert.isInstanceOf(PluginOne, h1.one);
 
240
 
 
241
                    Y.ObjectAssert.ownsKey("two", h1);
 
242
                    Y.Assert.isInstanceOf(PluginTwo, h1.two);
 
243
 
 
244
                    h1.unplug("one");
 
245
 
 
246
                    Y.Assert.isUndefined(h1.one);
 
247
 
 
248
                    Y.ObjectAssert.ownsKey("two", h1);
 
249
                    Y.Assert.isInstanceOf(PluginTwo, h1.two);
 
250
 
 
251
                    h1.unplug(PluginTwo);
 
252
 
 
253
                    Y.Assert.isUndefined(h1.one);
 
254
                    Y.Assert.isUndefined(h1.two);
 
255
                },
 
256
 
 
257
                testUnplugPlug : function() {
 
258
 
 
259
                    var h1 = new Host({
 
260
                        plugins:[PluginOne, PluginTwo]
 
261
                    });
 
262
 
 
263
                    Y.ObjectAssert.ownsKey("one", h1);
 
264
                    Y.Assert.isInstanceOf(PluginOne, h1.one);
 
265
 
 
266
                    Y.ObjectAssert.ownsKey("two", h1);
 
267
                    Y.Assert.isInstanceOf(PluginTwo, h1.two);
 
268
 
 
269
                    h1.unplug(PluginOne);
 
270
 
 
271
                    Y.Assert.isUndefined(h1.one);
 
272
 
 
273
                    h1.plug(PluginOne);
 
274
 
 
275
                    Y.ObjectAssert.ownsKey("one", h1);
 
276
                    Y.Assert.isInstanceOf(PluginOne, h1.one);
 
277
                },
 
278
 
 
279
                testPluginHost : function() {
 
280
                    var h1 = new Host();
 
281
                    h1.plug(PluginOne);
 
282
 
 
283
                    Y.Assert.areSame(h1, h1.one.get("host"));
 
284
                },
 
285
 
 
286
                testPlugFormatsDefault : function() {
 
287
                    var h1 = new Host();
 
288
                    h1.plug(PluginOne);
 
289
                    Y.Assert.areEqual(1, h1.one.get("a"));
 
290
                },
 
291
 
 
292
                testPlugFormatsCustom : function() {
 
293
                    var h1 = new Host();
 
294
                    h1.plug(PluginOne, {a:10});
 
295
                    Y.Assert.areEqual(10, h1.one.get("a"));
 
296
                },
 
297
 
 
298
                testPlugFormatsCustomLiteral : function() {
 
299
                    var h1 = new Host();
 
300
                    h1.plug({fn:PluginOne, cfg:{a:10}});
 
301
                    Y.Assert.areEqual(10, h1.one.get("a"));
 
302
                },
 
303
 
 
304
                testPlugFormatsArrayDefault : function() {
 
305
                    var h1 = new Host();
 
306
                    h1.plug([PluginOne, PluginTwo]);
 
307
                    Y.Assert.areEqual(1, h1.one.get("a"));
 
308
                    Y.Assert.areEqual(2, h1.two.get("b"));
 
309
                },
 
310
 
 
311
                testPlugFormatsArrayCustom : function() {
 
312
                    var h1 = new Host();
 
313
                    h1.plug([{fn:PluginOne, cfg:{a:10}}, {fn:PluginTwo, cfg:{b:20}}]);
 
314
                    Y.Assert.areEqual(10, h1.one.get("a"));
 
315
                    Y.Assert.areEqual(20, h1.two.get("b"));
 
316
                },
 
317
 
 
318
                testPlugFormatsArrayMixed : function() {
 
319
                    var h1 = new Host();
 
320
                    h1.plug([{fn:PluginOne, cfg:{a:10}}, PluginTwo]);
 
321
                    Y.Assert.areEqual(10, h1.one.get("a"));
 
322
                    Y.Assert.areEqual(2, h1.two.get("b"));
 
323
                },
 
324
 
 
325
                testPlugSamePluginTwice : function() {
 
326
                    var h1 = new Host();
 
327
 
 
328
                    var expectedEvents = ["PluginOne destroy"];
 
329
                    var actualEvents = [];
 
330
 
 
331
                    h1.plug(PluginOne, {a:10});
 
332
                    Y.Assert.areEqual(10, h1.one.get("a"));
 
333
 
 
334
                    h1.one.on("destroy", function(e) {
 
335
                        actualEvents.push("PluginOne destroy");
 
336
                    });
 
337
 
 
338
                    h1.plug(PluginOne, {a:20});
 
339
                    Y.Assert.areEqual(20, h1.one.get("a"));
 
340
 
 
341
                    h1.unplug(PluginOne);
 
342
                },
 
343
 
 
344
                testPluginEventListeners : function() {
 
345
 
 
346
                    var h1 = new Host(), stack;
 
347
 
 
348
                    stack = [];
 
349
                    h1.set("mainA", 10, {stack:stack});
 
350
                    h1.set("mainB", 20, {stack:stack});
 
351
 
 
352
                    Y.ArrayAssert.itemsAreEqual([], stack);
 
353
 
 
354
                    h1.plug(PluginFour);
 
355
 
 
356
                    h1.set("mainA", 11, {stack:stack});
 
357
                    h1.set("mainB", 21, {stack:stack});
 
358
 
 
359
                    Y.ArrayAssert.itemsAreEqual(["PluginFour._onAChange", "PluginFour._afterBChange"], stack);
 
360
 
 
361
                    h1.unplug(PluginFour);
 
362
 
 
363
                    stack = [];
 
364
                    h1.set("mainA", 12, {stack:stack});
 
365
                    h1.set("mainB", 22, {stack:stack});
 
366
 
 
367
                    Y.ArrayAssert.itemsAreEqual([], stack);
 
368
                },
 
369
 
 
370
                testPluginMethodInjection : function() {
 
371
                    var h1 = new Host(), stack;
 
372
 
 
373
                    stack = [];
 
374
                    h1.methodA(stack);
 
375
                    h1.methodB(stack);
 
376
 
 
377
                    Y.ArrayAssert.itemsAreEqual(["Host.methodA", "Host.methodB"], stack);
 
378
 
 
379
                    h1.plug(PluginFour);
 
380
 
 
381
                    stack = [];
 
382
                    h1.methodA(stack);
 
383
                    h1.methodB(stack);
 
384
 
 
385
                    Y.ArrayAssert.itemsAreEqual(["PluginFour.methodA", "Host.methodA", "Host.methodB", "PluginFour.methodB"], stack);
 
386
 
 
387
                    h1.unplug(PluginFour);
 
388
 
 
389
                    stack = [];
 
390
                    h1.methodA(stack);
 
391
                    h1.methodB(stack);
 
392
 
 
393
                    Y.ArrayAssert.itemsAreEqual(["Host.methodA", "Host.methodB"], stack);
 
394
                },
 
395
 
 
396
                // Execute Last - will affect Host, ExtendedHost classes on the page
 
397
                testStaticPlug : function() {
 
398
 
 
399
                    Y.Base.plug(Host, PluginOne);
 
400
                    Y.Base.plug(Host, [{fn:PluginTwo, cfg:{}}, PluginThree]);
 
401
 
 
402
                    var h1 = new Host();
 
403
 
 
404
                    Y.ObjectAssert.ownsKey("one", h1);
 
405
                    Y.Assert.isInstanceOf(PluginOne, h1.one);
 
406
 
 
407
                    Y.ObjectAssert.ownsKey("two", h1);
 
408
                    Y.Assert.isInstanceOf(PluginTwo, h1.two);
 
409
 
 
410
                    Y.ObjectAssert.ownsKey("three", h1);
 
411
                    Y.Assert.isInstanceOf(PluginThree, h1.three);
 
412
 
 
413
                    Y.Base.unplug(Host, PluginThree);
 
414
 
 
415
                    // ---
 
416
 
 
417
                    Y.Base.plug(ExtendedHost, PluginThree);
 
418
                    Y.Base.unplug(ExtendedHost, PluginOne);
 
419
 
 
420
                    var h2 = new Host();
 
421
 
 
422
                    Y.ObjectAssert.ownsKey("one", h2);
 
423
                    Y.Assert.isInstanceOf(PluginOne, h2.one);
 
424
                    Y.ObjectAssert.ownsKey("two", h2);
 
425
                    Y.Assert.isInstanceOf(PluginTwo, h2.two);
 
426
                    Y.Assert.isUndefined(h2.three);
 
427
 
 
428
                    var h3 = new ExtendedHost();
 
429
 
 
430
                    Y.Assert.isUndefined(h3.one);
 
431
                    Y.ObjectAssert.ownsKey("two", h3);
 
432
                    Y.Assert.isInstanceOf(PluginTwo, h3.two);
 
433
 
 
434
                    Y.ObjectAssert.ownsKey("three", h3);
 
435
                    Y.Assert.isInstanceOf(PluginThree, h3.three);
 
436
                },
 
437
 
 
438
                testHostDestroy : function() {
 
439
 
 
440
                    var h1 = new Host({
 
441
                        plugins:[PluginOne, PluginTwo]
 
442
                    });
 
443
 
 
444
                    var destroyed = [];
 
445
                    h1.one.after("destroy", function(e) {
 
446
                        destroyed.push("one");
 
447
                    });
 
448
                    h1.two.after("destroy", function(e) {
 
449
                        destroyed.push("two");
 
450
                    });
 
451
 
 
452
                    h1.destroy();
 
453
 
 
454
                    Y.Assert.isUndefined(h1.one);
 
455
                    Y.Assert.isUndefined(h1.two);
 
456
 
 
457
                    Y.ArrayAssert.itemsAreEqual(["one", "two"], destroyed);
 
458
 
 
459
 
 
460
                }
 
461
 
 
462
            };
 
463
 
 
464
            var suite = new Y.Test.Suite("Plugin Tests");
 
465
            suite.add(new Y.Test.Case(basicTemplate));
 
466
 
 
467
            Y.Test.Runner.setName("Plugin Tests");
 
468
            Y.Test.Runner.add(suite);
 
469
            Y.Test.Runner.disableLogging();
 
470
            Y.Test.Runner.run();
 
471
 
 
472
            var console;
 
473
 
 
474
            Y.one("#btnRun").set("disabled", false).on("click", function() {
 
475
                if (!console) {
 
476
                    console = new Y.Console({
 
477
                        id:"console",
 
478
                        width:"100%",
 
479
                        height:"90%",
 
480
                        verbose : false,
 
481
                        printTimeout: 0,
 
482
                        newestOnTop : false,
 
483
                        entryTemplate: '<pre class="{entry_class} {cat_class} {src_class}">'+
 
484
                                '<span class="{entry_cat_class}">{label}</span>'+
 
485
                                '<span class="{entry_content_class}">{message}</span>'+
 
486
                        '</pre>'
 
487
                    }).render();
 
488
                }
 
489
 
 
490
                Y.Test.Runner.enableLogging();
 
491
                Y.Test.Runner.run();
 
492
            });
 
493
        });
 
494
    </script>
 
495
    <p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
 
496
</body>
 
497
</html>