Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: extensions/test/data/web_view/apitest/main.js

Issue 843953003: Fixed testExecuteScriptIsAbortedWhenWebViewSourceIsChanged raciness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/extensions/platform_apps/web_view/shim/main.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var embedder = {}; 5 var embedder = {};
6 6
7 // TODO(lfg) Move these functions to a common js. 7 // TODO(lfg) Move these functions to a common js.
8 embedder.setUp_ = function(config) { 8 embedder.setUp_ = function(config) {
9 if (!config || !config.testServer) { 9 if (!config || !config.testServer) {
10 return; 10 return;
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 {code:'document.body.style.backgroundColor = "red";'}, 674 {code:'document.body.style.backgroundColor = "red";'},
675 function(results) { 675 function(results) {
676 embedder.test.fail(); 676 embedder.test.fail();
677 }); 677 });
678 setTimeout(function() { 678 setTimeout(function() {
679 embedder.test.succeed(); 679 embedder.test.succeed();
680 }, 0); 680 }, 0);
681 }, 0); 681 }, 0);
682 } 682 }
683 683
684 // This test verifies that the call of executeScript will fail and return null 684 // This test verifies that the call to executeScript will fail and return null
685 // if the webview has been navigated to another source. 685 // if the webview has been navigated between the time the call was made and the
686 // time it arrives in the guest process.
686 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() { 687 function testExecuteScriptIsAbortedWhenWebViewSourceIsChanged() {
687 var webview = document.createElement('webview'); 688 var webview = document.createElement('webview');
688 var initial = true; 689 webview.addEventListener('loadstop', function onLoadStop(e) {
689 var navigationOccur = false; 690 window.console.log('2. Inject script to trigger a guest-initiated ' +
690 var newSrc = 'data:text/html,trigger navigation'; 691 'navigation.');
691 webview.addEventListener('loadstart', function() { 692 var navUrl = 'data:text/html,trigger nav';
692 if (initial) { 693 webview.executeScript({
693 webview.setAttribute('src', newSrc); 694 code: 'window.location.href = "' + navUrl + '";'
694 navigationOccur = true; 695 });
695 } 696
696 initial = false; 697 window.console.log('3. Listening for the load that will be started as a ' +
697 }); 698 'result of 2.');
698 webview.addEventListener('loadstop', function() { 699 webview.addEventListener('loadstart', function onLoadStart(e) {
699 webview.executeScript( 700 embedder.test.assertEq('about:blank', webview.src);
700 {code:'document.body.style.backgroundColor = "red";'}, 701 window.console.log('4. Attempting to inject script into about:blank. ' +
701 function(results) { 702 'This is expected to fail.');
702 if (navigationOccur) { 703 webview.executeScript(
703 // Expect a null results because the executeScript failed; 704 { code: 'document.body.style.backgroundColor = "red";' },
704 // return "red", otherwise. 705 function(results) {
706 window.console.log(
707 '5. Verify that executeScript has, indeed, failed.');
705 embedder.test.assertEq(null, results); 708 embedder.test.assertEq(null, results);
709 embedder.test.assertEq(navUrl, webview.src);
706 embedder.test.succeed(); 710 embedder.test.succeed();
707 } 711 }
708 navigationOccur = false; 712 );
709 } 713 webview.removeEventListener('loadstart', onLoadStart);
710 ); 714 });
715 webview.removeEventListener('loadstop', onLoadStop);
711 }); 716 });
712 webview.setAttribute('src', "about:blank"); 717
718 window.console.log('1. Performing initial navigation.');
719 webview.setAttribute('src', 'about:blank');
713 document.body.appendChild(webview); 720 document.body.appendChild(webview);
714 } 721 }
715 722
716 function testFindAPI() { 723 function testFindAPI() {
717 var webview = new WebView(); 724 var webview = new WebView();
718 webview.src = 'data:text/html,Dog dog dog Dog dog dogcatDog dogDogdog.<br>' + 725 webview.src = 'data:text/html,Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
719 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' + 726 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
720 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' + 727 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
721 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' + 728 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
722 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' + 729 'Dog dog dog Dog dog dogcatDog dogDogdog.<br>' +
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 'testWebRequestAPIExistence': testWebRequestAPIExistence, 1733 'testWebRequestAPIExistence': testWebRequestAPIExistence,
1727 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty 1734 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty
1728 }; 1735 };
1729 1736
1730 onload = function() { 1737 onload = function() {
1731 chrome.test.getConfig(function(config) { 1738 chrome.test.getConfig(function(config) {
1732 embedder.setUp_(config); 1739 embedder.setUp_(config);
1733 chrome.test.sendMessage('LAUNCHED'); 1740 chrome.test.sendMessage('LAUNCHED');
1734 }); 1741 });
1735 }; 1742 };
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/platform_apps/web_view/shim/main.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698