browser_cmd_appcache_invalid.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Any copyright is dedicated to the Public Domain.
  2. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3. // Tests that the appcache validate works as they should with an invalid
  4. // manifest.
  5. const TEST_URI = "http://sub1.test1.example.com/browser/devtools/client/commandline/" +
  6. "test/browser_cmd_appcache_invalid_index.html";
  7. function test() {
  8. return Task.spawn(spawnTest).then(finish, helpers.handleError);
  9. }
  10. function* spawnTest() {
  11. let lines = [
  12. "Manifest has a character encoding of ISO-8859-1. Manifests must have the " +
  13. "utf-8 character encoding.",
  14. "The first line of the manifest must be \u201cCACHE MANIFEST\u201d at line 1.",
  15. "\u201cCACHE MANIFEST\u201d is only valid on the first line but was found at line 3.",
  16. "images/sound-icon.png points to a resource that is not available at line 9.",
  17. "images/background.png points to a resource that is not available at line 10.",
  18. "/checking.cgi points to a resource that is not available at line 13.",
  19. "Asterisk (*) incorrectly used in the NETWORK section at line 14. If a line " +
  20. "in the NETWORK section contains only a single asterisk character, then any " +
  21. "URI not listed in the manifest will be treated as if the URI was listed in " +
  22. "the NETWORK section. Otherwise such URIs will be treated as unavailable. " +
  23. "Other uses of the * character are prohibited",
  24. "../rel.html points to a resource that is not available at line 17.",
  25. "../../rel.html points to a resource that is not available at line 18.",
  26. "../../../rel.html points to a resource that is not available at line 19.",
  27. "../../../../rel.html points to a resource that is not available at line 20.",
  28. "../../../../../rel.html points to a resource that is not available at line 21.",
  29. "/../ is not a valid URI prefix at line 22.",
  30. "/test.css points to a resource that is not available at line 23.",
  31. "/test.js points to a resource that is not available at line 24.",
  32. "test.png points to a resource that is not available at line 25.",
  33. "/main/features.js points to a resource that is not available at line 27.",
  34. "/main/settings/index.css points to a resource that is not available at line 28.",
  35. "http://example.com/scene.jpg points to a resource that is not available at line 29.",
  36. "/section1/blockedbyfallback.html points to a resource that is not available at line 30.",
  37. "http://example.com/images/world.jpg points to a resource that is not available at line 31.",
  38. "/section2/blockedbyfallback.html points to a resource that is not available at line 32.",
  39. "/main/home points to a resource that is not available at line 34.",
  40. "main/app.js points to a resource that is not available at line 35.",
  41. "/settings/home points to a resource that is not available at line 37.",
  42. "/settings/app.js points to a resource that is not available at line 38.",
  43. "The file http://sub1.test1.example.com/browser/devtools/client/" +
  44. "commandline/test/browser_cmd_appcache_invalid_page3.html was modified " +
  45. "after http://sub1.test1.example.com/browser/devtools/client/" +
  46. "commandline/test/browser_cmd_appcache_invalid_appcache.appcache. Unless " +
  47. "the text in the manifest file is changed the cached version will be used " +
  48. "instead at line 39.",
  49. "browser_cmd_appcache_invalid_page3.html has cache-control set to no-store. " +
  50. "This will prevent the application cache from storing the file at line 39.",
  51. "http://example.com/logo.png points to a resource that is not available at line 40.",
  52. "http://example.com/check.png points to a resource that is not available at line 41.",
  53. "Spaces in URIs need to be replaced with % at line 42.",
  54. "http://example.com/cr oss.png points to a resource that is not available at line 42.",
  55. "Asterisk (*) incorrectly used in the CACHE section at line 43. If a line " +
  56. "in the NETWORK section contains only a single asterisk character, then " +
  57. "any URI not listed in the manifest will be treated as if the URI was " +
  58. "listed in the NETWORK section. Otherwise such URIs will be treated as " +
  59. "unavailable. Other uses of the * character are prohibited",
  60. "The SETTINGS section may only contain a single value, \u201cprefer-online\u201d or \u201cfast\u201d at line 47.",
  61. "FALLBACK section line 50 (/section1/ /offline1.html) prevents caching of " +
  62. "line 30 (/section1/blockedbyfallback.html) in the CACHE section.",
  63. "/offline1.html points to a resource that is not available at line 50.",
  64. "FALLBACK section line 51 (/section2/ offline2.html) prevents caching of " +
  65. "line 32 (/section2/blockedbyfallback.html) in the CACHE section.",
  66. "offline2.html points to a resource that is not available at line 51.",
  67. "Only two URIs separated by spaces are allowed in the FALLBACK section at line 52.",
  68. "Asterisk (*) incorrectly used in the FALLBACK section at line 53. URIs " +
  69. "in the FALLBACK section simply need to match a prefix of the request URI.",
  70. "offline3.html points to a resource that is not available at line 53.",
  71. "Invalid section name (BLAH) at line 55.",
  72. "Only two URIs separated by spaces are allowed in the FALLBACK section at line 55."
  73. ];
  74. let options = yield helpers.openTab(TEST_URI);
  75. info("window open");
  76. // Wait for site to be cached.
  77. yield helpers.listenOnce(gBrowser.contentWindow.applicationCache, "error");
  78. info("applicationCache error happened");
  79. yield helpers.openToolbar(options);
  80. info("toolbar open");
  81. // Pages containing an appcache the notification bar gives options to allow
  82. // or deny permission for the app to save data offline. Let's click Allow.
  83. let notificationID = "offline-app-requested-sub1.test1.example.com";
  84. let notification =
  85. PopupNotifications.getNotification(notificationID, gBrowser.selectedBrowser);
  86. if (notification) {
  87. info("Authorizing offline storage.");
  88. notification.mainAction.callback();
  89. } else {
  90. info("No notification box is available.");
  91. }
  92. info("Site now cached, running tests.");
  93. yield helpers.audit(options, [
  94. {
  95. setup: "appcache validate",
  96. check: {
  97. input: "appcache validate",
  98. markup: "VVVVVVVVVVVVVVVVV",
  99. status: "VALID",
  100. args: {}
  101. },
  102. exec: {
  103. output: lines.map(getRegexForString)
  104. },
  105. },
  106. ]);
  107. yield helpers.closeToolbar(options);
  108. yield helpers.closeTab(options);
  109. }
  110. /**
  111. * Creates a regular expression that matches a string. This greatly simplifies
  112. * matching and debugging long strings.
  113. *
  114. * @param {String} text
  115. * Text to convert
  116. * @return {RegExp}
  117. * Regular expression matching text
  118. */
  119. function getRegexForString(str) {
  120. str = str.replace(/(\.|\\|\/|\(|\)|\[|\]|\*|\+|\?|\$|\^|\|)/g, "\\$1");
  121. return new RegExp(str);
  122. }