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

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

Issue 1554233004: Plumb audio muting state to guest web-contents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 11 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/app_creates_webview/main.html » ('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 <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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 protected: 738 protected:
739 void SetUpCommandLine(base::CommandLine* command_line) override { 739 void SetUpCommandLine(base::CommandLine* command_line) override {
740 WebViewTest::SetUpCommandLine(command_line); 740 WebViewTest::SetUpCommandLine(command_line);
741 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, 741 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
742 base::StringPrintf("%f", scale())); 742 base::StringPrintf("%f", scale()));
743 } 743 }
744 744
745 static float scale() { return 2.0f; } 745 static float scale() { return 2.0f; }
746 }; 746 };
747 747
748 class WebContentsAudioMutedObserver : public content::WebContentsObserver {
749 public:
750 explicit WebContentsAudioMutedObserver(content::WebContents* web_contents)
751 : WebContentsObserver(web_contents),
752 loop_runner_(new content::MessageLoopRunner),
753 muting_update_observed_(false) {}
754
755 // WebContentsObserver.
756 void DidUpdateAudioMutingState(bool muted) override {
757 muting_update_observed_ = true;
758 loop_runner_->Quit();
759 }
760
761 void WaitForUpdate() {
762 loop_runner_->Run();
763 }
764
765 bool muting_update_observed() { return muting_update_observed_; }
766
767 private:
768 scoped_refptr<content::MessageLoopRunner> loop_runner_;
769 bool muting_update_observed_;
770
771 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioMutedObserver);
772 };
773
774 IN_PROC_BROWSER_TEST_F(WebViewTest, AudioMutesWhileAttached) {
775 LoadAppWithGuest("web_view/simple");
776
777 content::WebContents* embedder = GetEmbedderWebContents();
778 content::WebContents* guest = GetGuestWebContents();
779
780 EXPECT_FALSE(embedder->IsAudioMuted());
781 EXPECT_FALSE(guest->IsAudioMuted());
782
783 embedder->SetAudioMuted(true);
784 EXPECT_TRUE(embedder->IsAudioMuted());
785 EXPECT_TRUE(guest->IsAudioMuted());
786
787 embedder->SetAudioMuted(false);
788 EXPECT_FALSE(embedder->IsAudioMuted());
789 EXPECT_FALSE(guest->IsAudioMuted());
790 }
791
792 IN_PROC_BROWSER_TEST_F(WebViewTest, AudioMutesOnAttach) {
793 LoadAndLaunchPlatformApp("web_view/app_creates_webview",
794 "WebViewTest.LAUNCHED");
795 content::WebContents* embedder = GetEmbedderWebContents();
796 embedder->SetAudioMuted(true);
797 EXPECT_TRUE(embedder->IsAudioMuted());
798
799 SendMessageToEmbedder("create-guest");
800 content::WebContents* guest =
801 GetGuestViewManager()->WaitForSingleGuestCreated();
802
803 EXPECT_TRUE(embedder->IsAudioMuted());
804 WebContentsAudioMutedObserver observer(guest);
805 // If the guest hasn't attached yet, it may not have received the muting
806 // update, in which case we should wait until it does.
807 if (!guest->IsAudioMuted())
808 observer.WaitForUpdate();
809 EXPECT_TRUE(guest->IsAudioMuted());
810 }
811
748 // This test verifies that hiding the guest triggers WebContents::WasHidden(). 812 // This test verifies that hiding the guest triggers WebContents::WasHidden().
749 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest, GuestVisibilityChanged) { 813 IN_PROC_BROWSER_TEST_F(WebViewVisibilityTest, GuestVisibilityChanged) {
750 LoadAppWithGuest("web_view/visibility_changed"); 814 LoadAppWithGuest("web_view/visibility_changed");
751 815
752 scoped_refptr<content::MessageLoopRunner> loop_runner( 816 scoped_refptr<content::MessageLoopRunner> loop_runner(
753 new content::MessageLoopRunner); 817 new content::MessageLoopRunner);
754 WebContentsHiddenObserver observer(GetGuestWebContents(), 818 WebContentsHiddenObserver observer(GetGuestWebContents(),
755 loop_runner->QuitClosure()); 819 loop_runner->QuitClosure());
756 820
757 // Handled in platform_apps/web_view/visibility_changed/main.js 821 // Handled in platform_apps/web_view/visibility_changed/main.js
(...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2955 // 4 tasks expected. The order is arbitrary. 3019 // 4 tasks expected. The order is arbitrary.
2956 // Tab: about:blank, 3020 // Tab: about:blank,
2957 // Background Page: <webview> task manager test, 3021 // Background Page: <webview> task manager test,
2958 // App: <webview> task manager test, 3022 // App: <webview> task manager test,
2959 // Webview: WebViewed test content. 3023 // Webview: WebViewed test content.
2960 EXPECT_EQ(4U, task_manager.tasks().size()); 3024 EXPECT_EQ(4U, task_manager.tasks().size());
2961 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); 3025 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents));
2962 } 3026 }
2963 3027
2964 #endif // defined(ENABLE_TASK_MANAGER) 3028 #endif // defined(ENABLE_TASK_MANAGER)
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/app_creates_webview/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698