forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JasonLeyba: Deprecating bot.script.execute in favor of bot.inject.exe…
…cuteAsyncScript and migrating the iPhone from bot.script. r12110
- Loading branch information
Showing
8 changed files
with
2,263 additions
and
1,923 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>inject_async_test</title> | ||
<script src="test_bootstrap.js"></script> | ||
<script> | ||
goog.require('bot.ErrorCode'); | ||
goog.require('bot.inject'); | ||
goog.require('goog.testing.AsyncTestCase'); | ||
goog.require('goog.testing.jsunit'); | ||
goog.require('goog.userAgent'); | ||
goog.require('goog.userAgent.product'); | ||
goog.require('goog.userAgent.product.isVersion'); | ||
</script> | ||
</head> | ||
<body> | ||
<script> | ||
var TEST_CASE = goog.testing.AsyncTestCase.createAndInstall(document.title); | ||
var testWindow; | ||
|
||
function setUp() { | ||
testWindow = window.open(''); | ||
assertNotNull(testWindow); | ||
assertNotUndefined(testWindow); | ||
goog.global.onload = goog.partial(fail, 'Unexpected onload call'); | ||
} | ||
|
||
function tearDown() { | ||
testWindow.close(); | ||
testWindow = null; | ||
} | ||
|
||
function testSynchronizesTimeoutsWithGivenWindow() { | ||
if (goog.userAgent.product.SAFARI && | ||
goog.userAgent.getUserAgentString().search('Version/5') == -1) { | ||
// Fails in Safari prior to v5. | ||
return; | ||
} | ||
|
||
if (goog.userAgent.IE && !goog.userAgent.product.isVersion(8)) { | ||
// Fails in IE 7. | ||
return; | ||
} | ||
|
||
function onDone(response) { | ||
TEST_CASE.continueTesting(); | ||
assertEquals(bot.ErrorCode.SUCCESS, response['status']); | ||
assertEquals(3, response['value']); | ||
} | ||
|
||
TEST_CASE.waitForAsync('bot.inject.executeAsyncScript'); | ||
bot.inject.executeAsyncScript(function() { | ||
var callback = arguments[arguments.length - 1]; | ||
var count = 0; | ||
window.setTimeout(function() {count += 1;}, 250); | ||
window.setTimeout(function() {count += 2;}, 250); | ||
window.setTimeout(function() {callback(count);}, 250); | ||
}, [], 250, onDone, false, testWindow); | ||
} | ||
|
||
function testShouldExecuteInTheContextOfTheProvidedWindow() { | ||
if (goog.userAgent.IE || goog.userAgent.product.SAFARI) { | ||
// IE has trouble communicating with testWindow. | ||
// Safari cannot execute script in testWindow's context. | ||
return; | ||
} | ||
|
||
function onDone(response) { | ||
TEST_CASE.continueTesting(); | ||
assertEquals(bot.ErrorCode.SUCCESS, response['status']); | ||
assertEquals('script_data', response['value']); | ||
} | ||
|
||
TEST_CASE.waitForAsync('waiting for test window to load page'); | ||
goog.global.onload = function(loadedWindow) { | ||
assertEquals('wrong window', testWindow, loadedWindow); | ||
|
||
TEST_CASE.waitForAsync('bot.inject.executeAsyncScript'); | ||
bot.inject.executeAsyncScript(function() { | ||
arguments[arguments.length - 1](document.title); | ||
}, [], 0, onDone, false, testWindow); | ||
}; | ||
testWindow.location = './testdata/script_data.html'; | ||
} | ||
|
||
function testCanDetectPageUnloadEventsAndFailsTheScriptWhenTheyOccur() { | ||
if (goog.userAgent.IE || goog.userAgent.product.SAFARI) { | ||
// IE has trouble communicating with testWindow. | ||
// Safari cannot execute script in testWindow's context. | ||
return; | ||
} | ||
|
||
var navigateTo = window.location.protocol + '//' + window.location.host; | ||
|
||
function onDone(response) { | ||
TEST_CASE.continueTesting(); | ||
assertEquals(bot.ErrorCode.UNKNOWN_ERROR, response['status']); | ||
|
||
var message = response['value']['message']; | ||
assertTrue(message, /Detected a page unload event;/.test(message)); | ||
} | ||
|
||
TEST_CASE.waitForAsync('waiting for test window to load page'); | ||
goog.global.onload = function(loadedWindow) { | ||
assertEquals('wrong window', testWindow, loadedWindow); | ||
|
||
TEST_CASE.waitForAsync('bot.inject.executeAsyncScript'); | ||
bot.inject.executeAsyncScript(function() { | ||
window.location = arguments[0]; | ||
}, [navigateTo], 250, onDone, false, testWindow); | ||
}; | ||
testWindow.location = './testdata/script_data.html'; | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.