Commit e65b9d23 authored by gab's avatar gab Committed by Commit bot

Fix MediaDevices* tests dependency on BrowserThread globals after ~BrowserThreadImpl().

Mostly a matter of tweaking destruction order in test and adding an
additional flush instead of depending on ~MediaStreamManager() implicitly
flushing MediaStreamManager::video_capture_thread_().

This is a prereq to https://codereview.chromium.org/2464233002 which
will from now on reset BrowserThread globals associated with destroyed
BrowserThreadImpls and thus makes DCHECK_CURRENTLY_ON fail after that
fact.

BUG=653916

Review-Url: https://codereview.chromium.org/2535043003
Cr-Commit-Position: refs/heads/master@{#435055}
parent 19509c12
......@@ -251,9 +251,14 @@ class MediaDevicesDispatcherHostTest : public testing::Test {
}
}
std::unique_ptr<MediaDevicesDispatcherHost> host_;
// The order of these members is important on teardown:
// MediaDevicesDispatcherHost expects to be destroyed on the IO thread while
// MediaStreamManager expects to be destroyed after the IO thread has been
// uninitialized.
std::unique_ptr<MediaStreamManager> media_stream_manager_;
content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<MediaDevicesDispatcherHost> host_;
std::unique_ptr<media::AudioManager, media::AudioManagerDeleter>
audio_manager_;
content::TestBrowserContext browser_context_;
......@@ -326,6 +331,13 @@ TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevicesUniqueOrigin) {
base::Bind(&MediaDevicesDispatcherHostTest::ValidOriginCallback,
base::Unretained(this)));
base::RunLoop().RunUntilIdle();
#if defined(OS_WIN)
// On Windows, the underlying MediaStreamManager uses a separate thread for
// video capture which must be flushed to guarantee that the callback bound to
// EnumerateDevices above is invoked before the end of this test's body.
media_stream_manager_->FlushVideoCaptureThreadForTesting();
base::RunLoop().RunUntilIdle();
#endif
}
}; // namespace content
......@@ -125,8 +125,8 @@ class MockMediaDeviceChangeSubscriber : public MediaDeviceChangeSubscriber {
class MediaDevicesManagerTest : public ::testing::Test {
public:
MediaDevicesManagerTest()
: video_capture_device_factory_(nullptr),
thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
video_capture_device_factory_(nullptr) {}
~MediaDevicesManagerTest() override {}
MOCK_METHOD1(MockCallback, void(const MediaDeviceEnumeration&));
......@@ -156,10 +156,13 @@ class MediaDevicesManagerTest : public ::testing::Test {
type, MediaDevicesManager::CachePolicy::SYSTEM_MONITOR);
}
// Must outlive MediaDevicesManager as ~MediaDevicesManager() verifies it's
// running on the IO thread.
TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<MediaDevicesManager> media_devices_manager_;
scoped_refptr<VideoCaptureManager> video_capture_manager_;
MockVideoCaptureDeviceFactory* video_capture_device_factory_;
TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<MockAudioManager, media::AudioManagerDeleter> audio_manager_;
private:
......
......@@ -1757,4 +1757,10 @@ void MediaStreamManager::SetGenerateStreamCallbackForTesting(
generate_stream_test_callback_ = test_callback;
}
#if defined(OS_WIN)
void MediaStreamManager::FlushVideoCaptureThreadForTesting() {
video_capture_thread_.FlushForTesting();
}
#endif
} // namespace content
......@@ -249,6 +249,10 @@ class CONTENT_EXPORT MediaStreamManager
void SetGenerateStreamCallbackForTesting(
GenerateStreamTestCallback test_callback);
#if defined(OS_WIN)
void FlushVideoCaptureThreadForTesting();
#endif
private:
// Contains all data needed to keep track of requests.
class DeviceRequest;
......
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