| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>click_submit_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.action'); | |
| goog.require('bot.locators'); | |
| goog.require('goog.Promise'); | |
| goog.require('goog.Uri'); | |
| goog.require('goog.dom'); | |
| goog.require('goog.events'); | |
| goog.require('goog.events.EventType'); | |
| </script> | |
| <script type="text/javascript"> | |
| var findElement = bot.locators.findElement; | |
| function checkActionCompatibility(action) { | |
| if (action == bot.action.tap) { | |
| return bot.events.SUPPORTS_TOUCH_EVENTS; | |
| } | |
| return true; | |
| } | |
| QUnit.testStart(function() { | |
| var iframe = findElement({id: 'iframe'}); | |
| var iframeWindow = goog.dom.getFrameContentWindow(iframe); | |
| iframeWindow.location = buildAbsoluteUrl('/testdata/click_iframe.html'); | |
| }); | |
| function doesNotSubmitFormWhenEventDefaultPrevented(assert, action) { | |
| if (!checkActionCompatibility(action)) { | |
| assert.ok(true, 'Action not supported, skipping'); | |
| return; | |
| } | |
| var done = assert.async(); | |
| var iframe = findElement({id: 'iframe'}); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| var iframeDoc = goog.dom.getFrameContentDocument(iframe); | |
| var iframeWindow = goog.dom.getFrameContentWindow(iframe); | |
| var clickTarget = findElement({'id': 'submitForm'}, iframeDoc); | |
| var previousLocation = iframeWindow.location.href; | |
| goog.events.listen(clickTarget, goog.events.EventType.CLICK, function(e) { | |
| e.preventDefault(); | |
| }); | |
| action(clickTarget); | |
| assert.strictEqual(iframeWindow.location.href, previousLocation); | |
| done(); | |
| }); | |
| } | |
| QUnit.test('click does not submit form when event default prevented', function(assert) { | |
| doesNotSubmitFormWhenEventDefaultPrevented(assert, bot.action.click); | |
| }); | |
| QUnit.test('tap does not submit form when event default prevented', function(assert) { | |
| doesNotSubmitFormWhenEventDefaultPrevented(assert, bot.action.tap); | |
| }); | |
| function doNotSubmitFormWhenEventDefaultPreventedWithInlineHandler(assert, action) { | |
| if (!checkActionCompatibility(action)) { | |
| assert.ok(true, 'Action not supported, skipping'); | |
| return; | |
| } | |
| var done = assert.async(); | |
| var iframe = findElement({id: 'iframe'}); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| var iframeDoc = goog.dom.getFrameContentDocument(iframe); | |
| var iframeWindow = goog.dom.getFrameContentWindow(iframe); | |
| var clickTarget = | |
| findElement({'id': 'submitFormWithInlineHandler'}, iframeDoc); | |
| var previousLocation = iframeWindow.location.href; | |
| action(clickTarget); | |
| assert.strictEqual(iframeWindow.location.href, previousLocation); | |
| done(); | |
| }); | |
| } | |
| QUnit.test('click do not submit form when event default prevented with inline handler', function(assert) { | |
| doNotSubmitFormWhenEventDefaultPreventedWithInlineHandler(assert, bot.action.click); | |
| }); | |
| QUnit.test('tap do not submit form when event default prevented with inline handler', function(assert) { | |
| doNotSubmitFormWhenEventDefaultPreventedWithInlineHandler(assert, bot.action.tap); | |
| }); | |
| function submitExecutesDefaultHandler(assert, action) { | |
| if (!checkActionCompatibility(action)) { | |
| assert.ok(true, 'Action not supported, skipping'); | |
| return; | |
| } | |
| var done = assert.async(); | |
| var iframe = findElement({id: 'iframe'}); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| var iframeDoc = goog.dom.getFrameContentDocument(iframe); | |
| var iframeWindow = goog.dom.getFrameContentWindow(iframe); | |
| var clickTarget = findElement({'id': 'submitForm'}, iframeDoc); | |
| var targetHref = buildAbsoluteUrl('/testdata/click_destination.html'); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| assert.ok(iframeWindow.location.href.indexOf(targetHref) !== -1); | |
| done(); | |
| }); | |
| action(clickTarget); | |
| }); | |
| } | |
| QUnit.test('click submit executes default handler', function(assert) { | |
| submitExecutesDefaultHandler(assert, bot.action.click); | |
| }); | |
| QUnit.test('tap submit executes default handler', function(assert) { | |
| submitExecutesDefaultHandler(assert, bot.action.tap); | |
| }); | |
| function submitButtonTag(assert, action) { | |
| if (!checkActionCompatibility(action)) { | |
| assert.ok(true, 'Action not supported, skipping'); | |
| return; | |
| } | |
| var done = assert.async(); | |
| var iframe = findElement({id: 'iframe'}); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| var iframeDoc = goog.dom.getFrameContentDocument(iframe); | |
| var iframeWindow = goog.dom.getFrameContentWindow(iframe); | |
| var clickTarget = findElement({'id': 'buttonText'}, iframeDoc); | |
| var targetHref = buildAbsoluteUrl('/testdata/click_destination.html'); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| assert.ok(iframeWindow.location.href.indexOf(targetHref) !== -1); | |
| done(); | |
| }); | |
| action(clickTarget); | |
| }); | |
| } | |
| QUnit.test('click submit button tag', function(assert) { | |
| submitButtonTag(assert, bot.action.click); | |
| }); | |
| QUnit.test('tap submit button tag', function(assert) { | |
| submitButtonTag(assert, bot.action.tap); | |
| }); | |
| function formWithCorrectSubmitButton(assert, action) { | |
| if (!checkActionCompatibility(action)) { | |
| assert.ok(true, 'Action not supported, skipping'); | |
| return; | |
| } | |
| var done = assert.async(); | |
| var iframe = findElement({id: 'iframe'}); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| var iframeDoc = goog.dom.getFrameContentDocument(iframe); | |
| var iframeWindow = goog.dom.getFrameContentWindow(iframe); | |
| var clickTarget = findElement({'id': 'submitForm'}, iframeDoc); | |
| goog.events.listenOnce(iframe, 'load', function() { | |
| assert.ok(iframeWindow.location.href.indexOf('submitButton=Submit') !== -1); | |
| done(); | |
| }); | |
| action(clickTarget); | |
| }); | |
| } | |
| QUnit.test('click form with correct submit button', function(assert) { | |
| formWithCorrectSubmitButton(assert, bot.action.click); | |
| }); | |
| QUnit.test('tap form with correct submit button', function(assert) { | |
| formWithCorrectSubmitButton(assert, bot.action.tap); | |
| }); | |
| function buildAbsoluteUrl(url) { | |
| var loc = location.href; | |
| return loc.substring(0, loc.lastIndexOf('/')) + url; | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <div id="qunit"></div> | |
| <div id="qunit-fixture"></div> | |
| <iframe id="iframe" src="testdata/click_iframe.html"> | |
| </iframe> | |
| </body> | |
| </html> |