Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const { Loader } = require('sdk/test/loader'); |
michael@0 | 6 | |
michael@0 | 7 | exports.testOnClick = function (assert) { |
michael@0 | 8 | let [loader, mockAlertServ] = makeLoader(module); |
michael@0 | 9 | let notifs = loader.require("sdk/notifications"); |
michael@0 | 10 | let data = "test data"; |
michael@0 | 11 | let opts = { |
michael@0 | 12 | onClick: function (clickedData) { |
michael@0 | 13 | assert.equal(this, notifs, "|this| should be notifications module"); |
michael@0 | 14 | assert.equal(clickedData, data, |
michael@0 | 15 | "data passed to onClick should be correct"); |
michael@0 | 16 | }, |
michael@0 | 17 | data: data, |
michael@0 | 18 | title: "test title", |
michael@0 | 19 | text: "test text", |
michael@0 | 20 | iconURL: "test icon URL" |
michael@0 | 21 | }; |
michael@0 | 22 | notifs.notify(opts); |
michael@0 | 23 | mockAlertServ.click(); |
michael@0 | 24 | loader.unload(); |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | exports['test:numbers and URLs in options'] = function(assert) { |
michael@0 | 28 | let [loader] = makeLoader(module); |
michael@0 | 29 | let notifs = loader.require('sdk/notifications'); |
michael@0 | 30 | let opts = { |
michael@0 | 31 | title: 123, |
michael@0 | 32 | text: 45678, |
michael@0 | 33 | // must use in-loader `sdk/url` module for the validation type check to work |
michael@0 | 34 | iconURL: loader.require('sdk/url').URL('data:image/png,blah') |
michael@0 | 35 | }; |
michael@0 | 36 | try { |
michael@0 | 37 | notifs.notify(opts); |
michael@0 | 38 | assert.pass('using numbers and URLs in options works'); |
michael@0 | 39 | } catch (e) { |
michael@0 | 40 | assert.fail('using numbers and URLs in options must not throw'); |
michael@0 | 41 | } |
michael@0 | 42 | loader.unload(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | exports['test:new tag, dir and lang options'] = function(assert) { |
michael@0 | 46 | let [loader] = makeLoader(module); |
michael@0 | 47 | let notifs = loader.require('sdk/notifications'); |
michael@0 | 48 | let opts = { |
michael@0 | 49 | title: 'best', |
michael@0 | 50 | tag: 'tagging', |
michael@0 | 51 | lang: 'en' |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | try { |
michael@0 | 55 | opts.dir = 'ttb'; |
michael@0 | 56 | notifs.notify(opts); |
michael@0 | 57 | assert.fail('`dir` option must not accept TopToBottom direction.'); |
michael@0 | 58 | } catch (e) { |
michael@0 | 59 | assert.equal(e.message, |
michael@0 | 60 | '`dir` option must be one of: "auto", "ltr" or "rtl".'); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | try { |
michael@0 | 64 | opts.dir = 'rtl'; |
michael@0 | 65 | notifs.notify(opts); |
michael@0 | 66 | assert.pass('`dir` option accepts "rtl" direction.'); |
michael@0 | 67 | } catch (e) { |
michael@0 | 68 | assert.fail('`dir` option must accept "rtl" direction.'); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | loader.unload(); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | // Returns [loader, mockAlertService]. |
michael@0 | 75 | function makeLoader(module) { |
michael@0 | 76 | let loader = Loader(module); |
michael@0 | 77 | let mockAlertServ = { |
michael@0 | 78 | showAlertNotification: function (imageUrl, title, text, textClickable, |
michael@0 | 79 | cookie, alertListener, name) { |
michael@0 | 80 | this._cookie = cookie; |
michael@0 | 81 | this._alertListener = alertListener; |
michael@0 | 82 | }, |
michael@0 | 83 | click: function () { |
michael@0 | 84 | this._alertListener.observe(null, "alertclickcallback", this._cookie); |
michael@0 | 85 | } |
michael@0 | 86 | }; |
michael@0 | 87 | loader.require("sdk/notifications"); |
michael@0 | 88 | let scope = loader.sandbox("sdk/notifications"); |
michael@0 | 89 | scope.notify = mockAlertServ.showAlertNotification.bind(mockAlertServ); |
michael@0 | 90 | return [loader, mockAlertServ]; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | require('sdk/test').run(exports); |