Commit 8babfbe4 authored by jiayl@chromium.org's avatar jiayl@chromium.org

Add getUserMedia info to the dump and add browser tests.

BUG= 304023

Review URL: https://codereview.chromium.org/129833002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244281 0039d316-1c4b-4281-b951-d872f2087c98
parent 9780bac4
...@@ -116,6 +116,26 @@ class PeerConnectionEntry { ...@@ -116,6 +116,26 @@ class PeerConnectionEntry {
std::map<string, StatsMap> stats_; std::map<string, StatsMap> stats_;
}; };
class UserMediaRequestEntry {
public:
UserMediaRequestEntry(int pid,
int rid,
const std::string& origin,
const std::string& audio_constraints,
const std::string& video_constraints)
: pid(pid),
rid(rid),
origin(origin),
audio_constraints(audio_constraints),
video_constraints(video_constraints) {}
int pid;
int rid;
std::string origin;
std::string audio_constraints;
std::string video_constraints;
};
static const int64 FAKE_TIME_STAMP = 3600000; static const int64 FAKE_TIME_STAMP = 3600000;
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -166,6 +186,24 @@ class MAYBE_WebRTCInternalsBrowserTest: public ContentBrowserTest { ...@@ -166,6 +186,24 @@ class MAYBE_WebRTCInternalsBrowserTest: public ContentBrowserTest {
ASSERT_TRUE(ExecuteJavascript("removePeerConnection(" + ss.str() + ");")); ASSERT_TRUE(ExecuteJavascript("removePeerConnection(" + ss.str() + ");"));
} }
// Execute the javascript of addGetUserMedia.
void ExecuteAddGetUserMediaJs(const UserMediaRequestEntry& request) {
std::stringstream ss;
ss << "{pid:" << request.pid << ", rid:" << request.rid << ", origin:'"
<< request.origin << "', audio:'" << request.audio_constraints
<< "', video:'" << request.video_constraints << "'}";
ASSERT_TRUE(ExecuteJavascript("addGetUserMedia(" + ss.str() + ");"));
}
// Execute the javascript of removeGetUserMediaForRenderer.
void ExecuteRemoveGetUserMediaForRendererJs(int rid) {
std::stringstream ss;
ss << "{rid:" << rid << "}";
ASSERT_TRUE(
ExecuteJavascript("removeGetUserMediaForRenderer(" + ss.str() + ");"));
}
// Verifies that the DOM element with id |id| exists. // Verifies that the DOM element with id |id| exists.
void VerifyElementWithId(const string& id) { void VerifyElementWithId(const string& id) {
bool result = false; bool result = false;
...@@ -186,6 +224,42 @@ class MAYBE_WebRTCInternalsBrowserTest: public ContentBrowserTest { ...@@ -186,6 +224,42 @@ class MAYBE_WebRTCInternalsBrowserTest: public ContentBrowserTest {
EXPECT_TRUE(result); EXPECT_TRUE(result);
} }
// Verifies the JS Array of userMediaRequests matches |requests|.
void VerifyUserMediaRequest(
const std::vector<UserMediaRequestEntry>& requests) {
string json_requests;
ASSERT_TRUE(ExecuteScriptAndExtractString(
shell()->web_contents(),
"window.domAutomationController.send("
"JSON.stringify(userMediaRequests));",
&json_requests));
scoped_ptr<base::Value> value_requests;
value_requests.reset(base::JSONReader::Read(json_requests));
EXPECT_EQ(base::Value::TYPE_LIST, value_requests->GetType());
base::ListValue* list_request =
static_cast<base::ListValue*>(value_requests.get());
EXPECT_EQ(requests.size(), list_request->GetSize());
for (size_t i = 0; i < requests.size(); ++i) {
base::DictionaryValue* dict = NULL;
ASSERT_TRUE(list_request->GetDictionary(i, &dict));
int pid, rid;
std::string origin, audio, video;
ASSERT_TRUE(dict->GetInteger("pid", &pid));
ASSERT_TRUE(dict->GetInteger("rid", &rid));
ASSERT_TRUE(dict->GetString("origin", &origin));
ASSERT_TRUE(dict->GetString("audio", &audio));
ASSERT_TRUE(dict->GetString("video", &video));
EXPECT_EQ(requests[i].pid, pid);
EXPECT_EQ(requests[i].rid, rid);
EXPECT_EQ(requests[i].origin, origin);
EXPECT_EQ(requests[i].audio_constraints, audio);
EXPECT_EQ(requests[i].video_constraints, video);
}
}
// Verifies that DOM for |pc| is correctly created with the right content. // Verifies that DOM for |pc| is correctly created with the right content.
void VerifyPeerConnectionEntry(const PeerConnectionEntry& pc) { void VerifyPeerConnectionEntry(const PeerConnectionEntry& pc) {
VerifyElementWithId(pc.getIdString()); VerifyElementWithId(pc.getIdString());
...@@ -715,4 +789,26 @@ IN_PROC_BROWSER_TEST_F(MAYBE_WebRTCInternalsBrowserTest, CreatePageDump) { ...@@ -715,4 +789,26 @@ IN_PROC_BROWSER_TEST_F(MAYBE_WebRTCInternalsBrowserTest, CreatePageDump) {
VerifyStatsDump(dump.get(), pc_0, type, id, stats); VerifyStatsDump(dump.get(), pc_0, type, id, stats);
} }
IN_PROC_BROWSER_TEST_F(MAYBE_WebRTCInternalsBrowserTest, UpdateGetUserMedia) {
GURL url("chrome://webrtc-internals");
NavigateToURL(shell(), url);
UserMediaRequestEntry request1(1, 1, "origin", "ac", "vc");
UserMediaRequestEntry request2(2, 2, "origin2", "ac2", "vc2");
ExecuteAddGetUserMediaJs(request1);
ExecuteAddGetUserMediaJs(request2);
std::vector<UserMediaRequestEntry> list;
list.push_back(request1);
list.push_back(request2);
VerifyUserMediaRequest(list);
ExecuteRemoveGetUserMediaForRendererJs(1);
list.erase(list.begin());
VerifyUserMediaRequest(list);
ExecuteRemoveGetUserMediaForRendererJs(2);
list.erase(list.begin());
VerifyUserMediaRequest(list);
}
} // namespace content } // namespace content
...@@ -58,10 +58,15 @@ var DumpCreator = (function() { ...@@ -58,10 +58,15 @@ var DumpCreator = (function() {
* @private * @private
*/ */
onDownloadData_: function() { onDownloadData_: function() {
var textBlob = var dump_object =
new Blob([JSON.stringify(peerConnectionDataStore, null, ' ')], {
{type: 'octet/stream'}); 'getUserMedia': userMediaRequests,
'PeerConnections': peerConnectionDataStore,
};
var textBlob = new Blob([JSON.stringify(dump_object, null, ' ')],
{type: 'octet/stream'});
var URL = window.URL.createObjectURL(textBlob); var URL = window.URL.createObjectURL(textBlob);
this.root_.getElementsByTagName('a')[0].href = URL; this.root_.getElementsByTagName('a')[0].href = URL;
// The default action of the anchor will download the URL. // The default action of the anchor will download the URL.
}, },
......
...@@ -9,6 +9,8 @@ var statsTable = null; ...@@ -9,6 +9,8 @@ var statsTable = null;
var dumpCreator = null; var dumpCreator = null;
/** A map from peer connection id to the PeerConnectionRecord. */ /** A map from peer connection id to the PeerConnectionRecord. */
var peerConnectionDataStore = {}; var peerConnectionDataStore = {};
/** A list of getUserMedia requests. */
var userMediaRequests = [];
/** A simple class to store the updates and stats data for a peer connection. */ /** A simple class to store the updates and stats data for a peer connection. */
var PeerConnectionRecord = (function() { var PeerConnectionRecord = (function() {
...@@ -248,10 +250,11 @@ function addStats(data) { ...@@ -248,10 +250,11 @@ function addStats(data) {
* Adds a getUserMedia request. * Adds a getUserMedia request.
* *
* @param {!Object} data The object containing rid {number}, pid {number}, * @param {!Object} data The object containing rid {number}, pid {number},
* origin {string}, audio {Object<string>}, video {Object<string>}. * origin {string}, audio {string}, video {string}.
*/ */
function addGetUserMedia(data) { function addGetUserMedia(data) {
// TODO(jiayl): add the getUserMedia info to the tabbed UI. // TODO(jiayl): add the getUserMedia info to the tabbed UI.
userMediaRequests.push(data);
} }
...@@ -262,6 +265,10 @@ function addGetUserMedia(data) { ...@@ -262,6 +265,10 @@ function addGetUserMedia(data) {
*/ */
function removeGetUserMediaForRenderer(data) { function removeGetUserMediaForRenderer(data) {
// TODO(jiayl): remove the getUserMedia info from the tabbed UI. // TODO(jiayl): remove the getUserMedia info from the tabbed UI.
for (var i = userMediaRequests.length - 1; i >= 0; --i) {
if (userMediaRequests[i].rid == data.rid)
userMediaRequests.splice(i, 1);
}
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment