Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1542 // webview. | 1542 // webview. |
| 1543 function testWebRequestAPI() { | 1543 function testWebRequestAPI() { |
| 1544 var webview = new WebView(); | 1544 var webview = new WebView(); |
| 1545 webview.request.onBeforeRequest.addListener(function(e) { | 1545 webview.request.onBeforeRequest.addListener(function(e) { |
| 1546 embedder.test.succeed(); | 1546 embedder.test.succeed(); |
| 1547 }, { urls: ['<all_urls>']}) ; | 1547 }, { urls: ['<all_urls>']}) ; |
| 1548 webview.src = embedder.windowOpenGuestURL; | 1548 webview.src = embedder.windowOpenGuestURL; |
| 1549 document.body.appendChild(webview); | 1549 document.body.appendChild(webview); |
| 1550 } | 1550 } |
| 1551 | 1551 |
| 1552 // This test verifies that the WebRequest API onBeforeSendHeaders event fires on | |
| 1553 // webview and supports headers. This tests verifies that we can modify HTTP | |
| 1554 // headers via the WebRequest API and those modified headers will be sent to the | |
| 1555 // HTTP server. | |
| 1556 function testWebRequestAPIWithHeaders() { | |
| 1557 var webview = new WebView(); | |
| 1558 var requestFilter = { | |
| 1559 urls: ['<all_urls>'] | |
| 1560 }; | |
| 1561 var extraInfoSpec = ['requestHeaders', 'blocking']; | |
| 1562 webview.request.onBeforeSendHeaders.addListener(function(details) { | |
| 1563 var headers = details.requestHeaders; | |
| 1564 for( var i = 0, l = headers.length; i < l; ++i ) { | |
| 1565 if (headers[i].name == 'User-Agent') { | |
| 1566 headers[i].value = 'foobar'; | |
| 1567 break; | |
| 1568 } | |
| 1569 } | |
| 1570 var blockingResponse = {}; | |
| 1571 blockingResponse.requestHeaders = headers; | |
| 1572 return blockingResponse; | |
| 1573 }, requestFilter, extraInfoSpec); | |
| 1574 | |
| 1575 var loadstartCalled = false; | |
| 1576 webview.addEventListener('loadstart', function(e) { | |
| 1577 embedder.test.assertTrue(e.isTopLevel); | |
| 1578 embedder.test.assertEq(embedder.detectUserAgentURL, e.url); | |
| 1579 loadstartCalled = true; | |
| 1580 }); | |
| 1581 | |
| 1582 webview.addEventListener('loadredirect', function(e) { | |
| 1583 embedder.test.assertTrue(e.isTopLevel); | |
| 1584 embedder.test.assertEq(embedder.detectUserAgentURL, | |
| 1585 e.oldUrl.replace('127.0.0.1', 'localhost')); | |
| 1586 embedder.test.assertEq(embedder.redirectGuestURLDest, | |
| 1587 e.newUrl.replace('127.0.0.1', 'localhost')); | |
| 1588 if (loadstartCalled) { | |
| 1589 embedder.test.succeed(); | |
| 1590 } else { | |
| 1591 embedder.test.fail(); | |
| 1592 } | |
| 1593 }); | |
| 1594 webview.src = embedder.detectUserAgentURL; | |
|
lfg
2014/10/08 17:23:31
This needs to be defined on top of this file.
Fady Samuel
2014/10/08 19:18:50
Done.
| |
| 1595 document.body.appendChild(webview); | |
| 1596 } | |
| 1597 | |
| 1552 function testWebRequestAPIExistence() { | 1598 function testWebRequestAPIExistence() { |
| 1553 var apiPropertiesToCheck = [ | 1599 var apiPropertiesToCheck = [ |
| 1554 // Declarative WebRequest API. | 1600 // Declarative WebRequest API. |
| 1555 'onMessage', | 1601 'onMessage', |
| 1556 'onRequest', | 1602 'onRequest', |
| 1557 // WebRequest API. | 1603 // WebRequest API. |
| 1558 'onBeforeRequest', | 1604 'onBeforeRequest', |
| 1559 'onBeforeSendHeaders', | 1605 'onBeforeSendHeaders', |
| 1560 'onSendHeaders', | 1606 'onSendHeaders', |
| 1561 'onHeadersReceived', | 1607 'onHeadersReceived', |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1675 'testWebRequestAPIExistence': testWebRequestAPIExistence, | 1721 'testWebRequestAPIExistence': testWebRequestAPIExistence, |
| 1676 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty | 1722 'testWebRequestAPIGoogleProperty': testWebRequestAPIGoogleProperty |
| 1677 }; | 1723 }; |
| 1678 | 1724 |
| 1679 onload = function() { | 1725 onload = function() { |
| 1680 chrome.test.getConfig(function(config) { | 1726 chrome.test.getConfig(function(config) { |
| 1681 embedder.setUp_(config); | 1727 embedder.setUp_(config); |
| 1682 chrome.test.sendMessage('LAUNCHED'); | 1728 chrome.test.sendMessage('LAUNCHED'); |
| 1683 }); | 1729 }); |
| 1684 }; | 1730 }; |
| OLD | NEW |