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

Side by Side Diff: content/renderer/media/video_source_handler_unittest.cc

Issue 566793002: MediaStream content_unittests need to trigger a GC before tear down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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 <string> 5 #include <string>
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/child/child_process.h" 9 #include "content/child/child_process.h"
10 #include "content/common/media/video_capture.h" 10 #include "content/common/media/video_capture.h"
11 #include "content/public/renderer/media_stream_video_sink.h" 11 #include "content/public/renderer/media_stream_video_sink.h"
12 #include "content/renderer/media/media_stream.h" 12 #include "content/renderer/media/media_stream.h"
13 #include "content/renderer/media/media_stream_registry_interface.h" 13 #include "content/renderer/media/media_stream_registry_interface.h"
14 #include "content/renderer/media/mock_media_stream_registry.h" 14 #include "content/renderer/media/mock_media_stream_registry.h"
15 #include "content/renderer/media/video_source_handler.h" 15 #include "content/renderer/media/video_source_handler.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
19 #include "third_party/WebKit/public/platform/WebString.h" 19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/web/WebHeap.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 static const std::string kTestStreamUrl = "stream_url"; 24 static const std::string kTestStreamUrl = "stream_url";
24 static const std::string kTestVideoTrackId = "video_track_id"; 25 static const std::string kTestVideoTrackId = "video_track_id";
25 static const std::string kUnknownStreamUrl = "unknown_stream_url"; 26 static const std::string kUnknownStreamUrl = "unknown_stream_url";
26 27
27 class FakeFrameReader : public FrameReaderInterface { 28 class FakeFrameReader : public FrameReaderInterface {
28 public: 29 public:
29 virtual bool GotFrame( 30 virtual bool GotFrame(
30 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE { 31 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE {
31 last_frame_ = frame; 32 last_frame_ = frame;
32 return true; 33 return true;
33 } 34 }
34 35
35 const media::VideoFrame* last_frame() { 36 const media::VideoFrame* last_frame() {
36 return last_frame_.get(); 37 return last_frame_.get();
37 } 38 }
38 39
39 private: 40 private:
40 scoped_refptr<media::VideoFrame> last_frame_; 41 scoped_refptr<media::VideoFrame> last_frame_;
41 }; 42 };
42 43
43 class VideoSourceHandlerTest : public ::testing::Test { 44 class VideoSourceHandlerTest : public ::testing::Test {
44 public: 45 public:
45 VideoSourceHandlerTest() 46 VideoSourceHandlerTest()
46 : child_process_(new ChildProcess()), 47 : child_process_(new ChildProcess()),
47 registry_() { 48 registry_(new MockMediaStreamRegistry()) {
48 handler_.reset(new VideoSourceHandler(&registry_)); 49 handler_.reset(new VideoSourceHandler(registry_.get()));
49 registry_.Init(kTestStreamUrl); 50 registry_->Init(kTestStreamUrl);
50 registry_.AddVideoTrack(kTestVideoTrackId); 51 registry_->AddVideoTrack(kTestVideoTrackId);
52 }
53
54 virtual void TearDown() {
55 registry_.reset();
56 blink::WebHeap::collectAllGarbageForTesting();
51 } 57 }
52 58
53 protected: 59 protected:
54 base::MessageLoop message_loop_; 60 base::MessageLoop message_loop_;
55 scoped_ptr<ChildProcess> child_process_; 61 scoped_ptr<ChildProcess> child_process_;
56 scoped_ptr<VideoSourceHandler> handler_; 62 scoped_ptr<VideoSourceHandler> handler_;
57 MockMediaStreamRegistry registry_; 63 scoped_ptr<MockMediaStreamRegistry> registry_;
58 }; 64 };
59 65
60 TEST_F(VideoSourceHandlerTest, OpenClose) { 66 TEST_F(VideoSourceHandlerTest, OpenClose) {
61 FakeFrameReader reader; 67 FakeFrameReader reader;
62 // Unknow url will return false. 68 // Unknow url will return false.
63 EXPECT_FALSE(handler_->Open(kUnknownStreamUrl, &reader)); 69 EXPECT_FALSE(handler_->Open(kUnknownStreamUrl, &reader));
64 EXPECT_TRUE(handler_->Open(kTestStreamUrl, &reader)); 70 EXPECT_TRUE(handler_->Open(kTestStreamUrl, &reader));
65 71
66 int width = 640; 72 int width = 640;
67 int height = 360; 73 int height = 360;
(...skipping 19 matching lines...) Expand all
87 EXPECT_FALSE(handler_->Close(NULL)); 93 EXPECT_FALSE(handler_->Close(NULL));
88 EXPECT_TRUE(handler_->Close(&reader)); 94 EXPECT_TRUE(handler_->Close(&reader));
89 } 95 }
90 96
91 TEST_F(VideoSourceHandlerTest, OpenWithoutClose) { 97 TEST_F(VideoSourceHandlerTest, OpenWithoutClose) {
92 FakeFrameReader reader; 98 FakeFrameReader reader;
93 EXPECT_TRUE(handler_->Open(kTestStreamUrl, &reader)); 99 EXPECT_TRUE(handler_->Open(kTestStreamUrl, &reader));
94 } 100 }
95 101
96 } // namespace content 102 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698