3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../http/tests/inspector/extensions-test.js"></script>
5 <script src=
"../../http/tests/inspector/debugger-test.js"></script>
6 <script src=
"../sources/debugger/resources/edit-me.js"></script>
7 <script type=
"text/javascript">
9 function initialize_extensionsSidebarTest()
11 InspectorTest
.expandSidebar = function(callback
)
13 var sidebar
= InspectorTest
._extensionSidebar();
14 InspectorTest
.runAfterPendingDispatches(function() {
20 InspectorTest
._extensionSidebar = function()
22 return WebInspector
.extensionServer
.sidebarPanes()[0];
26 function extension_expandSidebar(callback
)
28 evaluateOnFrontend("InspectorTest.expandSidebar(reply);", callback
);
31 function extension_testOnSelectionChanged(nextTest
)
33 function onSelectionChanged()
35 webInspector
.panels
.elements
.onSelectionChanged
.removeListener(onSelectionChanged
);
36 output("onSelectionChanged fired");
39 webInspector
.panels
.elements
.onSelectionChanged
.addListener(onSelectionChanged
);
40 webInspector
.inspectedWindow
.eval("inspect(document.body.children[0]), 0");
43 function extension_testOnRequestFinished(nextTest
)
45 function onRequestFinished()
47 webInspector
.network
.onRequestFinished
.removeListener(onRequestFinished
);
48 output("onRequestFinished fired");
51 webInspector
.network
.onRequestFinished
.addListener(onRequestFinished
);
52 webInspector
.inspectedWindow
.eval("var xhr = new XMLHttpRequest(); xhr.open('GET', '" + location
.href
+ "', false); xhr.send(null);");
55 function extension_testOnNavigated(nextTest
)
65 function processEvent()
67 if (loadCount
!== urls
.length
)
70 evaluateOnFrontend("InspectorTest.navigate(InspectorTest.resourceTreeModel.inspectedPageURL().substring(0, InspectorTest.resourceTreeModel.inspectedPageURL().indexOf('?')), reply)", onLoad
);
72 webInspector
.network
.onNavigated
.removeListener(onNavigated
);
73 for (var i
= 0; i
< urls
.length
; ++i
)
74 output("Navigated to: " + urls
[i
]);
78 function onNavigated(url
)
80 urls
.push(url
.replace(/^(.*\/)*/, ""));
83 webInspector
.network
.onNavigated
.addListener(onNavigated
);
84 evaluateOnFrontend("InspectorTest.navigate(InspectorTest.resourceTreeModel.inspectedPageURL() + '?navigated', reply)", onLoad
);
87 function extension_testViewShowHide(nextTest
)
89 var listenersToCleanup
= [];
91 var beenToExtensionPanel
= false;
93 function onViewEvent(type
, viewName
, viewWindow
)
95 output("Got " + type
+ " event for " + viewName
);
96 if (type
!== "onShown")
98 if (viewName
=== "panel") {
99 output("Panel shown, location: " + trimURL(viewWindow
.location
.href
));
100 extension_showPanel("elements");
101 } else if (viewName
=== "sidebar") {
102 output("Sidebar shown, location: " + trimURL(viewWindow
.location
.href
));
103 if (!beenToExtensionPanel
) {
104 extension_showPanel("extension");
105 beenToExtensionPanel
= true;
112 function addListener(view
, viewName
, type
)
114 var listener
= bind(onViewEvent
, null, type
, viewName
);
115 var event
= view
[type
];
116 listenersToCleanup
.push({ event
: event
, listener
: listener
});
117 event
.addListener(listener
);
119 function cleanupListeners()
121 for (var i
= 0; i
< listenersToCleanup
.length
; ++i
)
122 listenersToCleanup
[i
].event
.removeListener(listenersToCleanup
[i
].listener
);
124 function onPanelCreated(panel
)
126 addListener(panel
, "panel", "onShown");
127 addListener(panel
, "panel", "onHidden");
128 addListener(sidebar
, "sidebar", "onHidden");
129 addListener(sidebar
, "sidebar", "onShown");
130 sidebar
.setPage(basePath
+ "extension-sidebar.html");
132 extension_showPanel("elements", extension_expandSidebar
);
133 var basePath
= location
.pathname
.replace(/\/[^/]*$/, "/");
134 function onSidebarCreated(sidebarPane)
136 sidebar = sidebarPane;
137 webInspector.panels.create("Test Panel
", basePath + "extension
-panel
.png
", basePath + "extension
-panel
.html
", onPanelCreated);
139 webInspector.panels.elements.createSidebarPane("Test Sidebar
", onSidebarCreated);
144 <body onload="runTest()">
145 <p>Tests WebInspector extension API</p>