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

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: Address comments. 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/simple/ping.mp3 » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 6 #include <set>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 811
812 bool muting_update_observed() { return muting_update_observed_; } 812 bool muting_update_observed() { return muting_update_observed_; }
813 813
814 private: 814 private:
815 scoped_refptr<content::MessageLoopRunner> loop_runner_; 815 scoped_refptr<content::MessageLoopRunner> loop_runner_;
816 bool muting_update_observed_; 816 bool muting_update_observed_;
817 817
818 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioMutedObserver); 818 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioMutedObserver);
819 }; 819 };
820 820
821 class WasAudibleWebContentsDelegate : public content::WebContentsDelegate {
822 public:
823 WasAudibleWebContentsDelegate() : invalidate_type_tab_seen_(false) {}
824
825 void NavigationStateChanged(content::WebContents* contents,
826 content::InvalidateTypes changed_flags) override {
827 if (changed_flags == content::INVALIDATE_TYPE_TAB) {
828 invalidate_type_tab_seen_ = true;
829 if (message_loop_runner_.get())
830 message_loop_runner_->Quit();
831 }
832 }
833
834 void WaitForInvalidateTypeTab() {
835 if (!invalidate_type_tab_seen_) {
836 message_loop_runner_ = new content::MessageLoopRunner;
837 message_loop_runner_->Run();
838 }
839 invalidate_type_tab_seen_ = false;
840 }
841
842 private:
843 bool invalidate_type_tab_seen_;
844 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
845
846 DISALLOW_COPY_AND_ASSIGN(WasAudibleWebContentsDelegate);
847 };
848
849 IN_PROC_BROWSER_TEST_P(WebViewTest, AudibilityStatePropagates) {
850 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest audio.
851
852 LoadAppWithGuest("web_view/simple");
853
854 content::WebContents* embedder = GetEmbedderWebContents();
855 content::WebContents* guest = GetGuestWebContents();
856
857 EXPECT_FALSE(embedder->WasRecentlyAudible());
858 EXPECT_FALSE(guest->WasRecentlyAudible());
859
860 std::unique_ptr<WasAudibleWebContentsDelegate> was_audible_delegate(
861 new WasAudibleWebContentsDelegate);
862 embedder->SetDelegate(was_audible_delegate.get());
863
864 // Just in case we get console error messages from the guest, we should
865 // surface them in the test output.
866 EXPECT_TRUE(content::ExecuteScript(
867 embedder,
868 "wv = document.getElementsByTagName('webview')[0];"
869 "wv.addEventListener('consolemessage', function (e) {"
870 " console.log('WebViewTest Guest: ' + e.message);"
871 "});"));
872
873 // Inject JS to start audio.
874 GURL audio_url = embedded_test_server()->GetURL(
875 "/extensions/platform_apps/web_view/simple/ping.mp3");
876 std::string setup_audio_script = base::StringPrintf(
877 "ae = document.createElement('audio');"
878 "ae.src='%s';"
879 "document.body.appendChild(ae);"
880 "ae.play();",
881 audio_url.spec().c_str());
882 EXPECT_TRUE(content::ExecuteScript(guest, setup_audio_script));
883
884 was_audible_delegate->WaitForInvalidateTypeTab();
885 EXPECT_TRUE(embedder->WasRecentlyAudible());
886 EXPECT_TRUE(guest->WasRecentlyAudible());
887
888 // Wait for audio to stop (the .mp3 is shorter than the audio stream
889 // monitor's timeout, so no need to explicitly stop it. Other callers may
890 // call NotifyNavigationStateChanged() on the embedder web contents, so
891 // we may have to wait several times).
892 while (embedder->WasRecentlyAudible())
893 was_audible_delegate->WaitForInvalidateTypeTab();
894 EXPECT_FALSE(embedder->WasRecentlyAudible());
895 EXPECT_FALSE(guest->WasRecentlyAudible());
896 }
897
821 IN_PROC_BROWSER_TEST_P(WebViewTest, AudioMutesWhileAttached) { 898 IN_PROC_BROWSER_TEST_P(WebViewTest, AudioMutesWhileAttached) {
822 LoadAppWithGuest("web_view/simple"); 899 LoadAppWithGuest("web_view/simple");
823 900
824 content::WebContents* embedder = GetEmbedderWebContents(); 901 content::WebContents* embedder = GetEmbedderWebContents();
825 content::WebContents* guest = GetGuestWebContents(); 902 content::WebContents* guest = GetGuestWebContents();
826 903
827 EXPECT_FALSE(embedder->IsAudioMuted()); 904 EXPECT_FALSE(embedder->IsAudioMuted());
828 EXPECT_FALSE(guest->IsAudioMuted()); 905 EXPECT_FALSE(guest->IsAudioMuted());
829 906
830 embedder->SetAudioMuted(true); 907 embedder->SetAudioMuted(true);
(...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after
3353 gfx::Point embedder_origin = 3430 gfx::Point embedder_origin =
3354 GetEmbedderWebContents()->GetContainerBounds().origin(); 3431 GetEmbedderWebContents()->GetContainerBounds().origin();
3355 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); 3432 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y());
3356 3433
3357 // Generate and send synthetic touch event. 3434 // Generate and send synthetic touch event.
3358 content::SimulateTouchPressAt(GetEmbedderWebContents(), 3435 content::SimulateTouchPressAt(GetEmbedderWebContents(),
3359 guest_rect.CenterPoint()); 3436 guest_rect.CenterPoint());
3360 EXPECT_TRUE(aura_webview->HasFocus()); 3437 EXPECT_TRUE(aura_webview->HasFocus());
3361 } 3438 }
3362 #endif 3439 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/simple/ping.mp3 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698