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
3 // found in the LICENSE file.
5 var EVENT_MESSAGE_EXTENSION_STRING = "Extension";
7 // Constants as functions, not to be called until after runTests.
8 function getURLHttpSimpleLoad() {
9 return getServerURL('extensions/api_test/webrequest/simpleLoad/a.html');
12 function getServerURL(path) {
13 return 'http://www.a.com:' + testServerPort + '/' + path;
16 function runTests(tests) {
17 chrome.test.getConfig(function(config) {
18 testServerPort = config.testServer.port;
19 chrome.test.runTests(tests);
26 if (obj.hasOwnProperty(key)) size++;
32 function testSendMessage() {
33 var expectedEvents = {
34 "onBeforeRequest-Extension": 1,
35 "onBeforeSendHeaders-Extension": 1,
36 "onHeadersReceived-Extension": 1
37 // "onAuthRequired-Extension" is not sent for this test case.
39 var done = chrome.test.listenForever(
40 chrome.declarativeWebRequest.onMessage,
42 if (EVENT_MESSAGE_EXTENSION_STRING != details.message) {
43 chrome.test.fail("Invalid message: " + details.message);
45 chrome.test.assertEq(getURLHttpSimpleLoad(), details.url);
46 var messageKey = details.stage + "-" + details.message;
47 if (messageKey in expectedEvents) {
48 delete expectedEvents[messageKey];
49 if (size(expectedEvents) == 0) {
57 chrome.declarativeWebRequest.onRequest.removeRules(null, function() {
60 new chrome.declarativeWebRequest.RequestMatcher(
61 {url: {urlEquals: getURLHttpSimpleLoad()}}),
64 new chrome.declarativeWebRequest.SendMessageToExtension(
65 {message: EVENT_MESSAGE_EXTENSION_STRING}),
68 chrome.declarativeWebRequest.onRequest.addRules([rule], function() {
69 chrome.tabs.create({"url": getURLHttpSimpleLoad()});