| Index: chrome/test/data/extensions/api_test/content_scripts/about_blank_iframes/test.js
|
| diff --git a/chrome/test/data/extensions/api_test/content_scripts/about_blank_iframes/test.js b/chrome/test/data/extensions/api_test/content_scripts/about_blank_iframes/test.js
|
| index c0a3918299a9ad29802932c16b137cb904fb5f05..5d08ce0a68dd5d10f773dea4f73eff7770fbdd86 100644
|
| --- a/chrome/test/data/extensions/api_test/content_scripts/about_blank_iframes/test.js
|
| +++ b/chrome/test/data/extensions/api_test/content_scripts/about_blank_iframes/test.js
|
| @@ -2,25 +2,30 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +function checkFirstMessageEquals(expectedRequest) {
|
| + return function(request) {
|
| + if (request != expectedRequest)
|
| + chrome.test.fail('Unexpected request: ' + JSON.stringify(request));
|
| + // chrome.test.succeed() will be called by chrome.test.listenOnce().
|
| + // If this function is not used by chrome.test.listenOnce(), then
|
| + // call chrome.test.succeed() when you're done.
|
| + };
|
| +}
|
| +
|
| +var onRequest = chrome.extension.onRequest;
|
| chrome.test.getConfig(function(config) {
|
| - chrome.extension.onRequest.addListener(
|
| - function(request, sender, sendResponse) {
|
| - if (request == 'parent')
|
| - chrome.test.succeed();
|
| - else
|
| - chrome.test.fail('Unexpected request: ' + JSON.stringify(request));
|
| - }
|
| - );
|
| chrome.test.runTests([
|
| function testDontInjectInAboutBlankFrame() {
|
| - chrome.test.log("Creating tab...");
|
| + chrome.test.listenOnce(onRequest, checkFirstMessageEquals('parent'));
|
| + chrome.test.log('Creating tab...');
|
| var test_url =
|
| - ("http://localhost:PORT/extensions/" +
|
| - "test_file_with_about_blank_iframe.html")
|
| + ('http://localhost:PORT/extensions/' +
|
| + 'test_file_with_about_blank_iframe.html')
|
| .replace(/PORT/, config.testServer.port);
|
| chrome.tabs.create({ url: test_url });
|
| },
|
| function testDontInjectInAboutSrcdocFrame() {
|
| + chrome.test.listenOnce(onRequest, checkFirstMessageEquals('parent'));
|
| chrome.test.log('Creating tab...');
|
| var test_url =
|
| ('http://localhost:PORT/extensions/' +
|
| @@ -29,12 +34,35 @@ chrome.test.getConfig(function(config) {
|
| chrome.tabs.create({ url: test_url });
|
| },
|
| function testDontInjectInNestedAboutFrames() {
|
| + chrome.test.listenOnce(onRequest, checkFirstMessageEquals('parent'));
|
| chrome.test.log('Creating tab...');
|
| var test_url =
|
| ('http://localhost:PORT/extensions/' +
|
| 'test_file_with_about_blank_in_srcdoc.html')
|
| .replace(/PORT/, config.testServer.port);
|
| chrome.tabs.create({ url: test_url });
|
| + },
|
| + function testDocumentStartRunsInSameWorldAsDocumentEndOfJavaScriptUrl() {
|
| + var hasReceivedFirstMessage = false;
|
| + onRequest.addListener(function listener(request) {
|
| + if (!hasReceivedFirstMessage) {
|
| + hasReceivedFirstMessage = true;
|
| + // Step one: Empty document where the JavaScript code was executed.
|
| + checkFirstMessageEquals('jsresult/')(request);
|
| + } else {
|
| + onRequest.removeListener(listener);
|
| + // Step 2: The empty document was replaced with the result of
|
| + // the evaluated JavaScript code.
|
| + checkFirstMessageEquals('jsresult/something')(request);
|
| + chrome.test.succeed();
|
| + }
|
| + });
|
| + chrome.test.log('Creating tab...');
|
| + var test_url =
|
| + ('http://localhost:PORT/extensions/' +
|
| + 'test_file_with_javascript_url_iframe.html')
|
| + .replace(/PORT/, config.testServer.port);
|
| + chrome.tabs.create({ url: test_url });
|
| }
|
| ]);
|
| });
|
|
|