| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>history_test.html</title> |
| <link rel="stylesheet" href="/filez/_main/third_party/js/qunit/qunit.css"> |
| <script src="/filez/_main/third_party/js/qunit/qunit.js"></script> |
| <script src="/filez/_main/third_party/js/qunit/qunit_test_runner.js"></script> |
| <script src="test_bootstrap.js"></script> |
| <script type="text/javascript"> |
| goog.require('bot'); |
| goog.require('bot.locators'); |
| goog.require('bot.test'); |
| goog.require('bot.userAgent'); |
| goog.require('bot.window'); |
| goog.require('goog.dom'); |
| goog.require('goog.events'); |
| goog.require('goog.Promise'); |
| goog.require('goog.userAgent'); |
| goog.require('goog.userAgent.platform'); |
| goog.require('goog.userAgent.product'); |
| </script> |
| </head> |
| <body> |
| <div id="qunit"></div> |
| <div id="qunit-fixture"></div> |
| <iframe id="frame"></iframe> |
| <script type="text/javascript"> |
| var frame = null; |
| var popup = null; |
| var resolver = null; |
| |
| var initFrame = new goog.Promise(function(ready) { |
| if (goog.userAgent.product.ANDROID) { |
| frame = bot.locators.findElement({'id': 'frame'}); |
| goog.events.listen(frame, 'load', notifyLoaded); |
| waitForLoad().then(function() { |
| bot.setWindow(goog.dom.getFrameContentWindow(frame)); |
| ready(); |
| }); |
| frame.src = 'testdata/history_page0.html'; |
| } else { |
| ready(); |
| } |
| }); |
| |
| function waitForLoad() { |
| resolver = goog.Promise.withResolver(); |
| return resolver.promise; |
| } |
| |
| function notifyLoaded() { |
| bot.getWindow().onunload = goog.nullFunction; |
| |
| window.setTimeout(function() { |
| resolver.resolve(); |
| }, 0); |
| } |
| |
| QUnit.testDone(function() { |
| if (popup) { |
| popup.close(); |
| popup = null; |
| } |
| }); |
| |
| function load(url) { |
| var loc = window.location.href; |
| url = loc.substring(0, loc.lastIndexOf('/') + 1) + url; |
| var loaded = waitForLoad(); |
| if (popup || frame) { |
| if (bot.getWindow() === window) { |
| throw new Error('bot.setWindow() not called'); |
| } |
| bot.getWindow().location.href = url; |
| } else { |
| popup = window.open(url); |
| if (!popup) { |
| throw new Error('window.open() failed: is a pop-up blocker enabled?'); |
| } |
| bot.setWindow(popup); |
| } |
| return loaded; |
| } |
| |
| function back(numPages) { |
| var loaded = waitForLoad(); |
| bot.window.back(numPages); |
| return loaded; |
| } |
| |
| function forward(numPages) { |
| var loaded = waitForLoad(); |
| bot.window.forward(numPages); |
| return loaded; |
| } |
| |
| function assertUrlContains(assert, str) { |
| assert.ok(bot.getWindow().location.href.indexOf(str) !== -1, 'URL should contain ' + str); |
| } |
| |
| QUnit.test('ErrorThrownWhenNumPagesNonPositive', function(assert) { |
| assert.throws(function() { bot.window.back(0); }); |
| assert.throws(function() { bot.window.back(0); }); |
| assert.throws(function() { bot.window.back(-1); }); |
| assert.throws(function() { bot.window.forward(-1); }); |
| }); |
| |
| QUnit.test('ErrorThrowWhenNumPagesNotLessThanHistoryLength', function(assert) { |
| if (!popup) { |
| assert.ok(true, 'Skipping: cannot check this property reliably without popups'); |
| return; |
| } |
| var done = assert.async(); |
| initFrame.then(function() { |
| return load('testdata/history_page1.html'); |
| }).then(function() { |
| return load('testdata/history_page2.html'); |
| }).then(function() { |
| assert.throws(function() { bot.window.back(3); }); |
| if (!goog.userAgent.WEBKIT || bot.userAgent.isEngineVersion('533')) { |
| assert.throws(function() { bot.window.forward(3); }); |
| } |
| done(); |
| }); |
| }); |
| |
| QUnit.test('BackForwardOnePage', function(assert) { |
| var done = assert.async(); |
| initFrame.then(function() { |
| return load('testdata/history_page1.html'); |
| }).then(function() { |
| return load('testdata/history_page2.html'); |
| }).then(function() { |
| return back(1); |
| }).then(function() { |
| assertUrlContains(assert, 'history_page1.html'); |
| return forward(1); |
| }).then(function() { |
| assertUrlContains(assert, 'history_page2.html'); |
| done(); |
| }); |
| }); |
| |
| QUnit.test('BackForwardMultiplePages', function(assert) { |
| var done = assert.async(); |
| initFrame.then(function() { |
| return load('testdata/history_page1.html'); |
| }).then(function() { |
| return load('testdata/history_page2.html'); |
| }).then(function() { |
| return load('testdata/history_page3.html'); |
| }).then(function() { |
| return back(2); |
| }).then(function() { |
| assertUrlContains(assert, 'history_page1.html'); |
| return forward(2); |
| }).then(function() { |
| assertUrlContains(assert, 'history_page3.html'); |
| done(); |
| }); |
| }); |
| </script> |
| </body> |
| </html> |