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

Unified Diff: chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm

Issue 1412083002: Indicate in the Window menu which Chrome window has an active sound playing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: put Emojis in generated_resources.grd Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm
index cfe3a71bb9e0a5e9f3eabb76901cd39a4506f421..b22e15550a92a8b7d8c3f84158fe48dedc359731 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm
@@ -9,6 +9,7 @@
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/media_stream_capture_indicator.h"
#include "chrome/browser/ui/browser_window.h"
+#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#import "chrome/browser/ui/cocoa/new_tab_button.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
@@ -29,6 +30,21 @@
using content::SiteInstance;
using content::WebContents;
+// Keeps media state of tabs in browser for testing purpose.
+static std::map<content::WebContents*, TabMediaState>
Robert Sesek 2015/10/28 18:45:58 Rather than keeping this in a static, store this i
+ contents_media_state_maps_;
+
+@interface TabStripControllerForMediaTesting : TabStripController {
+}
+@end
+
+@implementation TabStripControllerForMediaTesting
+// Returns the media state of each tab from the map we are keeping.
+- (TabMediaState)getMediaStateForContents:(content::WebContents*)contents {
+ return contents_media_state_maps_[contents];
+}
+@end
+
@interface TestTabStripControllerDelegate
: NSObject<TabStripControllerDelegate> {
}
@@ -102,7 +118,8 @@ class TabStripControllerTest : public CocoaProfileTest {
NSRect switch_frame = NSMakeRect(0, 0, content_frame.size.width, 500);
base::scoped_nsobject<NSView> switch_view(
[[NSView alloc] initWithFrame:switch_frame]);
- [parent addSubview:switch_view.get()];
+ switch_view_ = switch_view;
+ [parent addSubview:switch_view_.get()];
// Create the tab strip view. It's expected to have a child button in it
// already as the "new tab" button so create that too.
@@ -135,6 +152,17 @@ class TabStripControllerTest : public CocoaProfileTest {
CocoaProfileTest::TearDown();
}
+ // Return a derived TabStripController.
+ TabStripControllerForMediaTesting* InitTabStripControllerForMediaTesting() {
+ TabStripControllerForMediaTesting* c =
+ [[TabStripControllerForMediaTesting alloc]
+ initWithView:static_cast<TabStripView*>(tab_strip_.get())
+ switchView:switch_view_.get()
+ browser:browser()
+ delegate:controller_delegate_.get()];
+ return c;
+ }
+
TabView* CreateTab() {
SiteInstance* instance = SiteInstance::Create(profile());
WebContents* web_contents = WebContents::Create(
@@ -162,6 +190,7 @@ class TabStripControllerTest : public CocoaProfileTest {
base::scoped_nsobject<TestTabStripControllerDelegate> controller_delegate_;
base::scoped_nsobject<TabStripController> controller_;
base::scoped_nsobject<TabStripView> tab_strip_;
+ base::scoped_nsobject<NSView> switch_view_;
};
// Test adding and removing tabs and making sure that views get added to
@@ -349,4 +378,73 @@ TEST_F(TabStripControllerTest, ViewAccessibility_Value) {
EXPECT_EQ(tab1, value);
}
+TEST_F(TabStripControllerTest, CorrectWindowFromUpdateWindowMediaState) {
+ controller_.reset(InitTabStripControllerForMediaTesting());
+ NSWindow* window = [tab_strip_ window];
+ BrowserWindowController* windowController =
Robert Sesek 2015/10/28 18:45:58 naming: Use under_scores for variable names, excep
+ [BrowserWindowController browserWindowControllerForWindow:window];
+
+ TabView* const tab1 = CreateTab();
+ TabView* const tab2 = CreateTab();
+
+ // tab2 should be the selected one.
+ EXPECT_FALSE([tab1 controller].selected);
+ EXPECT_TRUE([tab2 controller].selected);
+ WebContents* const contentsAtTab1 = model_->GetActiveWebContents();
+
+ contents_media_state_maps_[contentsAtTab1] = TAB_MEDIA_STATE_AUDIO_PLAYING;
+ // Make sure the overriden from base controller correctly handles media
+ // status of tabs.
+ EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING,
+ [controller_ getMediaStateForContents:contentsAtTab1]);
+ [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING
+ on:contentsAtTab1];
+ // Because we have one tab playing, and the other one's media state is none,
+ // window media state should be AUDIO_PLAYING.
+ EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [windowController getMediaState]);
+
+ model_->ActivateTabAt(0, false);
+ // tab1 should be the selected one now.
+ EXPECT_TRUE([tab1 controller].selected);
+ EXPECT_FALSE([tab2 controller].selected);
+ WebContents* const contentsAtTab0 = model_->GetActiveWebContents();
+
+ contents_media_state_maps_[contentsAtTab0] = TAB_MEDIA_STATE_AUDIO_MUTING;
+ [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_MUTING
+ on:contentsAtTab0];
+ // We have two tabs. One is playing and the other one is muting. The window
+ // media state should be still AUDIO_PLAYING.
+ EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [windowController getMediaState]);
+
+ contents_media_state_maps_[contentsAtTab1] = TAB_MEDIA_STATE_AUDIO_MUTING;
+ [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_MUTING
+ on:contentsAtTab1];
+ // Now both tabs are muting, the window media state should be AUDIO_MUTING.
+ EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_MUTING, [windowController getMediaState]);
+
+ contents_media_state_maps_[contentsAtTab0] = TAB_MEDIA_STATE_AUDIO_PLAYING;
+ [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING
+ on:contentsAtTab0];
+ // Among those tabs which were muting, one is started playing, the window
+ // media state should be playing.
+ EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [windowController getMediaState]);
+
+ // Mute it again for further testing.
+ contents_media_state_maps_[contentsAtTab0] = TAB_MEDIA_STATE_AUDIO_MUTING;
+ [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_MUTING
+ on:contentsAtTab0];
+
+ contents_media_state_maps_[contentsAtTab1] = TAB_MEDIA_STATE_NONE;
+ [controller_ updateWindowMediaState:TAB_MEDIA_STATE_NONE on:contentsAtTab1];
+ // One of the tabs is muting, the other one is none. So window media state
+ // should be MUTING.
+ EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_MUTING, [windowController getMediaState]);
+
+ contents_media_state_maps_[contentsAtTab0] = TAB_MEDIA_STATE_NONE;
+ [controller_ updateWindowMediaState:TAB_MEDIA_STATE_NONE on:contentsAtTab0];
+ // Neither of tabs playing nor muting, so the window media state should be
+ // NONE.
+ EXPECT_EQ(TAB_MEDIA_STATE_NONE, [windowController getMediaState]);
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698