Permalink
Browse files

Bug 825148 - Make UI Tests and Test receivers app work with CSP

  • Loading branch information...
1 parent fbf48d6 commit c57add9e52a789036667543945e13c8638a2812f @timdream timdream committed May 29, 2013
Showing with 420 additions and 491 deletions.
  1. +0 −23 test_apps/test-receiver-1/js/share-receiver.js
  2. +0 −23 test_apps/test-receiver-2/js/share-receiver.js
  3. +4 −70 test_apps/test-receiver-inline/index.html
  4. +72 −0 test_apps/test-receiver-inline/js/inline-receiver.js
  5. +20 −20 test_apps/uitest/index.html
  6. +27 −0 test_apps/uitest/js/alert.js
  7. +21 −0 test_apps/uitest/js/audiotag.js
  8. +15 −0 test_apps/uitest/js/browseractivities.js
  9. +22 −0 test_apps/uitest/js/contextmenu.js
  10. +13 −0 test_apps/uitest/js/empty.js
  11. +15 −0 test_apps/uitest/js/fullscreen.js
  12. +14 −0 test_apps/uitest/js/geolocation.js
  13. +18 −0 test_apps/uitest/js/inlineactivities.js
  14. +7 −0 test_apps/uitest/js/multiactivities.js
  15. +62 −0 test_apps/uitest/js/notification.js
  16. +3 −0 test_apps/uitest/js/popup.js
  17. +13 −0 test_apps/uitest/js/savebookmark.js
  18. +6 −0 test_apps/uitest/js/scrollbar.js
  19. +16 −0 test_apps/uitest/js/select.js
  20. +7 −6 test_apps/uitest/tests/alert.html
  21. +7 −19 test_apps/uitest/tests/audiotag.html
  22. +5 −12 test_apps/uitest/tests/browseractivities.html
  23. +5 −11 test_apps/uitest/tests/contextmenu.html
  24. +17 −0 test_apps/uitest/tests/csp.html
  25. +1 −0 test_apps/uitest/tests/empty.html
  26. +3 −10 test_apps/uitest/tests/fullscreen.html
  27. +4 −19 test_apps/uitest/tests/geolocation.html
  28. +2 −22 test_apps/uitest/tests/inlineactivities.html
  29. +0 −2 test_apps/uitest/tests/inputmode.html
  30. +2 −8 test_apps/uitest/tests/multiactivities.html
  31. +7 −54 test_apps/uitest/tests/notification.html
  32. +0 −2 test_apps/uitest/tests/open.html
  33. +2 −12 test_apps/uitest/tests/popup.html
  34. +5 −100 test_apps/uitest/tests/recording.html
  35. +3 −15 test_apps/uitest/tests/savebookmark.html
  36. +1 −8 test_apps/uitest/tests/scrollbar.html
  37. +1 −21 test_apps/uitest/tests/select.html
  38. +0 −34 test_apps/uitest/tests/setcapture.html
