OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 util = {}; | 5 var util = {}; |
6 var embedder = {}; | 6 var embedder = {}; |
7 embedder.baseGuestURL = ''; | 7 embedder.baseGuestURL = ''; |
8 embedder.emptyGuestURL = ''; | 8 embedder.emptyGuestURL = ''; |
9 embedder.windowOpenGuestURL = ''; | 9 embedder.windowOpenGuestURL = ''; |
10 embedder.noReferrerGuestURL = ''; | 10 embedder.noReferrerGuestURL = ''; |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 // Removing after navigation should not change the partition. | 742 // Removing after navigation should not change the partition. |
743 webview.removeAttribute('partition'); | 743 webview.removeAttribute('partition'); |
744 embedder.test.assertEq('testme', webview.partition); | 744 embedder.test.assertEq('testme', webview.partition); |
745 embedder.test.succeed(); | 745 embedder.test.succeed(); |
746 }; | 746 }; |
747 webview.addEventListener('loadstop', loadstopHandler); | 747 webview.addEventListener('loadstop', loadstopHandler); |
748 | 748 |
749 webview.setAttribute('src', 'data:text/html,<html><body>guest</body></html>'); | 749 webview.setAttribute('src', 'data:text/html,<html><body>guest</body></html>'); |
750 } | 750 } |
751 | 751 |
| 752 function testAddAndRemoveContentScripts() { |
| 753 var webview = document.createElement('webview'); |
| 754 |
| 755 var count = 0; |
| 756 webview.addEventListener('loadstop', function() { |
| 757 if (count == 0) { |
| 758 webview.addContentScripts( |
| 759 [{"name": 'myrule', |
| 760 "matches": ["http://*/extensions/*"], |
| 761 "js": ["simple_script.js"]}], |
| 762 function() { |
| 763 window.console.log("Step 1: addContentScripts is called."); |
| 764 webview.src = embedder.emptyGuestURL; |
| 765 ++count; |
| 766 }); |
| 767 } else if (count == 1) { |
| 768 webview.executeScript( |
| 769 {code: 'document.body.style.backgroundColor;'}, |
| 770 function(results) { |
| 771 embedder.test.assertEq(1, results.length); |
| 772 embedder.test.assertEq('red', results[0]); |
| 773 window.console.log( |
| 774 "Step 2: content scripts are injected during navigation."); |
| 775 webview.src = "about:blank"; |
| 776 ++count; |
| 777 }); |
| 778 } else if (count == 2) { |
| 779 webview.removeContentScripts( |
| 780 function() { |
| 781 window.console.log("Step 3: removeContentScripts is called."); |
| 782 webview.src = embedder.emptyGuestURL; |
| 783 ++count; |
| 784 }); |
| 785 } else if (count == 3) { |
| 786 webview.executeScript( |
| 787 {code: 'document.body.style.backgroundColor;'}, |
| 788 function(results) { |
| 789 embedder.test.assertEq(1, results.length); |
| 790 embedder.test.assertEq('', results[0]); |
| 791 window.console.log( |
| 792 "Step 4: content scripts are successfully removed."); |
| 793 embedder.test.succeed(); |
| 794 }); |
| 795 } |
| 796 }); |
| 797 webview.setAttribute('src', 'about:blank'); |
| 798 document.body.appendChild(webview); |
| 799 } |
| 800 |
752 function testExecuteScriptFail() { | 801 function testExecuteScriptFail() { |
753 var webview = document.createElement('webview'); | 802 var webview = document.createElement('webview'); |
754 document.body.appendChild(webview); | 803 document.body.appendChild(webview); |
755 setTimeout(function() { | 804 setTimeout(function() { |
756 webview.executeScript( | 805 webview.executeScript( |
757 {code:'document.body.style.backgroundColor = "red";'}, | 806 {code:'document.body.style.backgroundColor = "red";'}, |
758 function(results) { | 807 function(results) { |
759 embedder.test.fail(); | 808 embedder.test.fail(); |
760 }); | 809 }); |
761 setTimeout(function() { | 810 setTimeout(function() { |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL, | 2098 'testInvalidChromeExtensionURL': testInvalidChromeExtensionURL, |
2050 'testWebRequestAPIExistence': testWebRequestAPIExistence, | 2099 'testWebRequestAPIExistence': testWebRequestAPIExistence, |
2051 'testEventName': testEventName, | 2100 'testEventName': testEventName, |
2052 'testOnEventProperties': testOnEventProperties, | 2101 'testOnEventProperties': testOnEventProperties, |
2053 'testLoadProgressEvent': testLoadProgressEvent, | 2102 'testLoadProgressEvent': testLoadProgressEvent, |
2054 'testDestroyOnEventListener': testDestroyOnEventListener, | 2103 'testDestroyOnEventListener': testDestroyOnEventListener, |
2055 'testCannotMutateEventName': testCannotMutateEventName, | 2104 'testCannotMutateEventName': testCannotMutateEventName, |
2056 'testPartitionChangeAfterNavigation': testPartitionChangeAfterNavigation, | 2105 'testPartitionChangeAfterNavigation': testPartitionChangeAfterNavigation, |
2057 'testPartitionRemovalAfterNavigationFails': | 2106 'testPartitionRemovalAfterNavigationFails': |
2058 testPartitionRemovalAfterNavigationFails, | 2107 testPartitionRemovalAfterNavigationFails, |
| 2108 'testAddAndRemoveContentScripts': testAddAndRemoveContentScripts, |
2059 'testExecuteScriptFail': testExecuteScriptFail, | 2109 'testExecuteScriptFail': testExecuteScriptFail, |
2060 'testExecuteScript': testExecuteScript, | 2110 'testExecuteScript': testExecuteScript, |
2061 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged': | 2111 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged': |
2062 testExecuteScriptIsAbortedWhenWebViewSourceIsChanged, | 2112 testExecuteScriptIsAbortedWhenWebViewSourceIsChanged, |
2063 'testTerminateAfterExit': testTerminateAfterExit, | 2113 'testTerminateAfterExit': testTerminateAfterExit, |
2064 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, | 2114 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, |
2065 'testNavOnConsecutiveSrcAttributeChanges': | 2115 'testNavOnConsecutiveSrcAttributeChanges': |
2066 testNavOnConsecutiveSrcAttributeChanges, | 2116 testNavOnConsecutiveSrcAttributeChanges, |
2067 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, | 2117 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, |
2068 'testReassignSrcAttribute': testReassignSrcAttribute, | 2118 'testReassignSrcAttribute': testReassignSrcAttribute, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 'testFindAPI_findupdate': testFindAPI, | 2160 'testFindAPI_findupdate': testFindAPI, |
2111 'testLoadDataAPI': testLoadDataAPI | 2161 'testLoadDataAPI': testLoadDataAPI |
2112 }; | 2162 }; |
2113 | 2163 |
2114 onload = function() { | 2164 onload = function() { |
2115 chrome.test.getConfig(function(config) { | 2165 chrome.test.getConfig(function(config) { |
2116 embedder.setUp_(config); | 2166 embedder.setUp_(config); |
2117 chrome.test.sendMessage("Launched"); | 2167 chrome.test.sendMessage("Launched"); |
2118 }); | 2168 }); |
2119 }; | 2169 }; |
OLD | NEW |