| 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 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 755 |
| 756 webview.setAttribute('src', 'data:text/html,<html><body>guest</body></html>'); | 756 webview.setAttribute('src', 'data:text/html,<html><body>guest</body></html>'); |
| 757 } | 757 } |
| 758 | 758 |
| 759 // This test verifies that a content script will be injected to the webview when | 759 // This test verifies that a content script will be injected to the webview when |
| 760 // the webview is navigated to a page that matches the URL pattern defined in | 760 // the webview is navigated to a page that matches the URL pattern defined in |
| 761 // the content sript. | 761 // the content sript. |
| 762 function testAddContentScript() { | 762 function testAddContentScript() { |
| 763 var webview = document.createElement('webview'); | 763 var webview = document.createElement('webview'); |
| 764 | 764 |
| 765 console.log("Step 1: call <webview>.addContentScripts."); | 765 console.log('Step 1: call <webview>.addContentScripts.'); |
| 766 webview.addContentScripts( | 766 webview.addContentScripts( |
| 767 [{"name": 'myrule', | 767 [{"name": 'myrule', |
| 768 "matches": ["http://*/extensions/*"], | 768 "matches": ['http://*/extensions/*'], |
| 769 "js": ["inject_comm_channel.js"], | 769 "js": ['inject_comm_channel.js'], |
| 770 "run_at": "document_start"}]); | 770 "run_at": 'document_start'}]); |
| 771 | 771 |
| 772 webview.addEventListener('loadstop', function() { | 772 webview.addEventListener('loadstop', function() { |
| 773 var msg = [request_to_comm_channel_1]; | 773 var msg = [request_to_comm_channel_1]; |
| 774 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 774 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 775 }); | 775 }); |
| 776 | 776 |
| 777 window.addEventListener('message', function(e) { | 777 window.addEventListener('message', function(e) { |
| 778 var data = JSON.parse(e.data); | 778 var data = JSON.parse(e.data); |
| 779 if (data == response_from_comm_channel_1) { | 779 if (data == response_from_comm_channel_1) { |
| 780 console.log( | 780 console.log( |
| 781 'Step 2: A communication channel has been established with webview.'); | 781 'Step 2: A communication channel has been established with webview.'); |
| 782 embedder.test.succeed(); | 782 embedder.test.succeed(); |
| 783 return; | 783 return; |
| 784 } | 784 } |
| 785 console.log('Unexpected message: \'' + data[0] + '\''); | 785 console.log('Unexpected message: \'' + data[0] + '\''); |
| 786 embedder.test.fail(); | 786 embedder.test.fail(); |
| 787 }); | 787 }); |
| 788 | 788 |
| 789 webview.src = embedder.emptyGuestURL; | 789 webview.src = embedder.emptyGuestURL; |
| 790 document.body.appendChild(webview); | 790 document.body.appendChild(webview); |
| 791 } | 791 } |
| 792 | 792 |
| 793 // Adds two content scripts with the same URL pattern to <webview> at the same | 793 // Adds two content scripts with the same URL pattern to <webview> at the same |
| 794 // time. This test verifies that both scripts are injected when the <webview> | 794 // time. This test verifies that both scripts are injected when the <webview> |
| 795 // navigates to a URL that matches the URL pattern. | 795 // navigates to a URL that matches the URL pattern. |
| 796 function testAddMultipleContentScripts() { | 796 function testAddMultipleContentScripts() { |
| 797 var webview = document.createElement('webview'); | 797 var webview = document.createElement('webview'); |
| 798 | 798 |
| 799 console.log("Step 1: call <webview>.addContentScripts(myrule1 & myrule2)"); | 799 console.log('Step 1: call <webview>.addContentScripts(myrule1 & myrule2)'); |
| 800 webview.addContentScripts( | 800 webview.addContentScripts( |
| 801 [{"name": 'myrule1', | 801 [{"name": 'myrule1', |
| 802 "matches": ["http://*/extensions/*"], | 802 "matches": ['http://*/extensions/*'], |
| 803 "js": ["inject_comm_channel.js"], | 803 "js": ['inject_comm_channel.js'], |
| 804 "run_at": "document_start"}, | 804 "run_at": 'document_start'}, |
| 805 {"name": 'myrule2', | 805 {"name": 'myrule2', |
| 806 "matches": ["http://*/extensions/*"], | 806 "matches": ['http://*/extensions/*'], |
| 807 "js": ["inject_comm_channel_2.js"], | 807 "js": ['inject_comm_channel_2.js'], |
| 808 "run_at": "document_start"}]); | 808 "run_at": 'document_start'}]); |
| 809 | 809 |
| 810 webview.addEventListener('loadstop', function() { | 810 webview.addEventListener('loadstop', function() { |
| 811 var msg1 = [request_to_comm_channel_1]; | 811 var msg1 = [request_to_comm_channel_1]; |
| 812 webview.contentWindow.postMessage(JSON.stringify(msg1), '*'); | 812 webview.contentWindow.postMessage(JSON.stringify(msg1), '*'); |
| 813 var msg2 = [request_to_comm_channel_2]; | 813 var msg2 = [request_to_comm_channel_2]; |
| 814 webview.contentWindow.postMessage(JSON.stringify(msg2), '*'); | 814 webview.contentWindow.postMessage(JSON.stringify(msg2), '*'); |
| 815 }); | 815 }); |
| 816 | 816 |
| 817 var response_1 = false; | 817 var response_1 = false; |
| 818 var response_2 = false; | 818 var response_2 = false; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 842 } | 842 } |
| 843 | 843 |
| 844 // Adds a content script to <webview> and navigates. After seeing the script is | 844 // Adds a content script to <webview> and navigates. After seeing the script is |
| 845 // injected, we add another content script with the same name to the <webview>. | 845 // injected, we add another content script with the same name to the <webview>. |
| 846 // This test verifies that the second script will replace the first one and be | 846 // This test verifies that the second script will replace the first one and be |
| 847 // injected after navigating the <webview>. Meanwhile, the <webview> shouldn't | 847 // injected after navigating the <webview>. Meanwhile, the <webview> shouldn't |
| 848 // get any message from the first script anymore. | 848 // get any message from the first script anymore. |
| 849 function testAddContentScriptWithSameNameShouldOverwriteTheExistingOne() { | 849 function testAddContentScriptWithSameNameShouldOverwriteTheExistingOne() { |
| 850 var webview = document.createElement('webview'); | 850 var webview = document.createElement('webview'); |
| 851 | 851 |
| 852 console.log("Step 1: call <webview>.addContentScripts(myrule1)"); | 852 console.log('Step 1: call <webview>.addContentScripts(myrule1)'); |
| 853 webview.addContentScripts( | 853 webview.addContentScripts( |
| 854 [{"name": 'myrule1', | 854 [{"name": 'myrule1', |
| 855 "matches": ["http://*/extensions/*"], | 855 "matches": ['http://*/extensions/*'], |
| 856 "js": ["inject_comm_channel.js"], | 856 "js": ['inject_comm_channel.js'], |
| 857 "run_at": "document_start"}]); | 857 "run_at": 'document_start'}]); |
| 858 var connect_script_1 = true; | 858 var connect_script_1 = true; |
| 859 var connect_script_2 = false; | 859 var connect_script_2 = false; |
| 860 | 860 |
| 861 webview.addEventListener('loadstop', function() { | 861 webview.addEventListener('loadstop', function() { |
| 862 if (connect_script_1) { | 862 if (connect_script_1) { |
| 863 var msg1 = [request_to_comm_channel_1]; | 863 var msg1 = [request_to_comm_channel_1]; |
| 864 webview.contentWindow.postMessage(JSON.stringify(msg1), '*'); | 864 webview.contentWindow.postMessage(JSON.stringify(msg1), '*'); |
| 865 connect_script_1 = false; | 865 connect_script_1 = false; |
| 866 } | 866 } |
| 867 if (connect_script_2) { | 867 if (connect_script_2) { |
| 868 var msg2 = [request_to_comm_channel_2]; | 868 var msg2 = [request_to_comm_channel_2]; |
| 869 webview.contentWindow.postMessage(JSON.stringify(msg2), '*'); | 869 webview.contentWindow.postMessage(JSON.stringify(msg2), '*'); |
| 870 connect_script_2 = false; | 870 connect_script_2 = false; |
| 871 } | 871 } |
| 872 }); | 872 }); |
| 873 | 873 |
| 874 var should_get_response_from_script_1 = true; | 874 var should_get_response_from_script_1 = true; |
| 875 window.addEventListener('message', function(e) { | 875 window.addEventListener('message', function(e) { |
| 876 var data = JSON.parse(e.data); | 876 var data = JSON.parse(e.data); |
| 877 if (data == response_from_comm_channel_1) { | 877 if (data == response_from_comm_channel_1) { |
| 878 if (should_get_response_from_script_1) { | 878 if (should_get_response_from_script_1) { |
| 879 console.log( | 879 console.log( |
| 880 'Step 2: A communication channel has been established with webview.' | 880 'Step 2: A communication channel has been established with webview.' |
| 881 ); | 881 ); |
| 882 webview.addContentScripts( | 882 webview.addContentScripts( |
| 883 [{"name": 'myrule1', | 883 [{"name": 'myrule1', |
| 884 "matches": ["http://*/extensions/*"], | 884 "matches": ['http://*/extensions/*'], |
| 885 "js": ["inject_comm_channel_2.js"], | 885 "js": ['inject_comm_channel_2.js'], |
| 886 "run_at": "document_start"}]); | 886 "run_at": 'document_start'}]); |
| 887 connect_script_2 = true; | 887 connect_script_2 = true; |
| 888 should_get_response_from_script_1 = false; | 888 should_get_response_from_script_1 = false; |
| 889 webview.src = embedder.emptyGuestURL; | 889 webview.src = embedder.emptyGuestURL; |
| 890 } else { | 890 } else { |
| 891 embedder.test.fail(); | 891 embedder.test.fail(); |
| 892 } | 892 } |
| 893 return; | 893 return; |
| 894 } else if (data == response_from_comm_channel_2) { | 894 } else if (data == response_from_comm_channel_2) { |
| 895 console.log( | 895 console.log( |
| 896 'Step 3: Another communication channel has been established ' + | 896 'Step 3: Another communication channel has been established ' + |
| (...skipping 11 matching lines...) Expand all Loading... |
| 908 document.body.appendChild(webview); | 908 document.body.appendChild(webview); |
| 909 } | 909 } |
| 910 | 910 |
| 911 // There are two <webview>s are added to the DOM, and we add a content script | 911 // There are two <webview>s are added to the DOM, and we add a content script |
| 912 // to one of them. This test verifies that the script won't be injected in | 912 // to one of them. This test verifies that the script won't be injected in |
| 913 // the other <webview>. | 913 // the other <webview>. |
| 914 function testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView() { | 914 function testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView() { |
| 915 var webview1 = document.createElement('webview'); | 915 var webview1 = document.createElement('webview'); |
| 916 var webview2 = document.createElement('webview'); | 916 var webview2 = document.createElement('webview'); |
| 917 | 917 |
| 918 console.log("Step 1: call <webview1>.addContentScripts."); | 918 console.log('Step 1: call <webview1>.addContentScripts.'); |
| 919 webview1.addContentScripts( | 919 webview1.addContentScripts( |
| 920 [{"name": 'myrule', | 920 [{"name": 'myrule', |
| 921 "matches": ["http://*/extensions/*"], | 921 "matches": ['http://*/extensions/*'], |
| 922 "js": ["inject_comm_channel.js"], | 922 "js": ['inject_comm_channel.js'], |
| 923 "run_at": "document_start"}]); | 923 "run_at": 'document_start'}]); |
| 924 | 924 |
| 925 webview2.addEventListener('loadstop', function() { | 925 webview2.addEventListener('loadstop', function() { |
| 926 console.log("Step 2: webview2 requests to build communication channel."); | 926 console.log('Step 2: webview2 requests to build communication channel.'); |
| 927 var msg = [request_to_comm_channel_1]; | 927 var msg = [request_to_comm_channel_1]; |
| 928 webview2.contentWindow.postMessage(JSON.stringify(msg), '*'); | 928 webview2.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 929 setTimeout(function() { | 929 setTimeout(function() { |
| 930 embedder.test.succeed(); | 930 embedder.test.succeed(); |
| 931 }, 0); | 931 }, 0); |
| 932 }); | 932 }); |
| 933 | 933 |
| 934 window.addEventListener('message', function(e) { | 934 window.addEventListener('message', function(e) { |
| 935 var data = JSON.parse(e.data); | 935 var data = JSON.parse(e.data); |
| 936 if (data == response_from_comm_channel_1) { | 936 if (data == response_from_comm_channel_1) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 949 | 949 |
| 950 | 950 |
| 951 // Adds a content script to <webview> and navigates to a URL that matches the | 951 // Adds a content script to <webview> and navigates to a URL that matches the |
| 952 // URL pattern defined in the script. After the first navigation, we remove this | 952 // URL pattern defined in the script. After the first navigation, we remove this |
| 953 // script from the <webview> and navigates to the same URL. This test verifies | 953 // script from the <webview> and navigates to the same URL. This test verifies |
| 954 // taht the script is injected during the first navigation, but isn't injected | 954 // taht the script is injected during the first navigation, but isn't injected |
| 955 // after removing it. | 955 // after removing it. |
| 956 function testAddAndRemoveContentScripts() { | 956 function testAddAndRemoveContentScripts() { |
| 957 var webview = document.createElement('webview'); | 957 var webview = document.createElement('webview'); |
| 958 | 958 |
| 959 console.log("Step 1: call <webview>.addContentScripts."); | 959 console.log('Step 1: call <webview>.addContentScripts.'); |
| 960 webview.addContentScripts( | 960 webview.addContentScripts( |
| 961 [{"name": 'myrule', | 961 [{"name": 'myrule', |
| 962 "matches": ["http://*/extensions/*"], | 962 "matches": ['http://*/extensions/*'], |
| 963 "js": ["inject_comm_channel.js"], | 963 "js": ['inject_comm_channel.js'], |
| 964 "run_at": "document_start"}]); | 964 "run_at": 'document_start'}]); |
| 965 | 965 |
| 966 var count = 0; | 966 var count = 0; |
| 967 webview.addEventListener('loadstop', function() { | 967 webview.addEventListener('loadstop', function() { |
| 968 if (count == 0) { | 968 if (count == 0) { |
| 969 console.log('Step 2: post message to build connect.'); | 969 console.log('Step 2: post message to build connect.'); |
| 970 var msg = [request_to_comm_channel_1]; | 970 var msg = [request_to_comm_channel_1]; |
| 971 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 971 webview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 972 ++count; | 972 ++count; |
| 973 } else if (count == 1) { | 973 } else if (count == 1) { |
| 974 console.log( | 974 console.log( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 var webview = document.createElement('webview'); | 1015 var webview = document.createElement('webview'); |
| 1016 | 1016 |
| 1017 var newwebview; | 1017 var newwebview; |
| 1018 webview.addEventListener('newwindow', function(e) { | 1018 webview.addEventListener('newwindow', function(e) { |
| 1019 e.preventDefault(); | 1019 e.preventDefault(); |
| 1020 newwebview = document.createElement('webview'); | 1020 newwebview = document.createElement('webview'); |
| 1021 | 1021 |
| 1022 console.log('Step 2: call newwebview.addContentScripts.'); | 1022 console.log('Step 2: call newwebview.addContentScripts.'); |
| 1023 newwebview.addContentScripts( | 1023 newwebview.addContentScripts( |
| 1024 [{"name": 'myrule', | 1024 [{"name": 'myrule', |
| 1025 "matches": ["http://*/extensions/*"], | 1025 "matches": ['http://*/extensions/*'], |
| 1026 "js": ["inject_comm_channel.js"], | 1026 "js": ['inject_comm_channel.js'], |
| 1027 "run_at": "document_start"}]); | 1027 "run_at": 'document_start'}]); |
| 1028 | 1028 |
| 1029 newwebview.addEventListener('loadstop', function(evt) { | 1029 newwebview.addEventListener('loadstop', function(evt) { |
| 1030 var msg = [request_to_comm_channel_1]; | 1030 var msg = [request_to_comm_channel_1]; |
| 1031 console.log('Step 4: new webview postmessage to build communication ' + | 1031 console.log('Step 4: new webview postmessage to build communication ' + |
| 1032 'channel.'); | 1032 'channel.'); |
| 1033 newwebview.contentWindow.postMessage(JSON.stringify(msg), '*'); | 1033 newwebview.contentWindow.postMessage(JSON.stringify(msg), '*'); |
| 1034 }); | 1034 }); |
| 1035 | 1035 |
| 1036 document.body.appendChild(newwebview); | 1036 document.body.appendChild(newwebview); |
| 1037 // attach the new window to the new <webview>. | 1037 // attach the new window to the new <webview>. |
| 1038 console.log("Step 3: attaches the new webview."); | 1038 console.log('Step 3: attaches the new webview.'); |
| 1039 e.window.attach(newwebview); | 1039 e.window.attach(newwebview); |
| 1040 }); | 1040 }); |
| 1041 | 1041 |
| 1042 window.addEventListener('message', function(e) { | 1042 window.addEventListener('message', function(e) { |
| 1043 var data = JSON.parse(e.data); | 1043 var data = JSON.parse(e.data); |
| 1044 if (data == response_from_comm_channel_1 && | 1044 if (data == response_from_comm_channel_1 && |
| 1045 e.source == newwebview.contentWindow) { | 1045 e.source == newwebview.contentWindow) { |
| 1046 console.log('Step 5: a communication channel has been established ' + | 1046 console.log('Step 5: a communication channel has been established ' + |
| 1047 'with the new webview.'); | 1047 'with the new webview.'); |
| 1048 embedder.test.succeed(); | 1048 embedder.test.succeed(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 // Adds a content script to <webview>. This test verifies that the script is | 1063 // Adds a content script to <webview>. This test verifies that the script is |
| 1064 // injected after terminate and reload <webview>. | 1064 // injected after terminate and reload <webview>. |
| 1065 function testContentScriptIsInjectedAfterTerminateAndReloadWebView() { | 1065 function testContentScriptIsInjectedAfterTerminateAndReloadWebView() { |
| 1066 var webview = document.createElement('webview'); | 1066 var webview = document.createElement('webview'); |
| 1067 | 1067 |
| 1068 console.log('Step 1: call <webview>.addContentScripts.'); | 1068 console.log('Step 1: call <webview>.addContentScripts.'); |
| 1069 webview.addContentScripts( | 1069 webview.addContentScripts( |
| 1070 [{"name": 'myrule', | 1070 [{"name": 'myrule', |
| 1071 "matches": ["http://*/extensions/*"], | 1071 "matches": ['http://*/extensions/*'], |
| 1072 "js": ["inject_comm_channel.js"], | 1072 "js": ['inject_comm_channel.js'], |
| 1073 "run_at": "document_start"}]); | 1073 "run_at": 'document_start'}]); |
| 1074 | 1074 |
| 1075 var count = 0; | 1075 var count = 0; |
| 1076 webview.addEventListener('loadstop', function() { | 1076 webview.addEventListener('loadstop', function() { |
| 1077 if (count == 0) { | 1077 if (count == 0) { |
| 1078 console.log('Step 2: call webview.terminate().'); | 1078 console.log('Step 2: call webview.terminate().'); |
| 1079 webview.terminate(); | 1079 webview.terminate(); |
| 1080 ++count; | 1080 ++count; |
| 1081 return; | 1081 return; |
| 1082 } else if (count == 1) { | 1082 } else if (count == 1) { |
| 1083 console.log('Step 4: postMessage to build communication.'); | 1083 console.log('Step 4: postMessage to build communication.'); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1109 } | 1109 } |
| 1110 | 1110 |
| 1111 // This test verifies the content script won't be removed when the guest is | 1111 // This test verifies the content script won't be removed when the guest is |
| 1112 // destroyed, i.e., removed <webview> from the DOM. | 1112 // destroyed, i.e., removed <webview> from the DOM. |
| 1113 function testContentScriptExistsAsLongAsWebViewTagExists() { | 1113 function testContentScriptExistsAsLongAsWebViewTagExists() { |
| 1114 var webview = document.createElement('webview'); | 1114 var webview = document.createElement('webview'); |
| 1115 | 1115 |
| 1116 console.log('Step 1: call <webview>.addContentScripts.'); | 1116 console.log('Step 1: call <webview>.addContentScripts.'); |
| 1117 webview.addContentScripts( | 1117 webview.addContentScripts( |
| 1118 [{"name": 'myrule', | 1118 [{"name": 'myrule', |
| 1119 "matches": ["http://*/extensions/*"], | 1119 "matches": ['http://*/extensions/*'], |
| 1120 "js": ["simple_script.js"], | 1120 "js": ['simple_script.js'], |
| 1121 "run_at": "document_end"}]); | 1121 "run_at": 'document_end'}]); |
| 1122 | 1122 |
| 1123 var count = 0; | 1123 var count = 0; |
| 1124 webview.addEventListener('loadstop', function() { | 1124 webview.addEventListener('loadstop', function() { |
| 1125 if (count == 0) { | 1125 if (count == 0) { |
| 1126 console.log('Step 2: check the result of content script injected.'); | 1126 console.log('Step 2: check the result of content script injected.'); |
| 1127 webview.executeScript({ | 1127 webview.executeScript({ |
| 1128 code: 'document.body.style.backgroundColor;' | 1128 code: 'document.body.style.backgroundColor;' |
| 1129 }, function(results) { | 1129 }, function(results) { |
| 1130 embedder.test.assertEq(1, results.length); | 1130 embedder.test.assertEq(1, results.length); |
| 1131 embedder.test.assertEq('red', results[0]); | 1131 embedder.test.assertEq('red', results[0]); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1147 embedder.test.assertEq('red', results[0]); | 1147 embedder.test.assertEq('red', results[0]); |
| 1148 embedder.test.succeed(); | 1148 embedder.test.succeed(); |
| 1149 }); | 1149 }); |
| 1150 } | 1150 } |
| 1151 }); | 1151 }); |
| 1152 | 1152 |
| 1153 webview.src = embedder.emptyGuestURL; | 1153 webview.src = embedder.emptyGuestURL; |
| 1154 document.body.appendChild(webview); | 1154 document.body.appendChild(webview); |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 function testAddContentScriptWithCode() { |
| 1158 var webview = document.createElement('webview'); |
| 1159 |
| 1160 console.log('Step 1: call <webview>.addContentScripts.'); |
| 1161 webview.addContentScripts( |
| 1162 [{"name": 'myrule', |
| 1163 "matches": ['http://*/extensions/*'], |
| 1164 "code": 'document.body.style.backgroundColor = \'red\';', |
| 1165 "run_at": 'document_end'}]); |
| 1166 |
| 1167 webview.addEventListener('loadstop', function() { |
| 1168 console.log('Step 2: call webview.executeScript() to check result.') |
| 1169 webview.executeScript({ |
| 1170 code: 'document.body.style.backgroundColor;'}, |
| 1171 function(results) { |
| 1172 embedder.test.assertEq(1, results.length); |
| 1173 embedder.test.assertEq('red', results[0]); |
| 1174 embedder.test.succeed(); |
| 1175 }); |
| 1176 }); |
| 1177 |
| 1178 webview.src = embedder.emptyGuestURL; |
| 1179 document.body.appendChild(webview); |
| 1180 } |
| 1181 |
| 1157 function testExecuteScriptFail() { | 1182 function testExecuteScriptFail() { |
| 1158 var webview = document.createElement('webview'); | 1183 var webview = document.createElement('webview'); |
| 1159 document.body.appendChild(webview); | 1184 document.body.appendChild(webview); |
| 1160 setTimeout(function() { | 1185 setTimeout(function() { |
| 1161 webview.executeScript( | 1186 webview.executeScript( |
| 1162 {code:'document.body.style.backgroundColor = "red";'}, | 1187 {code:'document.body.style.backgroundColor = "red";'}, |
| 1163 function(results) { | 1188 function(results) { |
| 1164 embedder.test.fail(); | 1189 embedder.test.fail(); |
| 1165 }); | 1190 }); |
| 1166 setTimeout(function() { | 1191 setTimeout(function() { |
| (...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2640 testAddContentScriptWithSameNameShouldOverwriteTheExistingOne, | 2665 testAddContentScriptWithSameNameShouldOverwriteTheExistingOne, |
| 2641 'testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView': | 2666 'testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView': |
| 2642 testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView, | 2667 testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView, |
| 2643 'testAddAndRemoveContentScripts': testAddAndRemoveContentScripts, | 2668 'testAddAndRemoveContentScripts': testAddAndRemoveContentScripts, |
| 2644 'testAddContentScriptsWithNewWindowAPI': | 2669 'testAddContentScriptsWithNewWindowAPI': |
| 2645 testAddContentScriptsWithNewWindowAPI, | 2670 testAddContentScriptsWithNewWindowAPI, |
| 2646 'testContentScriptIsInjectedAfterTerminateAndReloadWebView': | 2671 'testContentScriptIsInjectedAfterTerminateAndReloadWebView': |
| 2647 testContentScriptIsInjectedAfterTerminateAndReloadWebView, | 2672 testContentScriptIsInjectedAfterTerminateAndReloadWebView, |
| 2648 'testContentScriptExistsAsLongAsWebViewTagExists': | 2673 'testContentScriptExistsAsLongAsWebViewTagExists': |
| 2649 testContentScriptExistsAsLongAsWebViewTagExists, | 2674 testContentScriptExistsAsLongAsWebViewTagExists, |
| 2675 'testAddContentScriptWithCode': testAddContentScriptWithCode, |
| 2650 'testExecuteScriptFail': testExecuteScriptFail, | 2676 'testExecuteScriptFail': testExecuteScriptFail, |
| 2651 'testExecuteScript': testExecuteScript, | 2677 'testExecuteScript': testExecuteScript, |
| 2652 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged': | 2678 'testExecuteScriptIsAbortedWhenWebViewSourceIsChanged': |
| 2653 testExecuteScriptIsAbortedWhenWebViewSourceIsChanged, | 2679 testExecuteScriptIsAbortedWhenWebViewSourceIsChanged, |
| 2654 'testTerminateAfterExit': testTerminateAfterExit, | 2680 'testTerminateAfterExit': testTerminateAfterExit, |
| 2655 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, | 2681 'testAssignSrcAfterCrash': testAssignSrcAfterCrash, |
| 2656 'testNavOnConsecutiveSrcAttributeChanges': | 2682 'testNavOnConsecutiveSrcAttributeChanges': |
| 2657 testNavOnConsecutiveSrcAttributeChanges, | 2683 testNavOnConsecutiveSrcAttributeChanges, |
| 2658 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, | 2684 'testNavOnSrcAttributeChange': testNavOnSrcAttributeChange, |
| 2659 'testReassignSrcAttribute': testReassignSrcAttribute, | 2685 'testReassignSrcAttribute': testReassignSrcAttribute, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2706 'testPerViewZoomMode': testPerViewZoomMode, | 2732 'testPerViewZoomMode': testPerViewZoomMode, |
| 2707 'testDisabledZoomMode': testDisabledZoomMode, | 2733 'testDisabledZoomMode': testDisabledZoomMode, |
| 2708 }; | 2734 }; |
| 2709 | 2735 |
| 2710 onload = function() { | 2736 onload = function() { |
| 2711 chrome.test.getConfig(function(config) { | 2737 chrome.test.getConfig(function(config) { |
| 2712 embedder.setUp_(config); | 2738 embedder.setUp_(config); |
| 2713 chrome.test.sendMessage("Launched"); | 2739 chrome.test.sendMessage("Launched"); |
| 2714 }); | 2740 }); |
| 2715 }; | 2741 }; |
| OLD | NEW |