| OLD | NEW |
| 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 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_controller.h" | 5 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/media/desktop_media_list_observer.h" | 10 #include "chrome/browser/media/desktop_media_list_observer.h" |
| 11 #include "chrome/browser/media/fake_desktop_media_list.h" | 11 #include "chrome/browser/media/fake_desktop_media_list.h" |
| 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 13 #import "chrome/browser/ui/cocoa/media_picker/desktop_media_picker_item.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "testing/gtest_mac.h" | 15 #include "testing/gtest_mac.h" |
| 15 | 16 |
| 17 using content::DesktopMediaID; |
| 18 |
| 16 @interface DesktopMediaPickerController (ExposedForTesting) | 19 @interface DesktopMediaPickerController (ExposedForTesting) |
| 17 - (IKImageBrowserView*)sourceBrowser; | 20 - (IKImageBrowserView*)screenBrowser; |
| 21 - (IKImageBrowserView*)windowBrowser; |
| 22 - (NSTableView*)tabBrowser; |
| 23 - (NSSegmentedControl*)sourceTypeControl; |
| 18 - (NSButton*)shareButton; | 24 - (NSButton*)shareButton; |
| 19 - (NSButton*)audioShareCheckbox; | 25 - (NSButton*)audioShareCheckbox; |
| 20 - (NSArray*)items; | 26 - (NSArray*)screenItems; |
| 27 - (NSArray*)windowItems; |
| 28 - (NSArray*)tabItems; |
| 21 @end | 29 @end |
| 22 | 30 |
| 23 @implementation DesktopMediaPickerController (ExposedForTesting) | 31 @implementation DesktopMediaPickerController (ExposedForTesting) |
| 24 - (IKImageBrowserView*)sourceBrowser { | 32 - (IKImageBrowserView*)screenBrowser { |
| 25 return sourceBrowser_; | 33 return screenBrowser_; |
| 34 } |
| 35 |
| 36 - (IKImageBrowserView*)windowBrowser { |
| 37 return windowBrowser_; |
| 38 } |
| 39 |
| 40 - (NSTableView*)tabBrowser { |
| 41 return tabBrowser_; |
| 42 } |
| 43 |
| 44 - (NSSegmentedControl*)sourceTypeControl { |
| 45 return sourceTypeControl_; |
| 26 } | 46 } |
| 27 | 47 |
| 28 - (NSButton*)shareButton { | 48 - (NSButton*)shareButton { |
| 29 return shareButton_; | 49 return shareButton_; |
| 30 } | 50 } |
| 31 | 51 |
| 32 - (NSButton*)cancelButton { | 52 - (NSButton*)cancelButton { |
| 33 return cancelButton_; | 53 return cancelButton_; |
| 34 } | 54 } |
| 35 | 55 |
| 36 - (NSButton*)audioShareCheckbox { | 56 - (NSButton*)audioShareCheckbox { |
| 37 return audioShareCheckbox_; | 57 return audioShareCheckbox_; |
| 38 } | 58 } |
| 39 | 59 |
| 40 - (NSArray*)items { | 60 - (NSArray*)screenItems { |
| 41 return items_; | 61 return screenItems_; |
| 42 } | 62 } |
| 63 |
| 64 - (NSArray*)windowItems { |
| 65 return windowItems_; |
| 66 } |
| 67 |
| 68 - (NSArray*)tabItems { |
| 69 return tabItems_; |
| 70 } |
| 71 |
| 43 @end | 72 @end |
| 44 | 73 |
| 45 class DesktopMediaPickerControllerTest : public CocoaTest { | 74 class DesktopMediaPickerControllerTest : public CocoaTest { |
| 46 public: | 75 public: |
| 47 DesktopMediaPickerControllerTest() {} | 76 DesktopMediaPickerControllerTest() {} |
| 48 | 77 |
| 49 void SetUp() override { | 78 void SetUp() override { |
| 50 CocoaTest::SetUp(); | 79 CocoaTest::SetUp(); |
| 51 | 80 |
| 52 screen_list_ = new FakeDesktopMediaList(); | 81 screen_list_ = new FakeDesktopMediaList(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 73 CocoaTest::TearDown(); | 102 CocoaTest::TearDown(); |
| 74 } | 103 } |
| 75 | 104 |
| 76 bool WaitForCallback() { | 105 bool WaitForCallback() { |
| 77 if (!callback_called_) { | 106 if (!callback_called_) { |
| 78 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
| 79 } | 108 } |
| 80 return callback_called_; | 109 return callback_called_; |
| 81 } | 110 } |
| 82 | 111 |
| 112 void ChangeType(DesktopMediaID::Type sourceType) { |
| 113 NSSegmentedControl* control = [controller_ sourceTypeControl]; |
| 114 [control selectSegmentWithTag:sourceType]; |
| 115 // [control selectSegmentWithTag] does not trigger handler, so we need to |
| 116 // trigger it manually. |
| 117 [[control target] performSelector:[control action] withObject:control]; |
| 118 } |
| 119 |
| 120 void AddWindow(int id) { |
| 121 window_list_->AddSourceByFullMediaID( |
| 122 DesktopMediaID(DesktopMediaID::TYPE_WINDOW, id)); |
| 123 } |
| 124 |
| 125 void AddScreen(int id) { |
| 126 screen_list_->AddSourceByFullMediaID( |
| 127 DesktopMediaID(DesktopMediaID::TYPE_SCREEN, id)); |
| 128 } |
| 129 |
| 130 void AddTab(int id) { |
| 131 tab_list_->AddSourceByFullMediaID( |
| 132 DesktopMediaID(DesktopMediaID::TYPE_WEB_CONTENTS, id)); |
| 133 } |
| 134 |
| 83 protected: | 135 protected: |
| 84 void OnResult(content::DesktopMediaID source) { | 136 void OnResult(DesktopMediaID source) { |
| 85 EXPECT_FALSE(callback_called_); | 137 EXPECT_FALSE(callback_called_); |
| 86 callback_called_ = true; | 138 callback_called_ = true; |
| 87 source_reported_ = source; | 139 source_reported_ = source; |
| 88 } | 140 } |
| 89 | 141 |
| 90 content::TestBrowserThreadBundle thread_bundle_; | 142 content::TestBrowserThreadBundle thread_bundle_; |
| 91 bool callback_called_ = false; | 143 bool callback_called_ = false; |
| 92 content::DesktopMediaID source_reported_; | 144 DesktopMediaID source_reported_; |
| 93 FakeDesktopMediaList* screen_list_ = nullptr; | 145 FakeDesktopMediaList* screen_list_ = nullptr; |
| 94 FakeDesktopMediaList* window_list_ = nullptr; | 146 FakeDesktopMediaList* window_list_ = nullptr; |
| 95 FakeDesktopMediaList* tab_list_ = nullptr; | 147 FakeDesktopMediaList* tab_list_ = nullptr; |
| 96 base::scoped_nsobject<DesktopMediaPickerController> controller_; | 148 base::scoped_nsobject<DesktopMediaPickerController> controller_; |
| 97 }; | 149 }; |
| 98 | 150 |
| 99 TEST_F(DesktopMediaPickerControllerTest, ShowAndDismiss) { | 151 TEST_F(DesktopMediaPickerControllerTest, ShowAndDismiss) { |
| 100 [controller_ showWindow:nil]; | 152 [controller_ showWindow:nil]; |
| 153 ChangeType(DesktopMediaID::TYPE_SCREEN); |
| 101 | 154 |
| 102 window_list_->AddSource(0); | 155 AddScreen(0); |
| 103 window_list_->AddSource(1); | 156 AddScreen(1); |
| 104 window_list_->SetSourceThumbnail(1); | 157 screen_list_->SetSourceThumbnail(1); |
| 105 | 158 |
| 106 NSArray* items = [controller_ items]; | 159 NSArray* items = [controller_ screenItems]; |
| 107 EXPECT_EQ(2U, [items count]); | 160 EXPECT_EQ(2U, [items count]); |
| 108 EXPECT_NSEQ(@"0", [[items objectAtIndex:0] imageTitle]); | 161 EXPECT_NSEQ(@"0", [[items objectAtIndex:0] imageTitle]); |
| 109 EXPECT_EQ(nil, [[items objectAtIndex:0] imageRepresentation]); | 162 EXPECT_EQ(nil, [[items objectAtIndex:0] imageRepresentation]); |
| 110 EXPECT_NSEQ(@"1", [[items objectAtIndex:1] imageTitle]); | 163 EXPECT_NSEQ(@"1", [[items objectAtIndex:1] imageTitle]); |
| 111 EXPECT_TRUE([[items objectAtIndex:1] imageRepresentation] != nil); | 164 EXPECT_TRUE([[items objectAtIndex:1] imageRepresentation] != nil); |
| 112 } | 165 } |
| 113 | 166 |
| 114 TEST_F(DesktopMediaPickerControllerTest, ClickShare) { | 167 TEST_F(DesktopMediaPickerControllerTest, ClickShareScreen) { |
| 115 [controller_ showWindow:nil]; | 168 [controller_ showWindow:nil]; |
| 169 ChangeType(DesktopMediaID::TYPE_SCREEN); |
| 170 AddScreen(0); |
| 171 screen_list_->SetSourceThumbnail(0); |
| 172 AddScreen(1); |
| 173 screen_list_->SetSourceThumbnail(1); |
| 116 | 174 |
| 117 window_list_->AddSource(0); | 175 EXPECT_EQ(2U, [[controller_ screenItems] count]); |
| 118 window_list_->SetSourceThumbnail(0); | |
| 119 window_list_->AddSource(1); | |
| 120 window_list_->SetSourceThumbnail(1); | |
| 121 | |
| 122 EXPECT_EQ(2U, [[controller_ items] count]); | |
| 123 EXPECT_FALSE([[controller_ shareButton] isEnabled]); | 176 EXPECT_FALSE([[controller_ shareButton] isEnabled]); |
| 124 | 177 |
| 125 NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:1]; | 178 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:1]; |
| 126 [[controller_ sourceBrowser] setSelectionIndexes:indexSet | 179 [[controller_ screenBrowser] setSelectionIndexes:index_set |
| 127 byExtendingSelection:NO]; | 180 byExtendingSelection:NO]; |
| 128 EXPECT_TRUE([[controller_ shareButton] isEnabled]); | 181 EXPECT_TRUE([[controller_ shareButton] isEnabled]); |
| 129 | 182 |
| 183 [[controller_ shareButton] performClick:nil]; |
| 184 EXPECT_TRUE(WaitForCallback()); |
| 185 EXPECT_EQ(screen_list_->GetSource(1).id, source_reported_); |
| 186 } |
| 187 |
| 188 TEST_F(DesktopMediaPickerControllerTest, ClickShareWindow) { |
| 189 [controller_ showWindow:nil]; |
| 190 ChangeType(DesktopMediaID::TYPE_WINDOW); |
| 191 AddWindow(0); |
| 192 window_list_->SetSourceThumbnail(0); |
| 193 AddWindow(1); |
| 194 window_list_->SetSourceThumbnail(1); |
| 195 |
| 196 EXPECT_EQ(2U, [[controller_ windowItems] count]); |
| 197 EXPECT_FALSE([[controller_ shareButton] isEnabled]); |
| 198 |
| 199 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:1]; |
| 200 [[controller_ windowBrowser] setSelectionIndexes:index_set |
| 201 byExtendingSelection:NO]; |
| 202 EXPECT_TRUE([[controller_ shareButton] isEnabled]); |
| 203 |
| 130 [[controller_ shareButton] performClick:nil]; | 204 [[controller_ shareButton] performClick:nil]; |
| 131 EXPECT_TRUE(WaitForCallback()); | 205 EXPECT_TRUE(WaitForCallback()); |
| 132 EXPECT_EQ(window_list_->GetSource(1).id, source_reported_); | 206 EXPECT_EQ(window_list_->GetSource(1).id, source_reported_); |
| 133 } | 207 } |
| 134 | 208 |
| 209 TEST_F(DesktopMediaPickerControllerTest, ClickShareTab) { |
| 210 [controller_ showWindow:nil]; |
| 211 ChangeType(DesktopMediaID::TYPE_WEB_CONTENTS); |
| 212 AddTab(0); |
| 213 tab_list_->SetSourceThumbnail(0); |
| 214 AddTab(1); |
| 215 tab_list_->SetSourceThumbnail(1); |
| 216 |
| 217 EXPECT_EQ(2U, [[controller_ tabItems] count]); |
| 218 EXPECT_FALSE([[controller_ shareButton] isEnabled]); |
| 219 |
| 220 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:1]; |
| 221 [[controller_ tabBrowser] selectRowIndexes:index_set byExtendingSelection:NO]; |
| 222 EXPECT_TRUE([[controller_ shareButton] isEnabled]); |
| 223 |
| 224 // Disable audio share here, otherwise the |source_reported_| will be |
| 225 // different from original Id, because audio share is by default on. |
| 226 [[controller_ audioShareCheckbox] setState:NSOffState]; |
| 227 [[controller_ shareButton] performClick:nil]; |
| 228 EXPECT_TRUE(WaitForCallback()); |
| 229 EXPECT_EQ(tab_list_->GetSource(1).id, source_reported_); |
| 230 } |
| 231 |
| 135 TEST_F(DesktopMediaPickerControllerTest, ClickCancel) { | 232 TEST_F(DesktopMediaPickerControllerTest, ClickCancel) { |
| 136 [controller_ showWindow:nil]; | 233 [controller_ showWindow:nil]; |
| 234 ChangeType(DesktopMediaID::TYPE_WINDOW); |
| 137 | 235 |
| 138 window_list_->AddSource(0); | 236 AddWindow(0); |
| 139 window_list_->SetSourceThumbnail(0); | 237 window_list_->SetSourceThumbnail(0); |
| 140 window_list_->AddSource(1); | 238 AddWindow(1); |
| 141 window_list_->SetSourceThumbnail(1); | 239 window_list_->SetSourceThumbnail(1); |
| 142 | 240 |
| 241 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:1]; |
| 242 [[controller_ windowBrowser] setSelectionIndexes:index_set |
| 243 byExtendingSelection:NO]; |
| 143 [[controller_ cancelButton] performClick:nil]; | 244 [[controller_ cancelButton] performClick:nil]; |
| 144 EXPECT_TRUE(WaitForCallback()); | 245 EXPECT_TRUE(WaitForCallback()); |
| 145 EXPECT_EQ(content::DesktopMediaID(), source_reported_); | 246 EXPECT_EQ(DesktopMediaID(), source_reported_); |
| 146 } | 247 } |
| 147 | 248 |
| 148 TEST_F(DesktopMediaPickerControllerTest, CloseWindow) { | 249 TEST_F(DesktopMediaPickerControllerTest, CloseWindow) { |
| 149 [controller_ showWindow:nil]; | 250 [controller_ showWindow:nil]; |
| 251 ChangeType(DesktopMediaID::TYPE_SCREEN); |
| 150 | 252 |
| 151 window_list_->AddSource(0); | 253 AddScreen(0); |
| 152 window_list_->SetSourceThumbnail(0); | 254 screen_list_->SetSourceThumbnail(0); |
| 153 window_list_->AddSource(1); | 255 AddScreen(1); |
| 154 window_list_->SetSourceThumbnail(1); | 256 screen_list_->SetSourceThumbnail(1); |
| 155 | 257 |
| 156 [controller_ close]; | 258 [controller_ close]; |
| 157 EXPECT_TRUE(WaitForCallback()); | 259 EXPECT_TRUE(WaitForCallback()); |
| 158 EXPECT_EQ(content::DesktopMediaID(), source_reported_); | 260 EXPECT_EQ(DesktopMediaID(), source_reported_); |
| 159 } | 261 } |
| 160 | 262 |
| 161 TEST_F(DesktopMediaPickerControllerTest, UpdateThumbnail) { | 263 TEST_F(DesktopMediaPickerControllerTest, UpdateThumbnail) { |
| 162 [controller_ showWindow:nil]; | 264 [controller_ showWindow:nil]; |
| 265 ChangeType(DesktopMediaID::TYPE_WEB_CONTENTS); |
| 163 | 266 |
| 164 window_list_->AddSource(0); | 267 AddTab(0); |
| 165 window_list_->SetSourceThumbnail(0); | 268 tab_list_->SetSourceThumbnail(0); |
| 166 window_list_->AddSource(1); | 269 AddTab(1); |
| 167 window_list_->SetSourceThumbnail(1); | 270 tab_list_->SetSourceThumbnail(1); |
| 168 | 271 |
| 169 NSArray* items = [controller_ items]; | 272 NSArray* items = [controller_ tabItems]; |
| 170 EXPECT_EQ(2U, [items count]); | 273 EXPECT_EQ(2U, [items count]); |
| 171 NSUInteger version = [[items objectAtIndex:0] imageVersion]; | 274 NSUInteger version = [[items objectAtIndex:0] imageVersion]; |
| 172 | 275 |
| 173 window_list_->SetSourceThumbnail(0); | 276 tab_list_->SetSourceThumbnail(0); |
| 174 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); | 277 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); |
| 175 } | 278 } |
| 176 | 279 |
| 177 TEST_F(DesktopMediaPickerControllerTest, UpdateName) { | 280 TEST_F(DesktopMediaPickerControllerTest, UpdateName) { |
| 178 [controller_ showWindow:nil]; | 281 [controller_ showWindow:nil]; |
| 282 ChangeType(DesktopMediaID::TYPE_WINDOW); |
| 179 | 283 |
| 180 window_list_->AddSource(0); | 284 AddWindow(0); |
| 181 window_list_->SetSourceThumbnail(0); | 285 window_list_->SetSourceThumbnail(0); |
| 182 window_list_->AddSource(1); | 286 AddWindow(1); |
| 183 window_list_->SetSourceThumbnail(1); | 287 window_list_->SetSourceThumbnail(1); |
| 184 | 288 |
| 185 NSArray* items = [controller_ items]; | 289 NSArray* items = [controller_ windowItems]; |
| 186 EXPECT_EQ(2U, [items count]); | 290 EXPECT_EQ(2U, [items count]); |
| 187 NSUInteger version = [[items objectAtIndex:0] imageVersion]; | 291 NSUInteger version = [[items objectAtIndex:0] imageVersion]; |
| 188 | 292 |
| 189 window_list_->SetSourceThumbnail(0); | 293 window_list_->SetSourceThumbnail(0); |
| 190 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); | 294 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); |
| 191 } | 295 } |
| 192 | 296 |
| 193 TEST_F(DesktopMediaPickerControllerTest, RemoveSource) { | 297 TEST_F(DesktopMediaPickerControllerTest, RemoveSource) { |
| 194 [controller_ showWindow:nil]; | 298 [controller_ showWindow:nil]; |
| 299 ChangeType(DesktopMediaID::TYPE_SCREEN); |
| 195 | 300 |
| 196 window_list_->AddSource(0); | 301 AddScreen(0); |
| 197 window_list_->AddSource(1); | 302 AddScreen(1); |
| 198 window_list_->AddSource(2); | 303 AddScreen(2); |
| 199 window_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); | 304 screen_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); |
| 200 | 305 |
| 201 NSArray* items = [controller_ items]; | 306 NSArray* items = [controller_ screenItems]; |
| 202 EXPECT_EQ(3U, [items count]); | 307 EXPECT_EQ(3U, [items count]); |
| 203 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); | 308 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); |
| 204 } | 309 } |
| 205 | 310 |
| 206 TEST_F(DesktopMediaPickerControllerTest, MoveSource) { | 311 TEST_F(DesktopMediaPickerControllerTest, MoveSource) { |
| 207 [controller_ showWindow:nil]; | 312 [controller_ showWindow:nil]; |
| 313 ChangeType(DesktopMediaID::TYPE_WINDOW); |
| 208 | 314 |
| 209 window_list_->AddSource(0); | 315 AddWindow(0); |
| 210 window_list_->AddSource(1); | 316 AddWindow(1); |
| 211 window_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); | 317 window_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); |
| 212 NSArray* items = [controller_ items]; | 318 NSArray* items = [controller_ windowItems]; |
| 213 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); | 319 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); |
| 214 | 320 |
| 215 window_list_->MoveSource(1, 0); | 321 window_list_->MoveSource(1, 0); |
| 216 EXPECT_NSEQ(@"foo", [[items objectAtIndex:0] imageTitle]); | 322 EXPECT_NSEQ(@"foo", [[items objectAtIndex:0] imageTitle]); |
| 217 | 323 |
| 218 window_list_->MoveSource(0, 1); | 324 window_list_->MoveSource(0, 1); |
| 219 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); | 325 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); |
| 220 } | 326 } |
| 221 | 327 |
| 222 // Make sure the audio share checkbox' state reacts correctly with | 328 // Make sure the audio share checkbox' state reacts correctly with |
| 223 // the source selection. Namely the checkbox is enabled only for tab | 329 // the source selection. Namely the checkbox is enabled only for tab |
| 224 // sharing on Mac. | 330 // sharing on Mac. |
| 225 TEST_F(DesktopMediaPickerControllerTest, AudioShareCheckboxState) { | 331 TEST_F(DesktopMediaPickerControllerTest, AudioShareCheckboxState) { |
| 226 [controller_ showWindow:nil]; | 332 [controller_ showWindow:nil]; |
| 227 | 333 |
| 228 screen_list_->AddSourceByFullMediaID( | 334 AddScreen(0); |
| 229 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, 0)); | 335 AddWindow(1); |
| 230 window_list_->AddSourceByFullMediaID( | 336 AddTab(2); |
| 231 content::DesktopMediaID(content::DesktopMediaID::TYPE_WINDOW, 1)); | |
| 232 tab_list_->AddSourceByFullMediaID( | |
| 233 content::DesktopMediaID(content::DesktopMediaID::TYPE_WEB_CONTENTS, 2)); | |
| 234 | 337 |
| 235 NSButton* checkbox = [controller_ audioShareCheckbox]; | 338 NSButton* checkbox = [controller_ audioShareCheckbox]; |
| 236 EXPECT_EQ(NO, [checkbox isEnabled]); | 339 EXPECT_EQ(YES, [checkbox isHidden]); |
| 340 |
| 341 [checkbox setHidden:NO]; |
| 342 ChangeType(DesktopMediaID::TYPE_WINDOW); |
| 343 EXPECT_EQ(YES, [checkbox isHidden]); |
| 344 |
| 345 [checkbox setHidden:YES]; |
| 346 ChangeType(DesktopMediaID::TYPE_WEB_CONTENTS); |
| 347 EXPECT_EQ(NO, [checkbox isHidden]); |
| 348 |
| 349 [checkbox setHidden:NO]; |
| 350 ChangeType(DesktopMediaID::TYPE_SCREEN); |
| 351 EXPECT_EQ(YES, [checkbox isHidden]); |
| 352 } |
| 353 |
| 354 TEST_F(DesktopMediaPickerControllerTest, TabShareWithAudio) { |
| 355 [controller_ showWindow:nil]; |
| 356 ChangeType(DesktopMediaID::TYPE_WEB_CONTENTS); |
| 357 |
| 358 DesktopMediaID origin_id = |
| 359 DesktopMediaID(DesktopMediaID::TYPE_WEB_CONTENTS, 123); |
| 360 DesktopMediaID id_with_audio = origin_id; |
| 361 id_with_audio.audio_share = true; |
| 362 |
| 363 tab_list_->AddSourceByFullMediaID(origin_id); |
| 237 | 364 |
| 238 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:0]; | 365 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:0]; |
| 239 [checkbox setEnabled:YES]; | 366 [[controller_ tabBrowser] selectRowIndexes:index_set byExtendingSelection:NO]; |
| 240 [[controller_ sourceBrowser] setSelectionIndexes:index_set | 367 EXPECT_TRUE([[controller_ shareButton] isEnabled]); |
| 241 byExtendingSelection:NO]; | |
| 242 EXPECT_EQ(NO, [checkbox isEnabled]); | |
| 243 | 368 |
| 244 index_set = [NSIndexSet indexSetWithIndex:1]; | 369 [[controller_ shareButton] performClick:nil]; |
| 245 [checkbox setEnabled:YES]; | |
| 246 [[controller_ sourceBrowser] setSelectionIndexes:index_set | |
| 247 byExtendingSelection:NO]; | |
| 248 EXPECT_EQ(NO, [checkbox isEnabled]); | |
| 249 | 370 |
| 250 index_set = [NSIndexSet indexSetWithIndex:2]; | 371 EXPECT_TRUE(WaitForCallback()); |
| 251 [[controller_ sourceBrowser] setSelectionIndexes:index_set | 372 EXPECT_EQ(id_with_audio, source_reported_); |
| 252 byExtendingSelection:NO]; | 373 } |
| 253 EXPECT_EQ(YES, [checkbox isEnabled]); | |
| 254 | 374 |
| 255 index_set = [NSIndexSet indexSet]; | 375 TEST_F(DesktopMediaPickerControllerTest, TabBrowserFocusAlgorithm) { |
| 256 [[controller_ sourceBrowser] setSelectionIndexes:index_set | 376 [controller_ showWindow:nil]; |
| 257 byExtendingSelection:NO]; | 377 ChangeType(DesktopMediaID::TYPE_WEB_CONTENTS); |
| 258 EXPECT_EQ(NO, [checkbox isEnabled]); | 378 AddTab(0); |
| 379 AddTab(1); |
| 380 AddTab(2); |
| 381 AddTab(3); |
| 382 |
| 383 NSArray* items = [controller_ tabItems]; |
| 384 NSTableView* browser = [controller_ tabBrowser]; |
| 385 |
| 386 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:1]; |
| 387 [browser selectRowIndexes:index_set byExtendingSelection:NO]; |
| 388 |
| 389 // Move source [0, 1, 2, 3]-->[1, 2, 3, 0] |
| 390 tab_list_->MoveSource(0, 3); |
| 391 NSUInteger selected_index = [[browser selectedRowIndexes] firstIndex]; |
| 392 EXPECT_EQ(1, [[items objectAtIndex:selected_index] sourceID].id); |
| 393 |
| 394 // Move source [1, 2, 3, 0]-->[3, 1, 2, 0] |
| 395 tab_list_->MoveSource(2, 0); |
| 396 selected_index = [[browser selectedRowIndexes] firstIndex]; |
| 397 EXPECT_EQ(1, [[items objectAtIndex:selected_index] sourceID].id); |
| 398 |
| 399 // Remove a source [3, 1, 2, 0]-->[1, 2, 0] |
| 400 tab_list_->RemoveSource(0); |
| 401 selected_index = [[browser selectedRowIndexes] firstIndex]; |
| 402 EXPECT_EQ(1, [[items objectAtIndex:selected_index] sourceID].id); |
| 403 |
| 404 // Change source type back and forth, browser should memorize the selection. |
| 405 ChangeType(DesktopMediaID::TYPE_SCREEN); |
| 406 ChangeType(DesktopMediaID::TYPE_WEB_CONTENTS); |
| 407 selected_index = [[browser selectedRowIndexes] firstIndex]; |
| 408 EXPECT_EQ(1, [[items objectAtIndex:selected_index] sourceID].id); |
| 259 } | 409 } |
| OLD | NEW |