summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-10 15:37:58 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-10 15:37:58 +0000
commitf873d0f49aa098cea3f737d25d8c1adae5365c1c (patch)
treed6f0a8da5e7bf463776eaeccb3d4cf14255c7868
parent0f76308c1ff77b73e0a6538c97eb30d06dfdc854 (diff)
downloadchromium_src-f873d0f49aa098cea3f737d25d8c1adae5365c1c.zip
chromium_src-f873d0f49aa098cea3f737d25d8c1adae5365c1c.tar.gz
chromium_src-f873d0f49aa098cea3f737d25d8c1adae5365c1c.tar.bz2
DevTools: Add test for resource panel enabling.
Review URL: http://codereview.chromium.org/118502 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18059 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/debugger/devtools_sanity_unittest.cc7
-rw-r--r--webkit/glue/devtools/js/devtools_host_stub.js38
-rw-r--r--webkit/glue/devtools/js/inspector_controller.js5
-rw-r--r--webkit/glue/devtools/js/tests.js108
4 files changed, 145 insertions, 13 deletions
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc
index 09b3cca..270665e 100644
--- a/chrome/browser/debugger/devtools_sanity_unittest.cc
+++ b/chrome/browser/debugger/devtools_sanity_unittest.cc
@@ -104,9 +104,14 @@ IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestElementsTreeRoot) {
RunTest("testElementsTreeRoot");
}
-// Tests resources panel basics.
+// Tests main resource load.
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestMainResource) {
RunTest("testMainResource");
}
+// Tests resources panel enabling.
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestEnableResourcesTab) {
+ RunTest("testEnableResourcesTab");
+}
+
} // namespace
diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js
index bfa7304..42a27ea 100644
--- a/webkit/glue/devtools/js/devtools_host_stub.js
+++ b/webkit/glue/devtools/js/devtools_host_stub.js
@@ -241,6 +241,7 @@ RemoteToolsAgentStub.prototype.SetResourceTrackingEnabled = function(enabled, al
} else {
WebInspector.resourceTrackingWasDisabled();
}
+ addDummyResource();
};
@@ -285,16 +286,51 @@ DevToolsHostStub = function() {
};
+function addDummyResource() {
+ var payload = {
+ requestHeaders : {},
+ requestURL: 'http://google.com/simple_page.html',
+ host: 'google.com',
+ path: 'simple_page.html',
+ lastPathComponent: 'simple_page.html',
+ isMainResource: true,
+ cached: false,
+ mimeType: 'text/html',
+ suggestedFilename: 'simple_page.html',
+ expectedContentLength: 10000,
+ statusCode: 200,
+ contentLength: 10000,
+ responseHeaders: {},
+ type: WebInspector.Resource.Type.Document,
+ finished: true,
+ startTime: new Date(),
+
+ didResponseChange: true,
+ didCompletionChange: true,
+ didTypeChange: true
+ };
+
+ WebInspector.addResource(1, payload);
+ WebInspector.updateResource(1, payload);
+}
+
+
DevToolsHostStub.prototype.loaded = function() {
RemoteDomAgentStub.sendDocumentElement_();
RemoteDomAgentStub.sendChildNodes_(1);
RemoteDomAgentStub.sendChildNodes_(2);
devtools.tools.updateFocusedNode_(4);
- devtools.tools.addMessageToConsole_('message', 'source', 3);
+ addDummyResource();
+
uiTests.runAllTests();
};
+DevToolsHostStub.prototype.addResourceSourceToFrame = function(
+ identifier, mimeType, element) {
+};
+
+
if (!window['DevToolsHost']) {
window['RemoteDebuggerAgent'] = new RemoteDebuggerAgentStub();
window['RemoteDebuggerCommandExecutor'] =
diff --git a/webkit/glue/devtools/js/inspector_controller.js b/webkit/glue/devtools/js/inspector_controller.js
index 4f9ae30..5401b49 100644
--- a/webkit/glue/devtools/js/inspector_controller.js
+++ b/webkit/glue/devtools/js/inspector_controller.js
@@ -41,6 +41,11 @@ devtools.InspectorController = function() {
* @type {boolean}
*/
this.profilerEnabled_ = true;
+
+ /**
+ * @type {boolean}
+ */
+ this.resourceTrackingEnabled_ = false;
};
diff --git a/webkit/glue/devtools/js/tests.js b/webkit/glue/devtools/js/tests.js
index a2d5a28..2507ed6 100644
--- a/webkit/glue/devtools/js/tests.js
+++ b/webkit/glue/devtools/js/tests.js
@@ -27,7 +27,7 @@ TestSuite = function() {
*/
TestSuite.prototype.fail = function(message) {
throw message;
-}
+};
/**
@@ -39,7 +39,7 @@ TestSuite.prototype.assertEquals = function(expected, actual) {
if (expected != actual) {
this.fail('Expected: "' + expected + '", but was "' + actual + '"');
}
-}
+};
/**
@@ -49,7 +49,7 @@ TestSuite.prototype.assertEquals = function(expected, actual) {
*/
TestSuite.prototype.assertTrue = function(value) {
this.assertEquals(true, value);
-}
+};
/**
@@ -63,20 +63,78 @@ TestSuite.prototype.runAllTests = function() {
this.runTest(name);
}
}
-}
+};
+
+
+/**
+ * Async tests use this one to report that they are completed.
+ */
+TestSuite.prototype.reportOk = function() {
+ window.domAutomationController.send('[OK]');
+};
+
+
+/**
+ * Manual controller for async tests.
+ * @constructor.
+ */
+TestSuite.Controller = function() {
+ this.controlTaken_ = false;
+ this.timerId_ = -1;
+};
+
+
+/**
+ * Takes control over execution.
+ */
+TestSuite.Controller.prototype.takeControl = function() {
+ this.controlTaken_ = true;
+ // Set up guard timer.
+ var self = this;
+ this.timerId_ = setTimeout(function() {
+ self.reportFailure('Timeout exceeded: 20 sec');
+ }, 20000);
+};
+
+
+/**
+ * Async tests use this one to report that they are completed.
+ */
+TestSuite.Controller.prototype.reportOk = function() {
+ if (this.timerId_ != -1) {
+ this.timerId_ = -1;
+ clearTimeout(this.timerId_);
+ }
+ window.domAutomationController.send('[OK]');
+};
+
+
+/**
+ * Async tests use this one to report failures.
+ */
+TestSuite.Controller.prototype.reportFailure = function(error) {
+ if (this.timerId_ != -1) {
+ this.timerId_ = -1;
+ clearTimeout(this.timerId_);
+ }
+ window.domAutomationController.send('[FAILED] ' + error);
+};
/**
* Runs all global functions starting with 'test' as unit tests.
*/
TestSuite.prototype.runTest = function(testName) {
+ var controller = new TestSuite.Controller();
try {
- this[testName]();
- window.domAutomationController.send('[OK]');
+ this[testName](controller);
+ if (!controller.controlTaken_) {
+ controller.reportOk();
+ }
} catch (e) {
- window.domAutomationController.send('[FAILED] ' + testName + ': ' + e);
+ controller.reportFailure(e);
}
-}
+};
// UI Tests
@@ -90,7 +148,7 @@ TestSuite.prototype.testHostIsPresent = function() {
var doc = domAgent.getDocument();
this.assertTrue(typeof DevToolsHost == 'object' && !DevToolsHost.isStub);
this.assertTrue(!!doc.documentElement);
-}
+};
/**
@@ -101,7 +159,7 @@ TestSuite.prototype.testElementsTreeRoot = function() {
var doc = domAgent.getDocument();
this.assertEquals('HTML', doc.documentElement.nodeName);
this.assertTrue(doc.documentElement.hasChildNodes());
-}
+};
/**
@@ -115,7 +173,35 @@ TestSuite.prototype.testMainResource = function() {
tokens.push(resources[id].lastPathComponent);
}
this.assertEquals('simple_page.html', tokens.join(','));
-}
+};
+
+
+/**
+ * Tests that resources tab is enabled when corresponding item is selected.
+ */
+TestSuite.prototype.testEnableResourcesTab = function(controller) {
+ WebInspector.panels.elements.hide();
+ WebInspector.panels.resources.show();
+
+ var test = this;
+ var oldAddResource = WebInspector.addResource;
+ WebInspector.addResource = function(identifier, payload) {
+ WebInspector.addResource = oldAddResource;
+ oldAddResource.call(this, identifier, payload);
+ test.assertEquals('simple_page.html', payload.lastPathComponent);
+ WebInspector.panels.resources.refresh();
+ WebInspector.resources[identifier]._resourcesTreeElement.select();
+
+ controller.reportOk();
+ };
+
+ // Following call should lead to reload that we capture in the
+ // addResource override.
+ WebInspector.panels.resources._enableResourceTracking();
+
+ // We now have some time to report results to controller.
+ controller.takeControl();
+};
var uiTests = new TestSuite();