// This test verifies that the loadstop event fires when loading a webview
// accessible resource from a partition that is privileged.
function testChromeExtensionURL() {
- var localResource = chrome.runtime.getURL('guest.html');
+ var localResource = chrome.runtime.getURL('guest_with_inline_script.html');
var webview = document.createElement('webview');
// foobar is a privileged partition according to the manifest file.
webview.partition = 'foobar';
webview.addEventListener('loadstop', function(e) {
embedder.test.succeed();
});
- webview.setAttribute('src', 'guest.html');
+ webview.setAttribute('src', 'guest_with_inline_script.html');
+ document.body.appendChild(webview);
+}
+
+// Makes sure inline scripts works inside guest that was loaded from
+// accessible_resources.
+function testInlineScriptFromAccessibleResources() {
+ var webview = document.createElement('webview');
+ // foobar is a privileged partition according to the manifest file.
+ webview.partition = 'foobar';
+ webview.addEventListener('loadabort', function(e) {
+ embedder.test.fail();
+ });
+ webview.addEventListener('consolemessage', function(e) {
+ window.console.log('consolemessage: ' + e.message);
+ if (e.message == 'guest_with_inline_script.html: Inline script ran') {
+ embedder.test.succeed();
+ }
+ });
+ webview.setAttribute('src', 'guest_with_inline_script.html');
document.body.appendChild(webview);
}
document.body.appendChild(webview);
}
+// This test verifies that the call of executeScript will fail and return null
+// if the webview has been navigated to another source.
+function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() {
+ var webview = document.createElement('webview');
+ var initial = true;
+ var navigationOccur = false;
+ var newSrc = 'data:text/html,trigger navigation';
+ webview.addEventListener('loadstart', function() {
+ if (initial) {
+ webview.setAttribute('src', newSrc);
+ navigationOccur = true;
+ }
+ initial = false;
+ });
+ webview.addEventListener('loadstop', function() {
+ webview.executeScript(
+ {code:'document.body.style.backgroundColor = "red";'},
+ function(results) {
+ if (navigationOccur) {
+ // Expect a null results because the executeScript failed;
+ // return "red", otherwise.
+ embedder.test.assertEq(null, results);
+ embedder.test.succeed();
+ }
+ navigationOccur = false;
+ }
+ );
+ });
+ webview.setAttribute('src', "about:blank");
+ document.body.appendChild(webview);
+}
+
// This test calls terminate() on guest after it has already been
// terminated. This makes sure we ignore the call gracefully.
function testTerminateAfterExit() {
'testAPIMethodExistence': testAPIMethodExistence,
'testChromeExtensionURL': testChromeExtensionURL,
'testChromeExtensionRelativePath': testChromeExtensionRelativePath,
+ 'testInlineScriptFromAccessibleResources':
+ testInlineScriptFromAccessibleResources,
'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL,
'testWebRequestAPIExistence': testWebRequestAPIExistence,
'testEventName': testEventName,
'testPartitionRaisesException': testPartitionRaisesException,
'testExecuteScriptFail': testExecuteScriptFail,
'testExecuteScript': testExecuteScript,
+ 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged':
+ testExecuteScriptIsAbortedWhenWebViewSourceIsChanged,
'testTerminateAfterExit': testTerminateAfterExit,
'testAssignSrcAfterCrash': testAssignSrcAfterCrash,
'testNavOnConsecutiveSrcAttributeChanges':