history_test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2013 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. /**
  15. * @fileoverview Unit tests for goog.history.History.
  16. */
  17. /** @suppress {extraProvide} */
  18. goog.provide('goog.HistoryTest');
  19. goog.require('goog.History');
  20. goog.require('goog.dispose');
  21. goog.require('goog.dom');
  22. goog.require('goog.html.TrustedResourceUrl');
  23. goog.require('goog.string.Const');
  24. goog.require('goog.testing.jsunit');
  25. goog.require('goog.userAgent');
  26. goog.setTestOnly('goog.HistoryTest');
  27. // Mimimal function to exercise construction.
  28. function testCreation() {
  29. var input = goog.dom.getElement('hidden-input');
  30. var iframe = goog.dom.getElement('hidden-iframe');
  31. try {
  32. var history = new goog.History(undefined, undefined, input, iframe);
  33. } finally {
  34. goog.dispose(history);
  35. }
  36. // Test that SafeHtml.create() calls in constructor succeed.
  37. try {
  38. // Undefined opt_input and opt_iframe will result in use document.write(),
  39. // which in some browsers overrides the current page and causes the
  40. // test to fail.
  41. var history = new goog.History(
  42. true, goog.html.TrustedResourceUrl.fromConstant(
  43. goog.string.Const.from('blank_test_helper.html')),
  44. input, iframe);
  45. } finally {
  46. goog.dispose(history);
  47. }
  48. }
  49. function testIsHashChangeSupported() {
  50. // This is the policy currently implemented.
  51. var supportsOnHashChange =
  52. (goog.userAgent.IE ? document.documentMode >= 8 :
  53. 'onhashchange' in window);
  54. assertEquals(supportsOnHashChange, goog.History.isOnHashChangeSupported());
  55. }
  56. // TODO(nnaze): Test additional behavior.