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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_browsertest.cc

Issue 1970313002: Audio notification plumbed from guest WebContents up to embedder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test. Created 4 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 <queue> 5 #include <queue>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 799
800 bool muting_update_observed() { return muting_update_observed_; } 800 bool muting_update_observed() { return muting_update_observed_; }
801 801
802 private: 802 private:
803 scoped_refptr<content::MessageLoopRunner> loop_runner_; 803 scoped_refptr<content::MessageLoopRunner> loop_runner_;
804 bool muting_update_observed_; 804 bool muting_update_observed_;
805 805
806 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioMutedObserver); 806 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioMutedObserver);
807 }; 807 };
808 808
809 class MockWasAudibleWebContentsDelegate : public content::WebContentsDelegate {
Avi (use Gerrit) 2016/05/13 21:54:26 This isn't a "mock", this is a legitimate delegate
wjmaclean 2016/05/13 22:17:23 Done.
810 public:
811 MockWasAudibleWebContentsDelegate() : invalidate_type_tab_seen_(false) {}
812
813 void NavigationStateChanged(content::WebContents* contents,
814 content::InvalidateTypes changed_flags) override {
815 if (changed_flags == content::INVALIDATE_TYPE_TAB) {
816 invalidate_type_tab_seen_ = true;
817 if (message_loop_runner_.get())
818 message_loop_runner_->Quit();
819 }
820 }
821
822 void WaitForInvalidateTypeTab() {
823 if (!invalidate_type_tab_seen_) {
824 message_loop_runner_ = new content::MessageLoopRunner;
825 message_loop_runner_->Run();
826 }
827 invalidate_type_tab_seen_ = false;
828 }
829
830 private:
831 bool invalidate_type_tab_seen_;
832 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
833
834 DISALLOW_COPY_AND_ASSIGN(MockWasAudibleWebContentsDelegate);
835 };
836
837 IN_PROC_BROWSER_TEST_P(WebViewTest, AudibilityStatePropagates) {
838 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest audio.
839
840 LoadAppWithGuest("web_view/simple");
841
842 content::WebContents* embedder = GetEmbedderWebContents();
843 content::WebContents* guest = GetGuestWebContents();
844
845 EXPECT_FALSE(embedder->WasRecentlyAudible());
846 EXPECT_FALSE(guest->WasRecentlyAudible());
847
848 std::unique_ptr<MockWasAudibleWebContentsDelegate> mock_delegate(
Avi (use Gerrit) 2016/05/13 21:54:25 Same "mock" naming issue here.
wjmaclean 2016/05/13 22:17:23 Done.
849 new MockWasAudibleWebContentsDelegate);
850 embedder->SetDelegate(mock_delegate.get());
851
852 // Just in case we get console error messages from the guest, we should
853 // surface them in the test output.
854 EXPECT_TRUE(content::ExecuteScript(
855 embedder,
856 "wv = document.getElementsByTagName('webview')[0];"
857 "wv.addEventListener('consolemessage', function (e) {"
858 " console.log('WebViewTest Guest: ' + e.message);"
859 "});"));
860
861 // Inject JS to start audio.
862 GURL audio_url = embedded_test_server()->GetURL(
863 "/extensions/platform_apps/web_view/simple/ping.mp3");
864 std::string setup_audio_script = base::StringPrintf(
865 "ae = document.createElement('audio');"
866 "ae.src='%s';"
867 "document.body.appendChild(ae);"
868 "ae.play();",
869 audio_url.spec().c_str());
870 EXPECT_TRUE(content::ExecuteScript(guest, setup_audio_script));
871
872 mock_delegate->WaitForInvalidateTypeTab();
873 EXPECT_TRUE(embedder->WasRecentlyAudible());
874 EXPECT_TRUE(guest->WasRecentlyAudible());
875
876 // Wait for audio to stop (the .mp3 is shorter than the audio stream
Avi (use Gerrit) 2016/05/13 21:54:26 unmatched ( in the comment
wjmaclean 2016/05/13 22:17:23 Done.
877 // monitor's timeout, so no need to explicitly stop it. Other callers may
878 // call NotifyNavigationStateChanged() on the embedder web contents, so
879 // we may have to wait several times.
880 while (embedder->WasRecentlyAudible())
881 mock_delegate->WaitForInvalidateTypeTab();
882 EXPECT_FALSE(embedder->WasRecentlyAudible());
883 EXPECT_FALSE(guest->WasRecentlyAudible());
884 }
885
809 IN_PROC_BROWSER_TEST_P(WebViewTest, AudioMutesWhileAttached) { 886 IN_PROC_BROWSER_TEST_P(WebViewTest, AudioMutesWhileAttached) {
810 LoadAppWithGuest("web_view/simple"); 887 LoadAppWithGuest("web_view/simple");
811 888
812 content::WebContents* embedder = GetEmbedderWebContents(); 889 content::WebContents* embedder = GetEmbedderWebContents();
813 content::WebContents* guest = GetGuestWebContents(); 890 content::WebContents* guest = GetGuestWebContents();
814 891
815 EXPECT_FALSE(embedder->IsAudioMuted()); 892 EXPECT_FALSE(embedder->IsAudioMuted());
816 EXPECT_FALSE(guest->IsAudioMuted()); 893 EXPECT_FALSE(guest->IsAudioMuted());
817 894
818 embedder->SetAudioMuted(true); 895 embedder->SetAudioMuted(true);
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2991 gfx::Point embedder_origin = 3068 gfx::Point embedder_origin =
2992 GetEmbedderWebContents()->GetContainerBounds().origin(); 3069 GetEmbedderWebContents()->GetContainerBounds().origin();
2993 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); 3070 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y());
2994 3071
2995 // Generate and send synthetic touch event. 3072 // Generate and send synthetic touch event.
2996 content::SimulateTouchPressAt(GetEmbedderWebContents(), 3073 content::SimulateTouchPressAt(GetEmbedderWebContents(),
2997 guest_rect.CenterPoint()); 3074 guest_rect.CenterPoint());
2998 EXPECT_TRUE(aura_webview->HasFocus()); 3075 EXPECT_TRUE(aura_webview->HasFocus());
2999 } 3076 }
3000 #endif 3077 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698