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

Side by Side Diff: content/browser/media/webrtc/webrtc_internals_message_handler_unittest.cc

Issue 2163983006: Add unit test for WebRTCInternalsMessageHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add NON_EXPORTED_BASE annotation. Created 4 years, 4 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
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/media/webrtc/webrtc_internals_message_handler.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/run_loop.h"
11 #include "content/browser/child_process_security_policy_impl.h"
12 #include "content/browser/media/webrtc/webrtc_internals.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/url_constants.h"
15 #include "content/public/test/test_web_ui.h"
16 #include "content/test/test_web_contents.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace content {
20
21 namespace {
22
23 static const char kConstraints[] = "c";
24 static const char kRtcConfiguration[] = "r";
25 static const char kUrl[] = "u";
26
27 class WebRTCInternalsMessageHandlerForTest
28 : public WebRTCInternalsMessageHandler {
29 public:
30 WebRTCInternalsMessageHandlerForTest(WebRTCInternals* webrtc_internals,
31 WebUI* web_ui)
32 : WebRTCInternalsMessageHandler(webrtc_internals) {
33 set_web_ui(web_ui);
34 }
35
36 ~WebRTCInternalsMessageHandlerForTest() override {}
37 };
38
39 class WebRTCInternalsForTest : public NON_EXPORTED_BASE(WebRTCInternals) {
40 public:
41 WebRTCInternalsForTest() : WebRTCInternals(0, false) {}
42 ~WebRTCInternalsForTest() override {}
43 };
44
45 } // namespace
46
47 class WebRtcInternalsMessageHandlerTest : public RenderViewHostTestHarness {
48 public:
49 WebRtcInternalsMessageHandlerTest() {}
50
51 protected:
52 void SetUp() override {
53 RenderViewHostTestHarness::SetUp();
54 web_ui_.reset(new TestWebUI());
55 web_ui_->set_web_contents(web_contents());
56 }
57
58 void TearDown() override {
59 web_ui_->set_web_contents(nullptr);
60 web_ui_.reset();
61 RenderViewHostTestHarness::TearDown();
62 }
63
64 std::unique_ptr<TestWebUI> web_ui_;
65 };
66
67 TEST_F(WebRtcInternalsMessageHandlerTest, DontRunJSBeforeNavigationCommitted) {
68 GURL webrtc_url(std::string("chrome://") + kChromeUIWebRTCInternalsHost);
69 GURL example_url("http://www.example.com/");
70
71 WebRTCInternalsForTest webrtc_internals;
72 WebRTCInternalsMessageHandlerForTest observer(&webrtc_internals,
73 web_ui_.get());
74
75 NavigateAndCommit(example_url);
76 webrtc_internals.OnAddPeerConnection(0, 1, 2, kUrl, kRtcConfiguration,
77 kConstraints);
78 base::RunLoop().RunUntilIdle();
79
80 static_cast<TestWebContents*>(web_contents())->StartNavigation(webrtc_url);
81 // We still shouldn't run JS, since navigation to webrtc-internals isn't
82 // finished.
83 webrtc_internals.OnRemovePeerConnection(1, 2);
84 base::RunLoop().RunUntilIdle();
85
86 webrtc_internals.RemoveObserver(&observer);
87 }
88
89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698