| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/media/android/browser_media_session_manager.h" | 5 #include "content/browser/media/session/browser_media_session_manager.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "content/browser/media/android/media_web_contents_observer_android.h" | 14 #include "content/browser/media/media_web_contents_observer.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/common/media_metadata.h" | 17 #include "content/public/common/media_metadata.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
| 19 #include "content/public/test/content_browser_test.h" | 19 #include "content/public/test/content_browser_test.h" |
| 20 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
| 21 #include "content/shell/browser/shell.h" | 21 #include "content/shell/browser/shell.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 | 23 |
| 24 using ::testing::_; | 24 using ::testing::_; |
| 25 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 class BrowserMediaSessionManagerBrowserTest : public ContentBrowserTest { | 108 class BrowserMediaSessionManagerBrowserTest : public ContentBrowserTest { |
| 109 public: | 109 public: |
| 110 BrowserMediaSessionManagerBrowserTest() = default; | 110 BrowserMediaSessionManagerBrowserTest() = default; |
| 111 ~BrowserMediaSessionManagerBrowserTest() override = default; | 111 ~BrowserMediaSessionManagerBrowserTest() override = default; |
| 112 | 112 |
| 113 protected: | 113 protected: |
| 114 void SetUpOnMainThread() override { | 114 void SetUpOnMainThread() override { |
| 115 ContentBrowserTest::SetUpOnMainThread(); | 115 ContentBrowserTest::SetUpOnMainThread(); |
| 116 web_contents_ = shell()->web_contents(); | 116 web_contents_ = static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 117 | 117 |
| 118 std::unique_ptr<MockBrowserMediaSessionManager> manager( | 118 std::unique_ptr<MockBrowserMediaSessionManager> manager( |
| 119 new MockBrowserMediaSessionManager(web_contents_->GetMainFrame())); | 119 new MockBrowserMediaSessionManager(web_contents_->GetMainFrame())); |
| 120 browser_media_session_manager_ = manager.get(); | 120 browser_media_session_manager_ = manager.get(); |
| 121 MediaWebContentsObserverAndroid::FromWebContents(web_contents_) | 121 web_contents_->media_web_contents_observer() |
| 122 ->SetMediaSessionManagerForTest( | 122 ->SetMediaSessionManagerForTest( |
| 123 web_contents_->GetMainFrame(), std::move(manager)); | 123 web_contents_->GetMainFrame(), std::move(manager)); |
| 124 | 124 |
| 125 shell()->LoadURL(GURL("about:blank")); | 125 shell()->LoadURL(GURL("about:blank")); |
| 126 | 126 |
| 127 ON_CALL(*browser_media_session_manager_, OnSetMetadata(_, _)) | 127 ON_CALL(*browser_media_session_manager_, OnSetMetadata(_, _)) |
| 128 .WillByDefault(InvokeWithoutArgs([&]{ | 128 .WillByDefault(InvokeWithoutArgs([&]{ |
| 129 message_loop_runner_->Quit(); | 129 message_loop_runner_->Quit(); |
| 130 })); | 130 })); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void SetUpCommandLine(base::CommandLine* command_line) override { | 133 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 134 command_line->AppendSwitchASCII( | 134 command_line->AppendSwitchASCII( |
| 135 switches::kEnableBlinkFeatures, "MediaSession"); | 135 switches::kEnableBlinkFeatures, "MediaSession"); |
| 136 } | 136 } |
| 137 | 137 |
| 138 WebContents* web_contents_; | 138 WebContentsImpl* web_contents_; |
| 139 MockBrowserMediaSessionManager* browser_media_session_manager_; | 139 MockBrowserMediaSessionManager* browser_media_session_manager_; |
| 140 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 140 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 IN_PROC_BROWSER_TEST_F(BrowserMediaSessionManagerBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(BrowserMediaSessionManagerBrowserTest, |
| 144 TestMetadataPropagated) { | 144 TestMetadataPropagated) { |
| 145 base::Optional<MediaMetadata> expected = MediaMetadata(); | 145 base::Optional<MediaMetadata> expected = MediaMetadata(); |
| 146 expected->title = base::ASCIIToUTF16("title1"); | 146 expected->title = base::ASCIIToUTF16("title1"); |
| 147 expected->artist = base::ASCIIToUTF16("artist1"); | 147 expected->artist = base::ASCIIToUTF16("artist1"); |
| 148 expected->album = base::ASCIIToUTF16("album1"); | 148 expected->album = base::ASCIIToUTF16("album1"); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Set metadata for the first time. | 239 // Set metadata for the first time. |
| 240 message_loop_runner_ = new MessageLoopRunner(); | 240 message_loop_runner_ = new MessageLoopRunner(); |
| 241 EXPECT_CALL(*browser_media_session_manager_, OnSetMetadata(_, expected)) | 241 EXPECT_CALL(*browser_media_session_manager_, OnSetMetadata(_, expected)) |
| 242 .Times(1); | 242 .Times(1); |
| 243 ASSERT_TRUE(ExecuteScript(web_contents_->GetMainFrame(), | 243 ASSERT_TRUE(ExecuteScript(web_contents_->GetMainFrame(), |
| 244 BuildSetMetadataScript(dirty_metadata))); | 244 BuildSetMetadataScript(dirty_metadata))); |
| 245 message_loop_runner_->Run(); | 245 message_loop_runner_->Run(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace content | 248 } // namespace content |
| OLD | NEW |