| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path_watcher.h" |
| 9 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 12 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 13 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 14 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" | 17 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr
ivate_api.h" |
| 15 #include "chrome/browser/extensions/extension_function_test_utils.h" | 18 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/media/webrtc_browsertest_base.h" | 20 #include "chrome/browser/media/webrtc_browsertest_base.h" |
| 18 #include "chrome/browser/media/webrtc_browsertest_common.h" | 21 #include "chrome/browser/media/webrtc_browsertest_common.h" |
| 19 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 #endif | 34 #endif |
| 32 | 35 |
| 33 using extensions::WebrtcLoggingPrivateStartWebRtcEventLoggingFunction; | 36 using extensions::WebrtcLoggingPrivateStartWebRtcEventLoggingFunction; |
| 34 using extensions::WebrtcLoggingPrivateStopWebRtcEventLoggingFunction; | 37 using extensions::WebrtcLoggingPrivateStopWebRtcEventLoggingFunction; |
| 35 | 38 |
| 36 namespace utils = extension_function_test_utils; | 39 namespace utils = extension_function_test_utils; |
| 37 | 40 |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 // Get the expected EventLog file name. The name will be | 43 // Get the expected EventLog file name. The name will be |
| 41 // <temporary path>.<render process id>.event_log.<consumer id>, for example | 44 // <temporary path>.<render process id>.<peer connection id>, for example |
| 42 // /tmp/.org.chromium.Chromium.vsygNQ/dnFW8ch/Default/WebRTC | 45 // /tmp/.org.chromium.Chromium.vsygNQ/dnFW8ch/Default/WebRTC |
| 43 // Logs/WebRtcEventLog.1.29113.event_log.1 | 46 // Logs/WebRtcEventLog.1.6.1 |
| 44 base::FilePath GetExpectedEventLogFileName(const base::FilePath& base_file, | 47 base::FilePath GetExpectedEventLogFileName(const base::FilePath& base_file, |
| 45 int render_process_id) { | 48 int render_process_id) { |
| 46 static const int kExpectedConsumerId = 1; | 49 static const int kExpectedPeerConnectionId = 1; |
| 47 return base_file.AddExtension(IntToStringType(render_process_id)) | 50 return base_file.AddExtension(IntToStringType(render_process_id)) |
| 48 .AddExtension(FILE_PATH_LITERAL("event_log")) | 51 .AddExtension(IntToStringType(kExpectedPeerConnectionId)); |
| 49 .AddExtension(IntToStringType(kExpectedConsumerId)); | |
| 50 } | 52 } |
| 51 | 53 |
| 52 static const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; | 54 static const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; |
| 53 | 55 |
| 54 std::string ParamsToString(const base::ListValue& parameters) { | 56 std::string ParamsToString(const base::ListValue& parameters) { |
| 55 std::string parameter_string; | 57 std::string parameter_string; |
| 56 EXPECT_TRUE(base::JSONWriter::Write(parameters, ¶meter_string)); | 58 EXPECT_TRUE(base::JSONWriter::Write(parameters, ¶meter_string)); |
| 57 return parameter_string; | 59 return parameter_string; |
| 58 } | 60 } |
| 59 | 61 |
| 62 class FileWaiter : public base::RefCountedThreadSafe<FileWaiter> { |
| 63 public: |
| 64 explicit FileWaiter(const base::FilePath& path) |
| 65 : found_(false), path_(path) {} |
| 66 |
| 67 bool Start() { |
| 68 if (base::PathExists(path_)) { |
| 69 found_ = true; |
| 70 return true; |
| 71 } else { |
| 72 return watcher_.Watch(path_, false /* recursive */, |
| 73 base::Bind(&FileWaiter::Callback, this)); |
| 74 } |
| 75 } |
| 76 |
| 77 // Returns true if |path_| became available. |
| 78 bool WaitForFile() { |
| 79 if (!found_) { |
| 80 run_loop_.Run(); |
| 81 } |
| 82 return found_; |
| 83 } |
| 84 |
| 85 // implements FilePathWatcher::Callback |
| 86 void Callback(const base::FilePath& path, bool error) { |
| 87 EXPECT_EQ(path, path_); |
| 88 if (!error) |
| 89 found_ = true; |
| 90 run_loop_.Quit(); |
| 91 } |
| 92 |
| 93 private: |
| 94 friend class base::RefCountedThreadSafe<FileWaiter>; |
| 95 ~FileWaiter() {} |
| 96 base::RunLoop run_loop_; |
| 97 bool found_; |
| 98 base::FilePath path_; |
| 99 base::FilePathWatcher watcher_; |
| 100 DISALLOW_COPY_AND_ASSIGN(FileWaiter); |
| 101 }; |
| 102 |
| 60 class WebrtcEventLogApiTest : public WebRtcTestBase { | 103 class WebrtcEventLogApiTest : public WebRtcTestBase { |
| 61 protected: | 104 protected: |
| 62 void SetUp() override { | 105 void SetUp() override { |
| 63 WebRtcTestBase::SetUp(); | 106 WebRtcTestBase::SetUp(); |
| 64 extension_ = extensions::test_util::CreateEmptyExtension(); | 107 extension_ = extensions::test_util::CreateEmptyExtension(); |
| 65 } | 108 } |
| 66 | 109 |
| 67 void SetUpInProcessBrowserTestFixture() override { | 110 void SetUpInProcessBrowserTestFixture() override { |
| 68 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. | 111 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. |
| 69 } | 112 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 100 parameters->Append(std::move(request_info)); | 143 parameters->Append(std::move(request_info)); |
| 101 parameters->AppendString(tab->GetURL().GetOrigin().spec()); | 144 parameters->AppendString(tab->GetURL().GetOrigin().spec()); |
| 102 } | 145 } |
| 103 | 146 |
| 104 private: | 147 private: |
| 105 scoped_refptr<extensions::Extension> extension_; | 148 scoped_refptr<extensions::Extension> extension_; |
| 106 }; | 149 }; |
| 107 | 150 |
| 108 } // namespace | 151 } // namespace |
| 109 | 152 |
| 110 // TODO(ivoc): Reenable when the event log functionality in Chrome is updated. | 153 IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest, TestStartStopWebRtcEventLogging) { |
| 111 IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest, | |
| 112 DISABLED_TestStartStopWebRtcEventLogging) { | |
| 113 ASSERT_TRUE(embedded_test_server()->Start()); | 154 ASSERT_TRUE(embedded_test_server()->Start()); |
| 114 | 155 |
| 115 content::WebContents* left_tab = | 156 content::WebContents* left_tab = |
| 116 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | 157 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 117 content::WebContents* right_tab = | 158 content::WebContents* right_tab = |
| 118 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | 159 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 119 | 160 |
| 120 SetupPeerconnectionWithLocalStream(left_tab); | 161 SetupPeerconnectionWithLocalStream(left_tab); |
| 121 SetupPeerconnectionWithLocalStream(right_tab); | 162 SetupPeerconnectionWithLocalStream(right_tab); |
| 122 | 163 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ASSERT_TRUE(recordings_info_stop.get()); | 212 ASSERT_TRUE(recordings_info_stop.get()); |
| 172 base::FilePath file_name_stop( | 213 base::FilePath file_name_stop( |
| 173 base::FilePath::FromUTF8Unsafe(recordings_info_stop->prefix_path)); | 214 base::FilePath::FromUTF8Unsafe(recordings_info_stop->prefix_path)); |
| 174 | 215 |
| 175 HangUp(left_tab); | 216 HangUp(left_tab); |
| 176 HangUp(right_tab); | 217 HangUp(right_tab); |
| 177 | 218 |
| 178 EXPECT_EQ(file_name_start, file_name_stop); | 219 EXPECT_EQ(file_name_start, file_name_stop); |
| 179 | 220 |
| 180 // Check that the file exists and is non-empty. | 221 // Check that the file exists and is non-empty. |
| 181 base::ProcessId render_process_id = | 222 content::RenderProcessHost* render_process_host = |
| 182 base::GetProcId(left_tab->GetRenderProcessHost()->GetHandle()); | 223 left_tab->GetRenderProcessHost(); |
| 183 EXPECT_NE(render_process_id, base::kNullProcessId); | 224 ASSERT_NE(render_process_host, nullptr); |
| 225 int render_process_id = render_process_host->GetID(); |
| 184 base::FilePath full_file_name = | 226 base::FilePath full_file_name = |
| 185 GetExpectedEventLogFileName(file_name_stop, render_process_id); | 227 GetExpectedEventLogFileName(file_name_stop, render_process_id); |
| 186 int64_t file_size = 0; | 228 int64_t file_size = 0; |
| 187 while (!(base::PathExists(full_file_name) && | 229 scoped_refptr<FileWaiter> waiter = new FileWaiter(full_file_name); |
| 188 base::GetFileSize(full_file_name, &file_size) && file_size > 0)) { | 230 |
| 189 // This should normally not happen, but is here to prevent the test | 231 ASSERT_TRUE(waiter->Start()) << "ERROR watching for " |
| 190 // from becoming flaky on devices with weird timings or when the | 232 << full_file_name.value(); |
| 191 // /webrtc/webrtc_jsep01_test.html changes. | 233 ASSERT_TRUE(waiter->WaitForFile()); |
| 192 VLOG(1) << "Waiting for logfile to become available..."; | |
| 193 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | |
| 194 } | |
| 195 ASSERT_TRUE(base::PathExists(full_file_name)); | 234 ASSERT_TRUE(base::PathExists(full_file_name)); |
| 196 EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size)); | 235 EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size)); |
| 197 EXPECT_GT(file_size, 0); | 236 EXPECT_GT(file_size, 0); |
| 198 | 237 |
| 199 // Clean up. | 238 // Clean up. |
| 200 base::DeleteFile(full_file_name, false); | 239 base::DeleteFile(full_file_name, false); |
| 201 } | 240 } |
| 202 | 241 |
| 203 // TODO(ivoc): Reenable when the event log functionality in Chrome is updated. | |
| 204 IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest, | 242 IN_PROC_BROWSER_TEST_F(WebrtcEventLogApiTest, |
| 205 DISABLED_TestStartTimedWebRtcEventLogging) { | 243 TestStartTimedWebRtcEventLogging) { |
| 206 ASSERT_TRUE(embedded_test_server()->Start()); | 244 ASSERT_TRUE(embedded_test_server()->Start()); |
| 207 | 245 |
| 208 content::WebContents* left_tab = | 246 content::WebContents* left_tab = |
| 209 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | 247 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 210 content::WebContents* right_tab = | 248 content::WebContents* right_tab = |
| 211 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | 249 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 212 | 250 |
| 213 SetupPeerconnectionWithLocalStream(left_tab); | 251 SetupPeerconnectionWithLocalStream(left_tab); |
| 214 SetupPeerconnectionWithLocalStream(right_tab); | 252 SetupPeerconnectionWithLocalStream(right_tab); |
| 215 | 253 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 245 // Video is choppy on Mac OS X. http://crbug.com/443542. | 283 // Video is choppy on Mac OS X. http://crbug.com/443542. |
| 246 WaitForVideoToPlay(left_tab); | 284 WaitForVideoToPlay(left_tab); |
| 247 WaitForVideoToPlay(right_tab); | 285 WaitForVideoToPlay(right_tab); |
| 248 #endif | 286 #endif |
| 249 | 287 |
| 250 HangUp(left_tab); | 288 HangUp(left_tab); |
| 251 HangUp(right_tab); | 289 HangUp(right_tab); |
| 252 | 290 |
| 253 // The log has stopped automatically. Check that the file exists and is | 291 // The log has stopped automatically. Check that the file exists and is |
| 254 // non-empty. | 292 // non-empty. |
| 255 base::ProcessId render_process_id = | 293 content::RenderProcessHost* render_process_host = |
| 256 base::GetProcId(left_tab->GetRenderProcessHost()->GetHandle()); | 294 left_tab->GetRenderProcessHost(); |
| 257 EXPECT_NE(render_process_id, base::kNullProcessId); | 295 ASSERT_NE(render_process_host, nullptr); |
| 296 int render_process_id = render_process_host->GetID(); |
| 258 base::FilePath full_file_name = | 297 base::FilePath full_file_name = |
| 259 GetExpectedEventLogFileName(file_name_start, render_process_id); | 298 GetExpectedEventLogFileName(file_name_start, render_process_id); |
| 260 int64_t file_size = 0; | 299 int64_t file_size = 0; |
| 261 while (!(base::PathExists(full_file_name) && | 300 |
| 262 base::GetFileSize(full_file_name, &file_size) && file_size > 0)) { | 301 scoped_refptr<FileWaiter> waiter = new FileWaiter(full_file_name); |
| 263 // This should normally not happen, but is here to prevent the test | 302 |
| 264 // from becoming flaky on devices with weird timings or when the | 303 ASSERT_TRUE(waiter->Start()) << "ERROR watching for " |
| 265 // /webrtc/webrtc_jsep01_test.html changes. | 304 << full_file_name.value(); |
| 266 VLOG(1) << "Waiting for logfile to become available..."; | 305 ASSERT_TRUE(waiter->WaitForFile()); |
| 267 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | |
| 268 } | |
| 269 ASSERT_TRUE(base::PathExists(full_file_name)); | 306 ASSERT_TRUE(base::PathExists(full_file_name)); |
| 270 EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size)); | 307 EXPECT_TRUE(base::GetFileSize(full_file_name, &file_size)); |
| 271 EXPECT_GT(file_size, 0); | 308 EXPECT_GT(file_size, 0); |
| 272 | 309 |
| 273 // Clean up. | 310 // Clean up. |
| 274 base::DeleteFile(full_file_name, false); | 311 base::DeleteFile(full_file_name, false); |
| 275 } | 312 } |
| OLD | NEW |