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