Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: content/browser/media/webrtc_internals_browsertest.cc

Issue 129833002: Add getUserMedia info to the dump and add browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/resources/media/dump_creator.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/json/json_reader.h" 6 #include "base/json/json_reader.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 int pid_; 109 int pid_;
110 int lid_; 110 int lid_;
111 std::vector<EventEntry> events_; 111 std::vector<EventEntry> events_;
112 // This is a record of the history of stats value reported for each stats 112 // This is a record of the history of stats value reported for each stats
113 // report id (e.g. ssrc-1234) for each stats name (e.g. framerate). 113 // report id (e.g. ssrc-1234) for each stats name (e.g. framerate).
114 // It a 2-D map with each map entry is a vector of reported values. 114 // It a 2-D map with each map entry is a vector of reported values.
115 // It is used to verify the graph data series. 115 // It is used to verify the graph data series.
116 std::map<string, StatsMap> stats_; 116 std::map<string, StatsMap> stats_;
117 }; 117 };
118 118
119 class UserMediaRequestEntry {
120 public:
121 UserMediaRequestEntry(int pid,
122 int rid,
123 const std::string& origin,
124 const std::string& audio_constraints,
125 const std::string& video_constraints)
126 : pid(pid),
127 rid(rid),
128 origin(origin),
129 audio_constraints(audio_constraints),
130 video_constraints(video_constraints) {}
131
132 int pid;
133 int rid;
134 std::string origin;
135 std::string audio_constraints;
136 std::string video_constraints;
137 };
138
119 static const int64 FAKE_TIME_STAMP = 3600000; 139 static const int64 FAKE_TIME_STAMP = 3600000;
120 140
121 #if defined(OS_WIN) 141 #if defined(OS_WIN)
122 // All tests are flaky on Windows: crbug.com/277322. 142 // All tests are flaky on Windows: crbug.com/277322.
123 #define MAYBE_WebRTCInternalsBrowserTest DISABLED_WebRTCInternalsBrowserTest 143 #define MAYBE_WebRTCInternalsBrowserTest DISABLED_WebRTCInternalsBrowserTest
124 #else 144 #else
125 #define MAYBE_WebRTCInternalsBrowserTest WebRTCInternalsBrowserTest 145 #define MAYBE_WebRTCInternalsBrowserTest WebRTCInternalsBrowserTest
126 #endif 146 #endif
127 147
128 class MAYBE_WebRTCInternalsBrowserTest: public ContentBrowserTest { 148 class MAYBE_WebRTCInternalsBrowserTest: public ContentBrowserTest {
(...skipping 30 matching lines...) Expand all
159 } 179 }
160 180
161 // Execute the javascript of removePeerConnection. 181 // Execute the javascript of removePeerConnection.
162 void ExecuteRemovePeerConnectionJs(const PeerConnectionEntry& pc) { 182 void ExecuteRemovePeerConnectionJs(const PeerConnectionEntry& pc) {
163 std::stringstream ss; 183 std::stringstream ss;
164 ss << "{pid:" << pc.pid_ <<", lid:" << pc.lid_ << "}"; 184 ss << "{pid:" << pc.pid_ <<", lid:" << pc.lid_ << "}";
165 185
166 ASSERT_TRUE(ExecuteJavascript("removePeerConnection(" + ss.str() + ");")); 186 ASSERT_TRUE(ExecuteJavascript("removePeerConnection(" + ss.str() + ");"));
167 } 187 }
168 188
189 // Execute the javascript of addGetUserMedia.
190 void ExecuteAddGetUserMediaJs(const UserMediaRequestEntry& request) {
191 std::stringstream ss;
192 ss << "{pid:" << request.pid << ", rid:" << request.rid << ", origin:'"
193 << request.origin << "', audio:'" << request.audio_constraints
194 << "', video:'" << request.video_constraints << "'}";
195
196 ASSERT_TRUE(ExecuteJavascript("addGetUserMedia(" + ss.str() + ");"));
197 }
198
199 // Execute the javascript of removeGetUserMediaForRenderer.
200 void ExecuteRemoveGetUserMediaForRendererJs(int rid) {
201 std::stringstream ss;
202 ss << "{rid:" << rid << "}";
203 ASSERT_TRUE(
204 ExecuteJavascript("removeGetUserMediaForRenderer(" + ss.str() + ");"));
205 }
206
169 // Verifies that the DOM element with id |id| exists. 207 // Verifies that the DOM element with id |id| exists.
170 void VerifyElementWithId(const string& id) { 208 void VerifyElementWithId(const string& id) {
171 bool result = false; 209 bool result = false;
172 ASSERT_TRUE(ExecuteScriptAndExtractBool( 210 ASSERT_TRUE(ExecuteScriptAndExtractBool(
173 shell()->web_contents(), 211 shell()->web_contents(),
174 "window.domAutomationController.send($('" + id + "') != null);", 212 "window.domAutomationController.send($('" + id + "') != null);",
175 &result)); 213 &result));
176 EXPECT_TRUE(result); 214 EXPECT_TRUE(result);
177 } 215 }
178 216
179 // Verifies that the DOM element with id |id| does not exist. 217 // Verifies that the DOM element with id |id| does not exist.
180 void VerifyNoElementWithId(const string& id) { 218 void VerifyNoElementWithId(const string& id) {
181 bool result = false; 219 bool result = false;
182 ASSERT_TRUE(ExecuteScriptAndExtractBool( 220 ASSERT_TRUE(ExecuteScriptAndExtractBool(
183 shell()->web_contents(), 221 shell()->web_contents(),
184 "window.domAutomationController.send($('" + id + "') == null);", 222 "window.domAutomationController.send($('" + id + "') == null);",
185 &result)); 223 &result));
186 EXPECT_TRUE(result); 224 EXPECT_TRUE(result);
187 } 225 }
188 226
227 // Verifies the JS Array of userMediaRequests matches |requests|.
228 void VerifyUserMediaRequest(
229 const std::vector<UserMediaRequestEntry>& requests) {
230 string json_requests;
231 ASSERT_TRUE(ExecuteScriptAndExtractString(
232 shell()->web_contents(),
233 "window.domAutomationController.send("
234 "JSON.stringify(userMediaRequests));",
235 &json_requests));
236 scoped_ptr<base::Value> value_requests;
237 value_requests.reset(base::JSONReader::Read(json_requests));
238
239 EXPECT_EQ(base::Value::TYPE_LIST, value_requests->GetType());
240
241 base::ListValue* list_request =
242 static_cast<base::ListValue*>(value_requests.get());
243 EXPECT_EQ(requests.size(), list_request->GetSize());
244
245 for (size_t i = 0; i < requests.size(); ++i) {
246 base::DictionaryValue* dict = NULL;
247 ASSERT_TRUE(list_request->GetDictionary(i, &dict));
248 int pid, rid;
249 std::string origin, audio, video;
250 ASSERT_TRUE(dict->GetInteger("pid", &pid));
251 ASSERT_TRUE(dict->GetInteger("rid", &rid));
252 ASSERT_TRUE(dict->GetString("origin", &origin));
253 ASSERT_TRUE(dict->GetString("audio", &audio));
254 ASSERT_TRUE(dict->GetString("video", &video));
255 EXPECT_EQ(requests[i].pid, pid);
256 EXPECT_EQ(requests[i].rid, rid);
257 EXPECT_EQ(requests[i].origin, origin);
258 EXPECT_EQ(requests[i].audio_constraints, audio);
259 EXPECT_EQ(requests[i].video_constraints, video);
260 }
261 }
262
189 // Verifies that DOM for |pc| is correctly created with the right content. 263 // Verifies that DOM for |pc| is correctly created with the right content.
190 void VerifyPeerConnectionEntry(const PeerConnectionEntry& pc) { 264 void VerifyPeerConnectionEntry(const PeerConnectionEntry& pc) {
191 VerifyElementWithId(pc.getIdString()); 265 VerifyElementWithId(pc.getIdString());
192 if (pc.events_.size() == 0) 266 if (pc.events_.size() == 0)
193 return; 267 return;
194 268
195 string log_id = pc.getLogIdString(); 269 string log_id = pc.getLogIdString();
196 VerifyElementWithId(log_id); 270 VerifyElementWithId(log_id);
197 string result; 271 string result;
198 for (size_t i = 0; i < pc.events_.size(); ++i) { 272 for (size_t i = 0; i < pc.events_.size(); ++i) {
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 782
709 ASSERT_TRUE(ExecuteScriptAndExtractString( 783 ASSERT_TRUE(ExecuteScriptAndExtractString(
710 shell()->web_contents(), 784 shell()->web_contents(),
711 "window.domAutomationController.send(" 785 "window.domAutomationController.send("
712 "JSON.stringify(peerConnectionDataStore));", 786 "JSON.stringify(peerConnectionDataStore));",
713 &dump_json)); 787 &dump_json));
714 dump.reset(base::JSONReader::Read(dump_json)); 788 dump.reset(base::JSONReader::Read(dump_json));
715 VerifyStatsDump(dump.get(), pc_0, type, id, stats); 789 VerifyStatsDump(dump.get(), pc_0, type, id, stats);
716 } 790 }
717 791
792 IN_PROC_BROWSER_TEST_F(MAYBE_WebRTCInternalsBrowserTest, UpdateGetUserMedia) {
793 GURL url("chrome://webrtc-internals");
794 NavigateToURL(shell(), url);
795
796 UserMediaRequestEntry request1(1, 1, "origin", "ac", "vc");
797 UserMediaRequestEntry request2(2, 2, "origin2", "ac2", "vc2");
798 ExecuteAddGetUserMediaJs(request1);
799 ExecuteAddGetUserMediaJs(request2);
800
801 std::vector<UserMediaRequestEntry> list;
802 list.push_back(request1);
803 list.push_back(request2);
804 VerifyUserMediaRequest(list);
805
806 ExecuteRemoveGetUserMediaForRendererJs(1);
807 list.erase(list.begin());
808 VerifyUserMediaRequest(list);
809
810 ExecuteRemoveGetUserMediaForRendererJs(2);
811 list.erase(list.begin());
812 VerifyUserMediaRequest(list);
813 }
718 } // namespace content 814 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/resources/media/dump_creator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698