tests.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. /* jshint jasmine: true */
  22. /* global StatusBar */
  23. exports.defineAutoTests = function() {
  24. describe("StatusBar", function() {
  25. it("statusbar.spec.1 should exist", function() {
  26. expect(window.StatusBar).toBeDefined();
  27. });
  28. it("statusbar.spec.2 should have show|hide methods", function() {
  29. expect(window.StatusBar.show).toBeDefined();
  30. expect(typeof window.StatusBar.show).toBe("function");
  31. expect(window.StatusBar.hide).toBeDefined();
  32. expect(typeof window.StatusBar.hide).toBe("function");
  33. });
  34. it("statusbar.spec.3 should have set backgroundColor methods", function() {
  35. expect(window.StatusBar.backgroundColorByName).toBeDefined();
  36. expect(typeof window.StatusBar.backgroundColorByName).toBe("function");
  37. expect(window.StatusBar.backgroundColorByHexString).toBeDefined();
  38. expect(typeof window.StatusBar.backgroundColorByHexString).toBe(
  39. "function"
  40. );
  41. });
  42. it("statusbar.spec.4 should have set style methods", function() {
  43. expect(window.StatusBar.styleBlackTranslucent).toBeDefined();
  44. expect(typeof window.StatusBar.styleBlackTranslucent).toBe("function");
  45. expect(window.StatusBar.styleDefault).toBeDefined();
  46. expect(typeof window.StatusBar.styleDefault).toBe("function");
  47. expect(window.StatusBar.styleLightContent).toBeDefined();
  48. expect(typeof window.StatusBar.styleLightContent).toBe("function");
  49. expect(window.StatusBar.styleBlackOpaque).toBeDefined();
  50. expect(typeof window.StatusBar.styleBlackOpaque).toBe("function");
  51. expect(window.StatusBar.overlaysWebView).toBeDefined();
  52. expect(typeof window.StatusBar.overlaysWebView).toBe("function");
  53. });
  54. });
  55. };
  56. exports.defineManualTests = function(contentEl, createActionButton) {
  57. function log(msg) {
  58. var el = document.getElementById("info");
  59. var logLine = document.createElement("div");
  60. logLine.innerHTML = msg;
  61. el.appendChild(logLine);
  62. }
  63. function doShow() {
  64. StatusBar.show();
  65. log("StatusBar.isVisible=" + StatusBar.isVisible);
  66. }
  67. function doHide() {
  68. StatusBar.hide();
  69. log("StatusBar.isVisible=" + StatusBar.isVisible);
  70. }
  71. function doColor1() {
  72. log("set color=red");
  73. StatusBar.backgroundColorByName("red");
  74. }
  75. function doColor2() {
  76. log("set style=translucent black");
  77. StatusBar.styleBlackTranslucent();
  78. }
  79. function doColor3() {
  80. log("set style=default");
  81. StatusBar.styleDefault();
  82. }
  83. var showOverlay = true;
  84. function doOverlay() {
  85. showOverlay = !showOverlay;
  86. StatusBar.overlaysWebView(showOverlay);
  87. log("Set overlay=" + showOverlay);
  88. }
  89. /******************************************************************************/
  90. contentEl.innerHTML =
  91. '<div id="info"></div>' +
  92. "Also: tapping bar on iOS should emit a log." +
  93. '<div id="action-show"></div>' +
  94. "Expected result: Status bar will be visible" +
  95. "</p> <div id=\"action-hide\"></div>" +
  96. "Expected result: Status bar will be hidden" +
  97. '</p> <div id="action-color2"></div>' +
  98. "Expected result: Status bar text will be a light (white) color" +
  99. '</p> <div id="action-color3"></div>' +
  100. "Expected result: Status bar text will be a dark (black) color" +
  101. "</p> <div id=\"action-overlays\"></div>" +
  102. "Expected result:<br>Overlay true = status bar will lay on top of web view content<br>Overlay false = status bar will be separate from web view and will not cover content" +
  103. "</p> <div id=\"action-color1\"></div>" +
  104. "Expected result: If overlay false, background color for status bar will be red";
  105. log("StatusBar.isVisible=" + StatusBar.isVisible);
  106. window.addEventListener(
  107. "statusTap",
  108. function() {
  109. log("tap!");
  110. },
  111. false
  112. );
  113. createActionButton(
  114. "Show",
  115. function() {
  116. doShow();
  117. },
  118. "action-show"
  119. );
  120. createActionButton(
  121. "Hide",
  122. function() {
  123. doHide();
  124. },
  125. "action-hide"
  126. );
  127. createActionButton(
  128. "Style=red (background)",
  129. function() {
  130. doColor1();
  131. },
  132. "action-color1"
  133. );
  134. createActionButton(
  135. "Style=translucent black",
  136. function() {
  137. doColor2();
  138. },
  139. "action-color2"
  140. );
  141. createActionButton(
  142. "Style=default",
  143. function() {
  144. doColor3();
  145. },
  146. "action-color3"
  147. );
  148. createActionButton(
  149. "Toggle Overlays",
  150. function() {
  151. doOverlay();
  152. },
  153. "action-overlays"
  154. );
  155. };