@@ -1,23 +0,0 @@
-window.onload = function() {
- navigator.mozSetMessageHandler('activity', function(activityRequest) {
- if (activityRequest.source.name === 'share-filenames') {
- addImages(activityRequest.source.data.filenames);
- }
- });
-};
-
-function addImages(filenames) {
- console.log('Receiving', filenames.length, 'files');
- var storage = navigator.getDeviceStorage('pictures');
- filenames.forEach(function(filename) {
- storage.get(filename).onsuccess = function(e) {
- var blob = e.target.result;
- var url = URL.createObjectURL(blob);
- var img = document.createElement('img');
- img.style.width = '100px';
- img.src = url;
- img.onload = function() { URL.revokeObjectURL(this.src); };
- document.body.appendChild(img);
- };
- });
-}
@@ -1,23 +0,0 @@
-window.onload = function() {
- navigator.mozSetMessageHandler('activity', function(activityRequest) {
- if (activityRequest.source.name === 'share-filenames') {
- addImages(activityRequest.source.data.filenames);
- }
- });
-};
-
-function addImages(filenames) {
- console.log('Receiving', filenames.length, 'files');
- var storage = navigator.getDeviceStorage('pictures');
- filenames.forEach(function(filename) {
- storage.get(filename).onsuccess = function(e) {
- var blob = e.target.result;
- var url = URL.createObjectURL(blob);
- var img = document.createElement('img');
- img.style.width = '100px';
- img.src = url;
- img.onload = function() { URL.revokeObjectURL(this.src); };
- document.body.appendChild(img);
- };
- });
-}
@@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache">
<title>Test Receiver</title>
+ <script src="js/inline-receiver.js" defer></script>
<style>
button {
font-size: 30px;
@@ -17,80 +18,13 @@
background-color: #e0e0e0;
}
</style>
- <script>
- var activityRequest;
-
- var webActivityHandler = function (request) {
- activityRequest = request;
-
- document.getElementById('button').disabled = '';
- document.getElementById('cancelButton').disabled = '';
- document.getElementById('number').focus();
-
- };
-
- window.onload = function () {
- // If the app is being loaded because a inline disposition web activity,
- // it will came with a pending system message.
- if (!navigator.mozHasPendingMessage('activity')) {
- alert('This application is not intend to launch directly.');
- } else {
- // Register for activity system message handling.
- // Do NOT register for message handling on the main app frame.
- navigator.mozSetMessageHandler('activity', webActivityHandler);
- }
- };
-
- var go = function go() {
- if (!activityRequest) {
- alert('There are no any pending activity request.');
- return;
- }
-
- // Return the request
- activityRequest.postResult({
- type: 'inline',
- text: 'Hello back!'
- });
- activityRequest = null;
-
- // close app, currently useless,
- // see https://bugzilla.mozilla.org/show_bug.cgi?id=789392
- window.close();
- };
-
- var cancel = function cancel() {
- if (!activityRequest) {
- alert('There are no any pending activity request.');
- return;
- }
-
- activityRequest.postError('canceled');
- activityRequest = null;
-
- // close app, currently useless,
- // see https://bugzilla.mozilla.org/show_bug.cgi?id=789392
- window.close();
- };
-
- // When the app is being closed or killed, we will cancel the pending
- // request.
- document.addEventListener('mozvisibilitychange', function visibility(e) {
- if (!document.mozHidden || !activityRequest)
- return;
-
- activityRequest.postError('canceled');
- activityRequest = null;
- });
-
- </script>
</head>
<body>
<h1>Inline Web Activities receiver</h1>
- <p><button onclick="go()" disabled id="button">Send "Hello Back!"</button></p>
+ <p><button disabled id="button">Send "Hello Back!"</button></p>
<!-- add an input field to test keyboard work well -->
<p><input type="number" id="number" size="4" /></p>
- <p><button onclick="cancel()" disabled id="cancelButton">Cancel</button></p>
- <p><button onclick="prompt('inline-activty prompt!');">Prompt</button></p>
+ <p><button disabled id="cancelButton">Cancel</button></p>
+ <p><button id="promptButton">Prompt</button></p>
</body>
</html>
@@ -0,0 +1,72 @@
+var activityRequest;
+
+var webActivityHandler = function (request) {
+ activityRequest = request;
+
+ document.getElementById('button').disabled = '';
+ document.getElementById('cancelButton').disabled = '';
+ document.getElementById('number').focus();
+
+};
+
+window.onload = function () {
+ document.getElementById('button').onclick = go;
+ document.getElementById('cancelButton').onclick = cancel;
+ document.getElementById('promptButton').onclick = promptButton;
+
+ // If the app is being loaded because a inline disposition web activity,
+ // it will came with a pending system message.
+ if (!navigator.mozHasPendingMessage('activity')) {
+ alert('This application is not intend to launch directly.');
+ } else {
+ // Register for activity system message handling.
+ // Do NOT register for message handling on the main app frame.
+ navigator.mozSetMessageHandler('activity', webActivityHandler);
+ }
+};
+
+var go = function go() {
+ if (!activityRequest) {
+ alert('There are no any pending activity request.');
+ return;
+ }
+
+ // Return the request
+ activityRequest.postResult({
+ type: 'inline',
+ text: 'Hello back!'
+ });
+ activityRequest = null;
+
+ // close app, currently useless,
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=789392
+ window.close();
+};
+
+var cancel = function cancel() {
+ if (!activityRequest) {
+ alert('There are no any pending activity request.');
+ return;
+ }
+
+ activityRequest.postError('canceled');
+ activityRequest = null;
+
+ // close app, currently useless,
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=789392
+ window.close();
+};
+
+var promptButton = function promptButton() {
+ prompt('inline-activty prompt!');
+};
+
+// When the app is being closed or killed, we will cancel the pending
+// request.
+document.addEventListener('mozvisibilitychange', function visibility(e) {
+ if (!document.mozHidden || !activityRequest)
+ return;
+
+ activityRequest.postError('canceled');
+ activityRequest = null;
+});
@@ -13,35 +13,35 @@
<p class="toolbar-title">UI Tests</p>
</div>
<ul class="list" id="test-list">
- <li><a href="#test=empty">Empty test</a></li>
- <li><a href="#test=keyboard">Keyboard test</a></li>
- <li><a href="#test=geolocation">Geolocation test</a></li>
- <li><a href="#test=contextmenu">Contextmenu test</a></li>
- <li><a href="#test=recording">Recording test</a></li>
- <li><a href="#test=select">Select test</a></li>
- <li><a href="#test=contacts">Contacts tests</a></li>
- <li><a href="#test=alert">Alert/Prompt tests</a></li>
- <li><a href="#test=open">window.open tests</a></li>
- <li><a href="#test=notification">mozNotification tests</a></li>
- <li><a href="#test=scrollbar">Scroll bar tests</a></li>
- <li><a href="#test=setcapture">setCapture test</a></li>
- <li><a href="#test=inlineactivities">Inline Activities test</a></li>
- <li><a href="#test=multiactivities">Multi Activities test</a></li>
- <li><a href="#test=browseractivities">Browser Web Activities test</a></li>
+ <li><a href="#test=empty">Empty</a></li>
+ <li><a href="#test=keyboard">Keyboard</a></li>
+ <li><a href="#test=geolocation">Geolocation</a></li>
+ <li><a href="#test=contextmenu">Contextmenu</a></li>
+ <li><a href="#test=recording">Recording</a></li>
+ <li><a href="#test=select">Select</a></li>
+ <li><a href="#test=contacts">Contacts</a></li>
+ <li><a href="#test=alert">Alert/Prompt</a></li>
+ <li><a href="#test=open">window.open</a></li>
+ <li><a href="#test=notification">mozNotification</a></li>
+ <li><a href="#test=scrollbar">Scroll bar</a></li>
+ <li><a href="#test=inlineactivities">Inline Activities</a></li>
+ <li><a href="#test=multiactivities">Multi Activities</a></li>
+ <li><a href="#test=browseractivities">Browser Activities</a></li>
<li><a href="#test=savebookmark">Save bookmark</a></li>
<li><a href="#test=fullscreen">mozRequestFullScreen</a></li>
<li><a href="#test=httpauthentication">HTTP Authentication</a></li>
<li><a href="#test=pickphoto">Pick Photo</a></li>
<li><a href="#test=viewphoto">View Photo</a></li>
<li><a href="#test=openvideo">Open Video</a></li>
<li><a href="#test=openaudio">Open Audio</a></li>
- <li><a href="#test=pay">navigator.mozPay tests</a></li>
- <li><a href="#test=inputmode">text inputmode tests</a></li>
- <li><a href="#test=audiotag">audio tag tests</a></li>
- <li><a href="#test=identity">navigator.mozId tests</a></li>
+ <li><a href="#test=pay">navigator.mozPay</a></li>
+ <li><a href="#test=inputmode">text inputmode</a></li>
+ <li><a href="#test=audiotag">audio tag</a></li>
+ <li><a href="#test=identity">navigator.mozId</a></li>
<li><a href="#test=identity-get">navigator.mozId.get</a></li>
<li><a href="#test=fullscreen_controls">Fullscreen Controls</a></li>
- <li><a href="#test=canvas">Canvas Tag test</a></li>
+ <li><a href="#test=canvas">Canvas Tag</a></li>
+ <li><a href="#test=csp">CSP Warning</a></li>
</ul>
</div>
<div id="test-panel" class="panel">
@@ -0,0 +1,27 @@
+'use strict';
+
+var clickHandlers = {
+ 'button1': function () {
+ window.parent.alert('Hello world!');
+ },
+ 'button2': function () {
+ window.parent.alert(window.parent.confirm('Hello world?'));
+ },
+ 'button3': function () {
+ window.parent.alert(window.parent.prompt('Hello world:', 'initial value'));
+ },
+ 'button21': function () {
+ alert('Hello world!');
+ },
+ 'button22': function () {
+ alert(confirm('Hello world?'));
+ },
+ 'button23': function () {
+ alert(prompt('Hello world:', 'initial value'));
+ }
+};
+
+document.body.addEventListener('click', function (evt) {
+ if (clickHandlers[evt.target.id])
+ clickHandlers[evt.target.id].call(this, evt);
+});
@@ -0,0 +1,21 @@
+'use strict';
+
+var clickHandlers = {
+ 'play': function play() {
+ var src = this.dataset.src;
+
+ var ringtonePlayer = new Audio();
+ ringtonePlayer.loop = true;
+ var selectedSound = '../style/ringtones/' + src;
+ ringtonePlayer.src = selectedSound;
+ ringtonePlayer.play();
+ window.setTimeout(function _pauseRingtone() {
+ ringtonePlayer.pause();
+ }, 20000);
+ }
+};
+
+document.body.addEventListener('click', function (evt) {
+ if (clickHandlers[evt.target.id || evt.target.dataset.fn])
+ clickHandlers[evt.target.id || evt.target.dataset.fn].call(this, evt);
+});
@@ -0,0 +1,15 @@
+'use strict';
+
+var clickHandlers = {
+ 'go': function _go() {
+ var URL = document.getElementById('URL').value;
+ var a = new MozActivity({ name: 'view', data: {type: 'url', url: URL }});
+ a.onsuccess = function() { alert('Success!'); };
+ a.onerror = function() { alert('Failure going to URL'); };
+ }
+};
+
+document.body.addEventListener('click', function (evt) {
+ if (clickHandlers[evt.target.id || evt.target.dataset.fn])
+ clickHandlers[evt.target.id || evt.target.dataset.fn].call(this, evt);
+});
@@ -0,0 +1,22 @@
+'use strict';
+
+var clickHandlers = {
+ 'reload': function () {
+ window.location.reload();
+ },
+ 'comments': function () {
+ window.location='#comments';
+ alert(window.location.href);
+ },
+ 'twitter': function () {
+ window.open('http://twitter.com/intent/tweet?text=' + document.title + ': ' + window.location.href, "shareWindow");
+ },
+ 'facebook': function () {
+ window.open('http://facebook.com/sharer/sharer.php?u=' + window.location.href, "shareWindow");
+ }
+};
+
+document.body.addEventListener('click', function (evt) {
+ if (clickHandlers[evt.target.id || evt.target.dataset.fn])
+ clickHandlers[evt.target.id || evt.target.dataset.fn].call(this, evt);
+});
@@ -0,0 +1,13 @@
+'use strict';
+
+var clickHandlers = {
+/*
+ 'id': function () {
+ alert('event triggered!');
+ }, */
+};
+
+document.body.addEventListener('click', function (evt) {
+ if (clickHandlers[evt.target.id || evt.target.dataset.fn])
+ clickHandlers[evt.target.id || evt.target.dataset.fn].call(this, evt);
+});
@@ -0,0 +1,15 @@
+'use strict';
+
+var clickHandlers = {
+ 'fullscreen': function fullscreen() {
+ document.getElementById('fullscreen-div').mozRequestFullScreen();
+ },
+ 'fullscreenFrame': function fullscreenFrame() {
+ window.parent.document.getElementById('test-iframe').mozRequestFullScreen();
+ }
+};
+
+document.body.addEventListener('click', function (evt) {
+ if (clickHandlers[evt.target.id || evt.target.dataset.fn])
+ clickHandlers[evt.target.id || evt.target.dataset.fn].call(this, evt);
+});
Oops, something went wrong.

0 comments on commit c57add9

Please sign in to comment.