keyboard_test.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // Copyright 2014 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.userAgent.keyboardTest');
  15. goog.setTestOnly('goog.userAgent.keyboardTest');
  16. goog.require('goog.labs.userAgent.testAgents');
  17. goog.require('goog.labs.userAgent.util');
  18. goog.require('goog.testing.MockUserAgent');
  19. goog.require('goog.testing.jsunit');
  20. goog.require('goog.userAgent.keyboard');
  21. goog.require('goog.userAgentTestUtil');
  22. var mockAgent;
  23. function setUp() {
  24. mockAgent = new goog.testing.MockUserAgent();
  25. mockAgent.install();
  26. }
  27. function tearDown() {
  28. mockAgent.dispose();
  29. goog.labs.userAgent.util.setUserAgent(null);
  30. goog.userAgentTestUtil.reinitializeUserAgent();
  31. }
  32. function testAndroid() {
  33. mockAgent.setNavigator({platform: 'Linux'});
  34. setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_235);
  35. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  36. setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_221);
  37. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  38. setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_233);
  39. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  40. setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_403);
  41. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  42. setUserAgent(goog.labs.userAgent.testAgents.ANDROID_BROWSER_403_ALT);
  43. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  44. }
  45. function testIe() {
  46. mockAgent.setNavigator({platform: 'Windows'});
  47. setUserAgent(goog.labs.userAgent.testAgents.IE_6);
  48. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  49. setUserAgent(goog.labs.userAgent.testAgents.IE_7);
  50. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  51. setUserAgent(goog.labs.userAgent.testAgents.IE_8);
  52. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  53. setUserAgent(goog.labs.userAgent.testAgents.IE_8_COMPATIBILITY);
  54. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  55. setUserAgent(goog.labs.userAgent.testAgents.IE_9);
  56. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  57. setUserAgent(goog.labs.userAgent.testAgents.IE_10);
  58. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  59. setUserAgent(goog.labs.userAgent.testAgents.IE_10_COMPATIBILITY);
  60. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  61. setUserAgent(goog.labs.userAgent.testAgents.IE_11);
  62. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  63. setUserAgent(goog.labs.userAgent.testAgents.IE_11_COMPATIBILITY_MSIE_7);
  64. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  65. setUserAgent(goog.labs.userAgent.testAgents.IE_11_COMPATIBILITY_MSIE_9);
  66. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  67. }
  68. function testFirefoxMac() {
  69. mockAgent.setNavigator({platform: 'Macintosh'});
  70. setUserAgent(goog.labs.userAgent.testAgents.FIREFOX_MAC);
  71. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  72. }
  73. function testFirefoxNotMac() {
  74. mockAgent.setNavigator({platform: 'X11'});
  75. setUserAgent(goog.labs.userAgent.testAgents.FIREFOX_LINUX);
  76. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  77. mockAgent.setNavigator({platform: 'Windows'});
  78. setUserAgent(goog.labs.userAgent.testAgents.FIREFOX_WINDOWS);
  79. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  80. }
  81. function testSafari() {
  82. mockAgent.setNavigator({platform: 'Macintosh'});
  83. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_6);
  84. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  85. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_MAC);
  86. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  87. mockAgent.setNavigator({platform: 'iPhone'});
  88. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_IPHONE_32);
  89. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  90. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_IPHONE_421);
  91. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  92. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_IPHONE_431);
  93. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  94. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_IPHONE_6);
  95. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  96. mockAgent.setNavigator({platform: 'iPod'});
  97. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_IPOD);
  98. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  99. }
  100. function testSafariWndows() {
  101. mockAgent.setNavigator({platform: 'Macintosh'});
  102. setUserAgent(goog.labs.userAgent.testAgents.SAFARI_WINDOWS);
  103. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  104. }
  105. function testOperaMac() {
  106. mockAgent.setNavigator({platform: 'Macintosh'});
  107. setUserAgent(goog.labs.userAgent.testAgents.OPERA_MAC);
  108. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  109. }
  110. function testOperaNonMac() {
  111. mockAgent.setNavigator({platform: 'X11'});
  112. setUserAgent(goog.labs.userAgent.testAgents.OPERA_LINUX);
  113. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  114. mockAgent.setNavigator({platform: 'Windows'});
  115. setUserAgent(goog.labs.userAgent.testAgents.OPERA_15);
  116. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  117. }
  118. function testIPad() {
  119. mockAgent.setNavigator({platform: 'iPad'});
  120. setUserAgent(goog.labs.userAgent.testAgents.IPAD_4);
  121. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  122. setUserAgent(goog.labs.userAgent.testAgents.IPAD_5);
  123. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  124. setUserAgent(goog.labs.userAgent.testAgents.IPAD_6);
  125. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  126. }
  127. function testChromeMac() {
  128. mockAgent.setNavigator({platform: 'Macintosh'});
  129. setUserAgent(goog.labs.userAgent.testAgents.CHROME_MAC);
  130. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  131. mockAgent.setNavigator({platform: 'iPhone'});
  132. setUserAgent(goog.labs.userAgent.testAgents.CHROME_IPHONE);
  133. assertTrue(goog.userAgent.keyboard.MAC_KEYBOARD);
  134. }
  135. function testChromeNonMac() {
  136. mockAgent.setNavigator({platform: 'Linux'});
  137. setUserAgent(goog.labs.userAgent.testAgents.CHROME_ANDROID);
  138. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  139. mockAgent.setNavigator({platform: 'X11'});
  140. setUserAgent(goog.labs.userAgent.testAgents.CHROME_OS);
  141. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  142. mockAgent.setNavigator({platform: 'X11'});
  143. setUserAgent(goog.labs.userAgent.testAgents.CHROME_LINUX);
  144. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  145. mockAgent.setNavigator({platform: 'Windows'});
  146. setUserAgent(goog.labs.userAgent.testAgents.CHROME_25);
  147. assertFalse(goog.userAgent.keyboard.MAC_KEYBOARD);
  148. }
  149. function setUserAgent(ua) {
  150. mockAgent.setUserAgentString(ua);
  151. goog.labs.userAgent.util.setUserAgent(ua);
  152. goog.userAgentTestUtil.reinitializeUserAgent();
  153. }