| 1 | <?xml version="1.0" encoding="UTF-8"?> |
|---|
| 2 | <Module> |
|---|
| 3 | <ModulePrefs title="OpenSocial Unit Tester" |
|---|
| 4 | author_email="lindner@inuus.com" |
|---|
| 5 | author="Paul Lindner" |
|---|
| 6 | author_affiliation="Inuus" |
|---|
| 7 | author_photo="http://www.yoyodyne.com/yoyodyne.jpg" |
|---|
| 8 | description="This fine application exercises your OpenSocial container!" |
|---|
| 9 | author_aboutme="Paul Lindner develops software that matters." |
|---|
| 10 | author_link="http://paul.vox.com/" |
|---|
| 11 | author_quote="You have to spit to see the shine!" |
|---|
| 12 | > |
|---|
| 13 | <Require feature="opensocial-0.7"/> |
|---|
| 14 | <Require feature="views"/> |
|---|
| 15 | <Require feature="settitle"/> |
|---|
| 16 | <Require feature="dynamic-height"> |
|---|
| 17 | <Param name="moo">goo</Param> |
|---|
| 18 | </Require> |
|---|
| 19 | </ModulePrefs> |
|---|
| 20 | <Content type="html"> |
|---|
| 21 | <![CDATA[ |
|---|
| 22 | |
|---|
| 23 | <script src="http://www.inuus.com/os/scriptaculous/prototype.js" type="text/javascript"></script> |
|---|
| 24 | <script src="http://www.inuus.com/os/scriptaculous/scriptaculous.js?load=effects,dragdrop" type="text/javascript"></script> |
|---|
| 25 | <script src="http://www.inuus.com/os/scriptaculous/unittest.js" type="text/javascript"></script> |
|---|
| 26 | <link rel="stylesheet" href="http://www.inuus.com/os/scriptaculous/test.css" type="text/css" /> |
|---|
| 27 | |
|---|
| 28 | <!-- Log output --> |
|---|
| 29 | <a href="javascript:doNav()">test navigateto</a> |
|---|
| 30 | <h3>Test Results</h3> |
|---|
| 31 | <div id="testlog"> </div> |
|---|
| 32 | <br/> |
|---|
| 33 | <!-- our stuff --> |
|---|
| 34 | <div id="testoutput" class=""> |
|---|
| 35 | <h3>Test Output</h3><br/><br/> |
|---|
| 36 | |
|---|
| 37 | </div> |
|---|
| 38 | |
|---|
| 39 | <script type="text/javascript" language="javascript" charset="utf-8"> |
|---|
| 40 | // Output a new message |
|---|
| 41 | function doNav() { |
|---|
| 42 | gadgets.views.requestNavigateTo(new gadgets.views.View("canvas"), {moo: 255}); |
|---|
| 43 | } |
|---|
| 44 | function testoutput(msg) { |
|---|
| 45 | $('testoutput').insert(msg + "<br/>"); |
|---|
| 46 | gadgets.window.adjustHeight(); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | // Output a new section heading |
|---|
| 50 | function testhead(msg) { |
|---|
| 51 | $('testoutput').insert("<br/><br/><b>" + msg + "</b><br/>"); |
|---|
| 52 | gadgets.window.adjustHeight(); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | function run_tests() { |
|---|
| 56 | new Test.Unit.Runner({ |
|---|
| 57 | |
|---|
| 58 | testBasic: function() { with(this) { |
|---|
| 59 | testhead("testBasic"); |
|---|
| 60 | assertNotNull(gadgets); |
|---|
| 61 | assertNotNull(gadgets.views); |
|---|
| 62 | assertNotNull(gadgets.window); |
|---|
| 63 | assertNotNull(opensocial); |
|---|
| 64 | testoutput("gadgets and opensocial defined"); |
|---|
| 65 | }}, |
|---|
| 66 | testEnvironment: function () { with(this) { |
|---|
| 67 | testhead("testEnvironment"); |
|---|
| 68 | var env = opensocial.getEnvironment(); |
|---|
| 69 | assertNotNull(env, 'opensocial.getEnvironment()'); |
|---|
| 70 | assertNotNull(env.getDomain()); |
|---|
| 71 | testoutput('Found Domain - ' + env.getDomain()); |
|---|
| 72 | |
|---|
| 73 | assertNotNull(gadgets.views.getCurrentView(), "getCurrentView()"); |
|---|
| 74 | testoutput("Current view is " + gadgets.views.getCurrentView().getName()); |
|---|
| 75 | var views = gadgets.views.getSupportedViews(); |
|---|
| 76 | assertNotNull(views); |
|---|
| 77 | if (views) { |
|---|
| 78 | var viewlist = ''; |
|---|
| 79 | for (var v in views) { |
|---|
| 80 | viewlist += v + ", "; |
|---|
| 81 | } |
|---|
| 82 | testoutput("Found views - " + viewlist); |
|---|
| 83 | } |
|---|
| 84 | var p = gadgets.views.getParams(); |
|---|
| 85 | assertNotNull(p); |
|---|
| 86 | // Special test just for hi5.com |
|---|
| 87 | if (env.getDomain() == "hi5.com") { |
|---|
| 88 | assertNotNull(p['Hi5AuthToken'], "Missing Hi5AuthToken only (valid for hi5.com container)"); |
|---|
| 89 | } |
|---|
| 90 | }}, |
|---|
| 91 | |
|---|
| 92 | testPrefs: function () { with(this) { |
|---|
| 93 | testhead("testPrefs"); |
|---|
| 94 | var p = new gadgets.Prefs() |
|---|
| 95 | assertNotNull(p, "cannot get gadgets.Prefs()"); |
|---|
| 96 | |
|---|
| 97 | assertNotNull(p.getCountry()); |
|---|
| 98 | assertNotEqual(p.getCountry(), 'all', 'country cannot be "all"'); |
|---|
| 99 | testoutput("Found country: '" + p.getCountry() + "'"); |
|---|
| 100 | assertEqual(2, p.getCountry().length, "country is two chars"); |
|---|
| 101 | |
|---|
| 102 | assertNotNull(p.getLang()); |
|---|
| 103 | assertNotEqual(p.getLang(), 'all', 'lang cannot be "all"'); |
|---|
| 104 | testoutput("Found language: '" + p.getLang() + "'"); |
|---|
| 105 | assertEqual(2, p.getLang().length, "lang is 2 chars"); |
|---|
| 106 | }}, |
|---|
| 107 | |
|---|
| 108 | testOwnerViewer: function () { with(this) { |
|---|
| 109 | testhead("testOwnerViewer"); |
|---|
| 110 | var dataResponse; |
|---|
| 111 | var req = opensocial.newDataRequest(); |
|---|
| 112 | assertNotNull(req, "opensocial.newDataRequest()"); |
|---|
| 113 | req.add (req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER), 'viewer'); |
|---|
| 114 | req.add (req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER), 'owner'); |
|---|
| 115 | req.send(function(response) { dataResponse = response } ); |
|---|
| 116 | |
|---|
| 117 | wait(2000, function() { |
|---|
| 118 | assertNotNull(dataResponse, "OWNER/VIEWER response"); |
|---|
| 119 | // TODO add error handling |
|---|
| 120 | var viewer = dataResponse.get('viewer').getData(); |
|---|
| 121 | assertInstanceOf(opensocial.Person, viewer); |
|---|
| 122 | assertInstanceOf(opensocial.Name, viewer.getField(opensocial.Person.Field.NAME)); |
|---|
| 123 | assertNotNull(viewer, "found viewer data"); |
|---|
| 124 | |
|---|
| 125 | var owner = dataResponse.get('owner').getData(); |
|---|
| 126 | assertInstanceOf(opensocial.Person, owner); |
|---|
| 127 | assertInstanceOf(opensocial.Name, owner.getField(opensocial.Person.Field.NAME)); |
|---|
| 128 | assertNotNull(owner, "found owner data"); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | assert(viewer.isViewer(), "isViewer() is true"); |
|---|
| 132 | assert(owner.isOwner(), "isOwner() is true"); |
|---|
| 133 | |
|---|
| 134 | var gender = viewer.getField(opensocial.Person.Field.GENDER); |
|---|
| 135 | assertType(opensocial.Enum, gender); |
|---|
| 136 | assertEqual(true, |
|---|
| 137 | gender.getKey() == opensocial.Enum.Gender.MALE || |
|---|
| 138 | gender.getKey() == opensocial.Enum.Gender.FEMALE, |
|---|
| 139 | 'Viewer Gender Defined') |
|---|
| 140 | |
|---|
| 141 | gender = owner.getField(opensocial.Person.Field.GENDER); |
|---|
| 142 | assertEqual(true, |
|---|
| 143 | gender.getKey() == opensocial.Enum.Gender.MALE || |
|---|
| 144 | gender.getKey() == opensocial.Enum.Gender.FEMALE, |
|---|
| 145 | 'Owner Gender Defined'); |
|---|
| 146 | |
|---|
| 147 | testoutput('found viewer, name: ' + viewer.getDisplayName() + ', id: ' + viewer.getId() + ', gender: ' + gender.getKey()); |
|---|
| 148 | testoutput('found owner, name: ' + owner.getDisplayName() + ', id: ' + owner.getId()); |
|---|
| 149 | }); |
|---|
| 150 | }}, |
|---|
| 151 | testFriends: function() { with (this) { |
|---|
| 152 | testhead("testFriends"); |
|---|
| 153 | var dataResponse; |
|---|
| 154 | var req = opensocial.newDataRequest(); |
|---|
| 155 | assertNotNull(req, "opensocial.newDataRequest()"); |
|---|
| 156 | req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS'), 'viewerFriends'); |
|---|
| 157 | req.add (req.newFetchPersonRequest('OWNER_FRIENDS'), 'ownerFriends'); |
|---|
| 158 | req.send(function(response) { dataResponse = response } ); |
|---|
| 159 | |
|---|
| 160 | wait(5000, function() { |
|---|
| 161 | assertNotNull(dataResponse, "OWNER/VIEWER friends response"); |
|---|
| 162 | |
|---|
| 163 | var ownerFriends = dataResponse.get('ownerFriends').getData(); |
|---|
| 164 | assertNotNull(ownerFriends); |
|---|
| 165 | |
|---|
| 166 | var viewerFriends = dataResponse.get('viewerFriends').getData(); |
|---|
| 167 | assertNotNull(viewerFriends); |
|---|
| 168 | |
|---|
| 169 | }); |
|---|
| 170 | }}, |
|---|
| 171 | testActivityFeed: function() { with(this) { |
|---|
| 172 | testhead("testActivityFeed"); |
|---|
| 173 | |
|---|
| 174 | var dataResponse; |
|---|
| 175 | var req = opensocial.newDataRequest(); |
|---|
| 176 | assertNotNull(req, "opensocial.newDataRequest()"); |
|---|
| 177 | req.add(req.newFetchActivitiesRequest('OWNER'), 'owner'); |
|---|
| 178 | req.add(req.newFetchActivitiesRequest('VIEWER'), 'viewer'); |
|---|
| 179 | req.add(req.newFetchActivitiesRequest('OWNER_FRIENDS'), 'ownerfriends'); |
|---|
| 180 | req.add(req.newFetchActivitiesRequest('VIEWER_FRIENDS'), 'viewerfriends'); |
|---|
| 181 | req.send(function(response) { dataResponse = response } ); |
|---|
| 182 | |
|---|
| 183 | wait(5000, function() { |
|---|
| 184 | assertNotNull(dataResponse, "activities response"); |
|---|
| 185 | |
|---|
| 186 | ['owner', 'viewer', 'ownerfriends', 'viewerfriends'].each(function(result) { |
|---|
| 187 | var resp = dataResponse.get(result); |
|---|
| 188 | var msg = "Data for " + result; |
|---|
| 189 | assertNotNull(resp, msg); |
|---|
| 190 | var activities = resp.getData(); |
|---|
| 191 | assertNotNull(activities); |
|---|
| 192 | activities = activities['activities']; |
|---|
| 193 | assertNotNull(activities); |
|---|
| 194 | |
|---|
| 195 | var numAct = activities.size(); |
|---|
| 196 | assertNotEqual(0, numAct, "Find events for " + result); |
|---|
| 197 | testoutput("Found " + numAct + " activities for " + result); |
|---|
| 198 | }); |
|---|
| 199 | |
|---|
| 200 | }); |
|---|
| 201 | |
|---|
| 202 | }}, |
|---|
| 203 | testPersistance: function () { with(this) { |
|---|
| 204 | testhead("testPersistance"); |
|---|
| 205 | var dataResponse; |
|---|
| 206 | var req = opensocial.newDataRequest(); |
|---|
| 207 | assertNotNull(req, "opensocial.newDataRequest()"); |
|---|
| 208 | req.add (req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER, "moo", "cow")); |
|---|
| 209 | req.add (req.newFetchPersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER, "moo"), 'data'); |
|---|
| 210 | req.send(function(response) { dataResponse = response } ); |
|---|
| 211 | wait(5000, function() { |
|---|
| 212 | assertNotNull(dataResponse); |
|---|
| 213 | var resp; |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | }); |
|---|
| 217 | }}, |
|---|
| 218 | |
|---|
| 219 | testFetchFeed: function() { with(this) { |
|---|
| 220 | testhead("testFetchFeed"); |
|---|
| 221 | var response; |
|---|
| 222 | gadgets.io.makeRequest("http://feeds.feedburner.com/Hi5Blog", function(r) { response=r}, |
|---|
| 223 | {contentType: gadgets.io.ContentType.FEED}); |
|---|
| 224 | |
|---|
| 225 | wait(5000, function() { |
|---|
| 226 | assertNotNull(response); |
|---|
| 227 | assertNotNull(response.data); |
|---|
| 228 | assertNotNull(response.text); |
|---|
| 229 | assertEqual(response.errors.length, 0); |
|---|
| 230 | testoutput("Got a response."); |
|---|
| 231 | }); |
|---|
| 232 | }}, |
|---|
| 233 | |
|---|
| 234 | testPostXml: function() { with(this) { |
|---|
| 235 | testhead("testPostXml"); |
|---|
| 236 | var response; |
|---|
| 237 | gadgets.io.makeRequest("http://api.hi5.com/rest/test/echo", function(r) { response=r}, |
|---|
| 238 | {CONTENT_TYPE: gadgets.io.ContentType.DOM, |
|---|
| 239 | METHOD: "POST", |
|---|
| 240 | POST_DATA: "message=moooooo"}); |
|---|
| 241 | |
|---|
| 242 | wait(5000, function() { |
|---|
| 243 | assertNotNull(response); |
|---|
| 244 | assertNotNull(response.data); |
|---|
| 245 | assertNotNull(response.text); |
|---|
| 246 | assertEqual(response.errors.length, 0); |
|---|
| 247 | assertMatch(/moooooo/, response.text, "Server found our posted message"); |
|---|
| 248 | testoutput("Got a response."); |
|---|
| 249 | }); |
|---|
| 250 | }}, |
|---|
| 251 | testSigned: function() { with(this) { |
|---|
| 252 | testhead("testSignedRequest"); |
|---|
| 253 | var response; |
|---|
| 254 | gadgets.io.makeRequest("http://www.inuus.com/os/testOauth.php", function(r) { response=r}, |
|---|
| 255 | {CONTENT_TYPE: gadgets.io.ContentType.JSON, |
|---|
| 256 | METHOD: "POST", |
|---|
| 257 | POST_DATA: "message=moooooo", |
|---|
| 258 | AUTHORIZATION: gadgets.io.AuthorizationType.SIGNED}); |
|---|
| 259 | |
|---|
| 260 | wait(5000, function() { |
|---|
| 261 | assertNotNull(response); |
|---|
| 262 | assertNotNull(response.data); |
|---|
| 263 | assertNotNull(response.text); |
|---|
| 264 | assertEqual(response.errors.length, 0); |
|---|
| 265 | assertMatch(/moooooo/, response.text, "Server found our posted message"); |
|---|
| 266 | testoutput("Got a response."); |
|---|
| 267 | }); |
|---|
| 268 | }}, |
|---|
| 269 | }, "testlog"); |
|---|
| 270 | gadgets.window.adjustHeight(); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | gadgets.util.registerOnLoadHandler(run_tests); |
|---|
| 274 | gadgets.window.adjustHeight(); |
|---|
| 275 | |
|---|
| 276 | </script> |
|---|
| 277 | |
|---|
| 278 | ]]> |
|---|
| 279 | </Content> |
|---|
| 280 | </Module> |
|---|