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 class WebRTCInternalsForTest : public NON_EXPORTED_BASE(WebRTCInternals) { | |
|
tommi (sloooow) - chröme
2016/07/25 10:16:06
nit: empty line above this one
Max Morin
2016/07/25 10:41:18
Done.
| |
| 39 public: | |
| 40 WebRTCInternalsForTest() : WebRTCInternals(0, false) {} | |
| 41 ~WebRTCInternalsForTest() override {} | |
| 42 }; | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 class WebRtcInternalsMessageHandlerTest : public RenderViewHostTestHarness { | |
| 47 public: | |
| 48 const GURL kWebRTCURL = | |
|
tommi (sloooow) - chröme
2016/07/25 10:16:06
either make this static or rename to webrtc_url_
Max Morin
2016/07/25 10:41:18
Done.
| |
| 49 GURL(std::string("chrome://") + kChromeUIWebRTCInternalsHost); | |
| 50 const GURL kExampleURL = GURL("http://www.example.com/"); | |
|
tommi (sloooow) - chröme
2016/07/25 10:16:06
same here.
Also, for initializing these variables
Max Morin
2016/07/25 10:41:18
Done.
| |
| 51 WebRtcInternalsMessageHandlerTest() {} | |
| 52 | |
| 53 protected: | |
| 54 void SetUp() override { | |
| 55 RenderViewHostTestHarness::SetUp(); | |
| 56 web_UI.reset(new TestWebUI()); | |
| 57 web_UI->set_web_contents(web_contents()); | |
| 58 } | |
| 59 | |
| 60 void TearDown() override { | |
| 61 web_UI->set_web_contents(nullptr); | |
| 62 web_UI.reset(); | |
| 63 RenderViewHostTestHarness::TearDown(); | |
| 64 } | |
| 65 | |
| 66 std::unique_ptr<TestWebUI> web_UI; | |
|
tommi (sloooow) - chröme
2016/07/25 10:16:06
web_ui_
Max Morin
2016/07/25 10:41:18
Done.
| |
| 67 }; | |
| 68 | |
| 69 TEST_F(WebRtcInternalsMessageHandlerTest, DontRunJSBeforeNavigationCommitted) { | |
| 70 WebRTCInternalsForTest webrtc_internals; | |
| 71 WebRTCInternalsMessageHandlerForTest observer(&webrtc_internals, | |
| 72 web_UI.get()); | |
| 73 | |
| 74 NavigateAndCommit(kExampleURL); | |
| 75 webrtc_internals.OnAddPeerConnection(0, 1, 2, kUrl, kRtcConfiguration, | |
| 76 kConstraints); | |
| 77 base::RunLoop().RunUntilIdle(); | |
| 78 | |
| 79 static_cast<TestWebContents*>(web_contents())->StartNavigation(kWebRTCURL); | |
| 80 // We still shouldn't run JS, since navigation to webrtc-internals isn't | |
| 81 // finished. | |
| 82 webrtc_internals.OnRemovePeerConnection(1, 2); | |
| 83 base::RunLoop().RunUntilIdle(); | |
| 84 | |
| 85 webrtc_internals.RemoveObserver(&observer); | |
| 86 } | |
| 87 | |
| 88 } // namespace content | |
| OLD | NEW |