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 | |
michael@0 | 2 | let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; |
michael@0 | 3 | |
michael@0 | 4 | let baseURL = "https://example.com/browser/browser/base/content/test/social/"; |
michael@0 | 5 | |
michael@0 | 6 | let manifest = { // normal provider |
michael@0 | 7 | name: "provider 1", |
michael@0 | 8 | origin: "https://example.com", |
michael@0 | 9 | workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 10 | iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png", |
michael@0 | 11 | shareURL: "https://example.com/browser/browser/base/content/test/social/share.html" |
michael@0 | 12 | }; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | waitForExplicitFinish(); |
michael@0 | 16 | |
michael@0 | 17 | runSocialTests(tests); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | let corpus = [ |
michael@0 | 21 | { |
michael@0 | 22 | url: baseURL+"opengraph/opengraph.html", |
michael@0 | 23 | options: { |
michael@0 | 24 | // og:title |
michael@0 | 25 | title: ">This is my title<", |
michael@0 | 26 | // og:description |
michael@0 | 27 | description: "A test corpus file for open graph tags we care about", |
michael@0 | 28 | //medium: this.getPageMedium(), |
michael@0 | 29 | //source: this.getSourceURL(), |
michael@0 | 30 | // og:url |
michael@0 | 31 | url: "https://www.mozilla.org/", |
michael@0 | 32 | //shortUrl: this.getShortURL(), |
michael@0 | 33 | // og:image |
michael@0 | 34 | previews:["https://www.mozilla.org/favicon.png"], |
michael@0 | 35 | // og:site_name |
michael@0 | 36 | siteName: ">My simple test page<" |
michael@0 | 37 | } |
michael@0 | 38 | }, |
michael@0 | 39 | { |
michael@0 | 40 | // tests that og:url doesn't override the page url if it is bad |
michael@0 | 41 | url: baseURL+"opengraph/og_invalid_url.html", |
michael@0 | 42 | options: { |
michael@0 | 43 | description: "A test corpus file for open graph tags passing a bad url", |
michael@0 | 44 | url: baseURL+"opengraph/og_invalid_url.html", |
michael@0 | 45 | previews: [], |
michael@0 | 46 | siteName: "Evil chrome delivering website" |
michael@0 | 47 | } |
michael@0 | 48 | }, |
michael@0 | 49 | { |
michael@0 | 50 | url: baseURL+"opengraph/shorturl_link.html", |
michael@0 | 51 | options: { |
michael@0 | 52 | previews: ["http://example.com/1234/56789.jpg"], |
michael@0 | 53 | url: "http://www.example.com/photos/56789/", |
michael@0 | 54 | shortUrl: "http://imshort/p/abcde" |
michael@0 | 55 | } |
michael@0 | 56 | }, |
michael@0 | 57 | { |
michael@0 | 58 | url: baseURL+"opengraph/shorturl_linkrel.html", |
michael@0 | 59 | options: { |
michael@0 | 60 | previews: ["http://example.com/1234/56789.jpg"], |
michael@0 | 61 | url: "http://www.example.com/photos/56789/", |
michael@0 | 62 | shortUrl: "http://imshort/p/abcde" |
michael@0 | 63 | } |
michael@0 | 64 | }, |
michael@0 | 65 | { |
michael@0 | 66 | url: baseURL+"opengraph/shortlink_linkrel.html", |
michael@0 | 67 | options: { |
michael@0 | 68 | previews: ["http://example.com/1234/56789.jpg"], |
michael@0 | 69 | url: "http://www.example.com/photos/56789/", |
michael@0 | 70 | shortUrl: "http://imshort/p/abcde" |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | ]; |
michael@0 | 74 | |
michael@0 | 75 | function loadURLInTab(url, callback) { |
michael@0 | 76 | info("Loading tab with "+url); |
michael@0 | 77 | let tab = gBrowser.selectedTab = gBrowser.addTab(url); |
michael@0 | 78 | tab.linkedBrowser.addEventListener("load", function listener() { |
michael@0 | 79 | is(tab.linkedBrowser.currentURI.spec, url, "tab loaded") |
michael@0 | 80 | tab.linkedBrowser.removeEventListener("load", listener, true); |
michael@0 | 81 | executeSoon(function() { callback(tab) }); |
michael@0 | 82 | }, true); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function hasoptions(testOptions, options) { |
michael@0 | 86 | let msg; |
michael@0 | 87 | for (let option in testOptions) { |
michael@0 | 88 | let data = testOptions[option]; |
michael@0 | 89 | info("data: "+JSON.stringify(data)); |
michael@0 | 90 | let message_data = options[option]; |
michael@0 | 91 | info("message_data: "+JSON.stringify(message_data)); |
michael@0 | 92 | if (Array.isArray(data)) { |
michael@0 | 93 | // the message may have more array elements than we are testing for, this |
michael@0 | 94 | // is ok since some of those are hard to test. So we just test that |
michael@0 | 95 | // anything in our test data IS in the message. |
michael@0 | 96 | ok(Array.every(data, function(item) { return message_data.indexOf(item) >= 0 }), "option "+option); |
michael@0 | 97 | } else { |
michael@0 | 98 | is(message_data, data, "option "+option); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | var tests = { |
michael@0 | 104 | testShareDisabledOnActivation: function(next) { |
michael@0 | 105 | // starting on about:blank page, share should be visible but disabled when |
michael@0 | 106 | // adding provider |
michael@0 | 107 | is(gBrowser.contentDocument.location.href, "about:blank"); |
michael@0 | 108 | SocialService.addProvider(manifest, function(provider) { |
michael@0 | 109 | is(SocialUI.enabled, true, "SocialUI is enabled"); |
michael@0 | 110 | checkSocialUI(); |
michael@0 | 111 | // share should not be enabled since we only have about:blank page |
michael@0 | 112 | let shareButton = SocialShare.shareButton; |
michael@0 | 113 | is(shareButton.disabled, true, "share button is disabled"); |
michael@0 | 114 | // verify the attribute for proper css |
michael@0 | 115 | is(shareButton.getAttribute("disabled"), "true", "share button attribute is disabled"); |
michael@0 | 116 | // button should be visible |
michael@0 | 117 | is(shareButton.hidden, false, "share button is visible"); |
michael@0 | 118 | SocialService.removeProvider(manifest.origin, next); |
michael@0 | 119 | }); |
michael@0 | 120 | }, |
michael@0 | 121 | testShareEnabledOnActivation: function(next) { |
michael@0 | 122 | // starting from *some* page, share should be visible and enabled when |
michael@0 | 123 | // activating provider |
michael@0 | 124 | let testData = corpus[0]; |
michael@0 | 125 | loadURLInTab(testData.url, function(tab) { |
michael@0 | 126 | SocialService.addProvider(manifest, function(provider) { |
michael@0 | 127 | is(SocialUI.enabled, true, "SocialUI is enabled"); |
michael@0 | 128 | checkSocialUI(); |
michael@0 | 129 | // share should not be enabled since we only have about:blank page |
michael@0 | 130 | let shareButton = SocialShare.shareButton; |
michael@0 | 131 | is(shareButton.disabled, false, "share button is enabled"); |
michael@0 | 132 | // verify the attribute for proper css |
michael@0 | 133 | ok(!shareButton.hasAttribute("disabled"), "share button is enabled"); |
michael@0 | 134 | // button should be visible |
michael@0 | 135 | is(shareButton.hidden, false, "share button is visible"); |
michael@0 | 136 | gBrowser.removeTab(tab); |
michael@0 | 137 | next(); |
michael@0 | 138 | }); |
michael@0 | 139 | }); |
michael@0 | 140 | }, |
michael@0 | 141 | testSharePage: function(next) { |
michael@0 | 142 | let provider = Social._getProviderFromOrigin(manifest.origin); |
michael@0 | 143 | let port = provider.getWorkerPort(); |
michael@0 | 144 | ok(port, "provider has a port"); |
michael@0 | 145 | let testTab; |
michael@0 | 146 | let testIndex = 0; |
michael@0 | 147 | let testData = corpus[testIndex++]; |
michael@0 | 148 | |
michael@0 | 149 | function runOneTest() { |
michael@0 | 150 | loadURLInTab(testData.url, function(tab) { |
michael@0 | 151 | testTab = tab; |
michael@0 | 152 | SocialShare.sharePage(); |
michael@0 | 153 | }); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | port.onmessage = function (e) { |
michael@0 | 157 | let topic = e.data.topic; |
michael@0 | 158 | switch (topic) { |
michael@0 | 159 | case "got-share-data-message": |
michael@0 | 160 | gBrowser.removeTab(testTab); |
michael@0 | 161 | hasoptions(testData.options, e.data.result); |
michael@0 | 162 | testData = corpus[testIndex++]; |
michael@0 | 163 | if (testData) { |
michael@0 | 164 | executeSoon(runOneTest); |
michael@0 | 165 | } else { |
michael@0 | 166 | SocialService.removeProvider(manifest.origin, next); |
michael@0 | 167 | } |
michael@0 | 168 | break; |
michael@0 | 169 | } |
michael@0 | 170 | } |
michael@0 | 171 | port.postMessage({topic: "test-init"}); |
michael@0 | 172 | executeSoon(runOneTest); |
michael@0 | 173 | } |
michael@0 | 174 | } |