Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 const GURL webrtc_url_{std::string("chrome://") + | |
|
tommi (sloooow) - chröme
2016/07/25 11:05:39
I was actually expecting you to use () here since
Max Morin
2016/07/25 12:02:57
Using () makes these function declarations, hence
| |
| 52 kChromeUIWebRTCInternalsHost}; | |
| 53 const GURL example_url_{"http://www.example.com/"}; | |
| 54 | |
| 55 protected: | |
| 56 void SetUp() override { | |
| 57 RenderViewHostTestHarness::SetUp(); | |
| 58 web_ui_.reset(new TestWebUI()); | |
| 59 web_ui_->set_web_contents(web_contents()); | |
| 60 } | |
| 61 | |
| 62 void TearDown() override { | |
| 63 web_ui_->set_web_contents(nullptr); | |
| 64 web_ui_.reset(); | |
| 65 RenderViewHostTestHarness::TearDown(); | |
| 66 } | |
| 67 | |
| 68 std::unique_ptr<TestWebUI> web_ui_; | |
| 69 }; | |
| 70 | |
| 71 TEST_F(WebRtcInternalsMessageHandlerTest, DontRunJSBeforeNavigationCommitted) { | |
| 72 WebRTCInternalsForTest webrtc_internals; | |
| 73 WebRTCInternalsMessageHandlerForTest observer(&webrtc_internals, | |
| 74 web_ui_.get()); | |
| 75 | |
| 76 NavigateAndCommit(example_url_); | |
| 77 webrtc_internals.OnAddPeerConnection(0, 1, 2, kUrl, kRtcConfiguration, | |
| 78 kConstraints); | |
| 79 base::RunLoop().RunUntilIdle(); | |
| 80 | |
| 81 static_cast<TestWebContents*>(web_contents())->StartNavigation(webrtc_url_); | |
| 82 // We still shouldn't run JS, since navigation to webrtc-internals isn't | |
| 83 // finished. | |
| 84 webrtc_internals.OnRemovePeerConnection(1, 2); | |
| 85 base::RunLoop().RunUntilIdle(); | |
| 86 | |
| 87 webrtc_internals.RemoveObserver(&observer); | |
| 88 } | |
| 89 | |
| 90 } // namespace content | |
| OLD | NEW |