OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 REQUEST_TO_COMM_CHANNEL_1 = 'connect'; | 5 var REQUEST_TO_COMM_CHANNEL_1 = 'connect'; |
6 var REQUEST_TO_COMM_CHANNEL_2 = 'connect_request'; | 6 var REQUEST_TO_COMM_CHANNEL_2 = 'connect_request'; |
7 var RESPONSE_FROM_COMM_CHANNEL_1 = 'connected'; | 7 var RESPONSE_FROM_COMM_CHANNEL_1 = 'connected'; |
8 var RESPONSE_FROM_COMM_CHANNEL_2 = 'connected_response'; | 8 var RESPONSE_FROM_COMM_CHANNEL_2 = 'connected_response'; |
9 | 9 |
10 function createWebview() { | 10 function createWebview() { |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 console.log('Step 5: check the result of content script injected again.'); | 437 console.log('Step 5: check the result of content script injected again.'); |
438 webview.executeScript({ | 438 webview.executeScript({ |
439 code: 'document.body.style.backgroundColor;' | 439 code: 'document.body.style.backgroundColor;' |
440 }, onGetBackgroundExecuted); | 440 }, onGetBackgroundExecuted); |
441 } | 441 } |
442 }); | 442 }); |
443 | 443 |
444 webview.src = url; | 444 webview.src = url; |
445 document.body.appendChild(webview); | 445 document.body.appendChild(webview); |
446 } | 446 } |
| 447 |
| 448 function testAddContentScriptWithCode(url) { |
| 449 var webview = document.createElement('webview'); |
| 450 |
| 451 console.log('Step 1: call <webview>.addContentScripts.'); |
| 452 webview.addContentScripts( |
| 453 [{'name': 'myrule', |
| 454 'matches': ['http://*/empty*'], |
| 455 'code': 'document.body.style.backgroundColor = \'red\';', |
| 456 'run_at': 'document_end'}]); |
| 457 |
| 458 webview.addEventListener('loadstop', function() { |
| 459 console.log('Step 2: call webview.executeScript() to check result.') |
| 460 webview.executeScript({ |
| 461 code: 'document.body.style.backgroundColor;' |
| 462 }, onGetBackgroundExecuted); |
| 463 }); |
| 464 |
| 465 webview.src = url; |
| 466 document.body.appendChild(webview); |
| 467 } |
OLD | NEW |