Chromium Code Reviews| 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" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 } | 38 } |
| 39 | 39 |
| 40 - (NSArray*)items { | 40 - (NSArray*)items { |
| 41 return items_; | 41 return items_; |
| 42 } | 42 } |
| 43 @end | 43 @end |
| 44 | 44 |
| 45 class DesktopMediaPickerControllerTest : public CocoaTest { | 45 class DesktopMediaPickerControllerTest : public CocoaTest { |
| 46 public: | 46 public: |
| 47 DesktopMediaPickerControllerTest() | 47 DesktopMediaPickerControllerTest() |
| 48 : callback_called_(false), media_list_(NULL) { | 48 : callback_called_(false), |
| 49 } | 49 screen_list_(nullptr), |
| 50 window_list_(nullptr), | |
| 51 tab_list_(nullptr) {} | |
|
Sergey Ulanov
2016/04/14 22:39:52
Add initializers where these members are defined.
qiangchen
2016/04/15 19:33:30
Done.
| |
| 50 | 52 |
| 51 void SetUp() override { | 53 void SetUp() override { |
| 52 CocoaTest::SetUp(); | 54 CocoaTest::SetUp(); |
| 53 | 55 |
| 54 media_list_ = new FakeDesktopMediaList(); | 56 screen_list_ = new FakeDesktopMediaList(); |
| 57 window_list_ = new FakeDesktopMediaList(); | |
| 58 tab_list_ = new FakeDesktopMediaList(); | |
| 55 | 59 |
| 56 DesktopMediaPicker::DoneCallback callback = | 60 DesktopMediaPicker::DoneCallback callback = |
| 57 base::Bind(&DesktopMediaPickerControllerTest::OnResult, | 61 base::Bind(&DesktopMediaPickerControllerTest::OnResult, |
| 58 base::Unretained(this)); | 62 base::Unretained(this)); |
| 59 | 63 |
| 60 controller_.reset([[DesktopMediaPickerController alloc] | 64 controller_.reset([[DesktopMediaPickerController alloc] |
| 61 initWithMediaList:std::unique_ptr<DesktopMediaList>(media_list_) | 65 initWithScreenList:std::unique_ptr<DesktopMediaList>(screen_list_) |
| 62 parent:nil | 66 windowList:std::unique_ptr<DesktopMediaList>(window_list_) |
| 63 callback:callback | 67 tabList:std::unique_ptr<DesktopMediaList>(tab_list_) |
| 64 appName:base::ASCIIToUTF16("Screenshare Test") | 68 parent:nil |
| 65 targetName:base::ASCIIToUTF16("https://foo.com") | 69 callback:callback |
| 66 requestAudio:true]); | 70 appName:base::ASCIIToUTF16("Screenshare Test") |
| 71 targetName:base::ASCIIToUTF16("https://foo.com") | |
| 72 requestAudio:true]); | |
| 67 } | 73 } |
| 68 | 74 |
| 69 void TearDown() override { | 75 void TearDown() override { |
| 70 controller_.reset(); | 76 controller_.reset(); |
| 71 CocoaTest::TearDown(); | 77 CocoaTest::TearDown(); |
| 72 } | 78 } |
| 73 | 79 |
| 74 bool WaitForCallback() { | 80 bool WaitForCallback() { |
| 75 if (!callback_called_) { | 81 if (!callback_called_) { |
| 76 base::RunLoop().RunUntilIdle(); | 82 base::RunLoop().RunUntilIdle(); |
| 77 } | 83 } |
| 78 return callback_called_; | 84 return callback_called_; |
| 79 } | 85 } |
| 80 | 86 |
| 81 protected: | 87 protected: |
| 82 void OnResult(content::DesktopMediaID source) { | 88 void OnResult(content::DesktopMediaID source) { |
| 83 EXPECT_FALSE(callback_called_); | 89 EXPECT_FALSE(callback_called_); |
| 84 callback_called_ = true; | 90 callback_called_ = true; |
| 85 source_reported_ = source; | 91 source_reported_ = source; |
| 86 } | 92 } |
| 87 | 93 |
| 88 content::TestBrowserThreadBundle thread_bundle_; | 94 content::TestBrowserThreadBundle thread_bundle_; |
| 89 bool callback_called_; | 95 bool callback_called_; |
|
Sergey Ulanov
2016/04/14 22:39:52
= false;
qiangchen
2016/04/15 19:33:30
Done.
| |
| 90 content::DesktopMediaID source_reported_; | 96 content::DesktopMediaID source_reported_; |
| 91 FakeDesktopMediaList* media_list_; | 97 FakeDesktopMediaList* screen_list_; |
|
Sergey Ulanov
2016/04/14 22:39:52
= nullptr;
qiangchen
2016/04/15 19:33:30
Done.
| |
| 98 FakeDesktopMediaList* window_list_; | |
| 99 FakeDesktopMediaList* tab_list_; | |
| 92 base::scoped_nsobject<DesktopMediaPickerController> controller_; | 100 base::scoped_nsobject<DesktopMediaPickerController> controller_; |
| 93 }; | 101 }; |
| 94 | 102 |
| 95 TEST_F(DesktopMediaPickerControllerTest, ShowAndDismiss) { | 103 TEST_F(DesktopMediaPickerControllerTest, ShowAndDismiss) { |
| 96 [controller_ showWindow:nil]; | 104 [controller_ showWindow:nil]; |
| 97 | 105 |
| 98 media_list_->AddSource(0); | 106 window_list_->AddSource(0); |
| 99 media_list_->AddSource(1); | 107 window_list_->AddSource(1); |
| 100 media_list_->SetSourceThumbnail(1); | 108 window_list_->SetSourceThumbnail(1); |
| 101 | 109 |
| 102 NSArray* items = [controller_ items]; | 110 NSArray* items = [controller_ items]; |
| 103 EXPECT_EQ(2U, [items count]); | 111 EXPECT_EQ(2U, [items count]); |
| 104 EXPECT_NSEQ(@"0", [[items objectAtIndex:0] imageTitle]); | 112 EXPECT_NSEQ(@"0", [[items objectAtIndex:0] imageTitle]); |
| 105 EXPECT_EQ(nil, [[items objectAtIndex:0] imageRepresentation]); | 113 EXPECT_EQ(nil, [[items objectAtIndex:0] imageRepresentation]); |
| 106 EXPECT_NSEQ(@"1", [[items objectAtIndex:1] imageTitle]); | 114 EXPECT_NSEQ(@"1", [[items objectAtIndex:1] imageTitle]); |
| 107 EXPECT_TRUE([[items objectAtIndex:1] imageRepresentation] != nil); | 115 EXPECT_TRUE([[items objectAtIndex:1] imageRepresentation] != nil); |
| 108 } | 116 } |
| 109 | 117 |
| 110 TEST_F(DesktopMediaPickerControllerTest, ClickShare) { | 118 TEST_F(DesktopMediaPickerControllerTest, ClickShare) { |
| 111 [controller_ showWindow:nil]; | 119 [controller_ showWindow:nil]; |
| 112 | 120 |
| 113 media_list_->AddSource(0); | 121 window_list_->AddSource(0); |
| 114 media_list_->SetSourceThumbnail(0); | 122 window_list_->SetSourceThumbnail(0); |
| 115 media_list_->AddSource(1); | 123 window_list_->AddSource(1); |
| 116 media_list_->SetSourceThumbnail(1); | 124 window_list_->SetSourceThumbnail(1); |
| 117 | 125 |
| 118 EXPECT_EQ(2U, [[controller_ items] count]); | 126 EXPECT_EQ(2U, [[controller_ items] count]); |
| 119 EXPECT_FALSE([[controller_ shareButton] isEnabled]); | 127 EXPECT_FALSE([[controller_ shareButton] isEnabled]); |
| 120 | 128 |
| 121 NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:1]; | 129 NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:1]; |
| 122 [[controller_ sourceBrowser] setSelectionIndexes:indexSet | 130 [[controller_ sourceBrowser] setSelectionIndexes:indexSet |
| 123 byExtendingSelection:NO]; | 131 byExtendingSelection:NO]; |
| 124 EXPECT_TRUE([[controller_ shareButton] isEnabled]); | 132 EXPECT_TRUE([[controller_ shareButton] isEnabled]); |
| 125 | 133 |
| 126 [[controller_ shareButton] performClick:nil]; | 134 [[controller_ shareButton] performClick:nil]; |
| 127 EXPECT_TRUE(WaitForCallback()); | 135 EXPECT_TRUE(WaitForCallback()); |
| 128 EXPECT_EQ(media_list_->GetSource(1).id, source_reported_); | 136 EXPECT_EQ(window_list_->GetSource(1).id, source_reported_); |
| 129 } | 137 } |
| 130 | 138 |
| 131 TEST_F(DesktopMediaPickerControllerTest, ClickCancel) { | 139 TEST_F(DesktopMediaPickerControllerTest, ClickCancel) { |
| 132 [controller_ showWindow:nil]; | 140 [controller_ showWindow:nil]; |
| 133 | 141 |
| 134 media_list_->AddSource(0); | 142 window_list_->AddSource(0); |
| 135 media_list_->SetSourceThumbnail(0); | 143 window_list_->SetSourceThumbnail(0); |
| 136 media_list_->AddSource(1); | 144 window_list_->AddSource(1); |
| 137 media_list_->SetSourceThumbnail(1); | 145 window_list_->SetSourceThumbnail(1); |
| 138 | 146 |
| 139 [[controller_ cancelButton] performClick:nil]; | 147 [[controller_ cancelButton] performClick:nil]; |
| 140 EXPECT_TRUE(WaitForCallback()); | 148 EXPECT_TRUE(WaitForCallback()); |
| 141 EXPECT_EQ(content::DesktopMediaID(), source_reported_); | 149 EXPECT_EQ(content::DesktopMediaID(), source_reported_); |
| 142 } | 150 } |
| 143 | 151 |
| 144 TEST_F(DesktopMediaPickerControllerTest, CloseWindow) { | 152 TEST_F(DesktopMediaPickerControllerTest, CloseWindow) { |
| 145 [controller_ showWindow:nil]; | 153 [controller_ showWindow:nil]; |
| 146 | 154 |
| 147 media_list_->AddSource(0); | 155 window_list_->AddSource(0); |
| 148 media_list_->SetSourceThumbnail(0); | 156 window_list_->SetSourceThumbnail(0); |
| 149 media_list_->AddSource(1); | 157 window_list_->AddSource(1); |
| 150 media_list_->SetSourceThumbnail(1); | 158 window_list_->SetSourceThumbnail(1); |
| 151 | 159 |
| 152 [controller_ close]; | 160 [controller_ close]; |
| 153 EXPECT_TRUE(WaitForCallback()); | 161 EXPECT_TRUE(WaitForCallback()); |
| 154 EXPECT_EQ(content::DesktopMediaID(), source_reported_); | 162 EXPECT_EQ(content::DesktopMediaID(), source_reported_); |
| 155 } | 163 } |
| 156 | 164 |
| 157 TEST_F(DesktopMediaPickerControllerTest, UpdateThumbnail) { | 165 TEST_F(DesktopMediaPickerControllerTest, UpdateThumbnail) { |
| 158 [controller_ showWindow:nil]; | 166 [controller_ showWindow:nil]; |
| 159 | 167 |
| 160 media_list_->AddSource(0); | 168 window_list_->AddSource(0); |
| 161 media_list_->SetSourceThumbnail(0); | 169 window_list_->SetSourceThumbnail(0); |
| 162 media_list_->AddSource(1); | 170 window_list_->AddSource(1); |
| 163 media_list_->SetSourceThumbnail(1); | 171 window_list_->SetSourceThumbnail(1); |
| 164 | 172 |
| 165 NSArray* items = [controller_ items]; | 173 NSArray* items = [controller_ items]; |
| 166 EXPECT_EQ(2U, [items count]); | 174 EXPECT_EQ(2U, [items count]); |
| 167 NSUInteger version = [[items objectAtIndex:0] imageVersion]; | 175 NSUInteger version = [[items objectAtIndex:0] imageVersion]; |
| 168 | 176 |
| 169 media_list_->SetSourceThumbnail(0); | 177 window_list_->SetSourceThumbnail(0); |
| 170 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); | 178 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); |
| 171 } | 179 } |
| 172 | 180 |
| 173 TEST_F(DesktopMediaPickerControllerTest, UpdateName) { | 181 TEST_F(DesktopMediaPickerControllerTest, UpdateName) { |
| 174 [controller_ showWindow:nil]; | 182 [controller_ showWindow:nil]; |
| 175 | 183 |
| 176 media_list_->AddSource(0); | 184 window_list_->AddSource(0); |
| 177 media_list_->SetSourceThumbnail(0); | 185 window_list_->SetSourceThumbnail(0); |
| 178 media_list_->AddSource(1); | 186 window_list_->AddSource(1); |
| 179 media_list_->SetSourceThumbnail(1); | 187 window_list_->SetSourceThumbnail(1); |
| 180 | 188 |
| 181 NSArray* items = [controller_ items]; | 189 NSArray* items = [controller_ items]; |
| 182 EXPECT_EQ(2U, [items count]); | 190 EXPECT_EQ(2U, [items count]); |
| 183 NSUInteger version = [[items objectAtIndex:0] imageVersion]; | 191 NSUInteger version = [[items objectAtIndex:0] imageVersion]; |
| 184 | 192 |
| 185 media_list_->SetSourceThumbnail(0); | 193 window_list_->SetSourceThumbnail(0); |
| 186 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); | 194 EXPECT_NE(version, [[items objectAtIndex:0] imageVersion]); |
| 187 } | 195 } |
| 188 | 196 |
| 189 TEST_F(DesktopMediaPickerControllerTest, RemoveSource) { | 197 TEST_F(DesktopMediaPickerControllerTest, RemoveSource) { |
| 190 [controller_ showWindow:nil]; | 198 [controller_ showWindow:nil]; |
| 191 | 199 |
| 192 media_list_->AddSource(0); | 200 window_list_->AddSource(0); |
| 193 media_list_->AddSource(1); | 201 window_list_->AddSource(1); |
| 194 media_list_->AddSource(2); | 202 window_list_->AddSource(2); |
| 195 media_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); | 203 window_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); |
| 196 | 204 |
| 197 NSArray* items = [controller_ items]; | 205 NSArray* items = [controller_ items]; |
| 198 EXPECT_EQ(3U, [items count]); | 206 EXPECT_EQ(3U, [items count]); |
| 199 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); | 207 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); |
| 200 } | 208 } |
| 201 | 209 |
| 202 TEST_F(DesktopMediaPickerControllerTest, MoveSource) { | 210 TEST_F(DesktopMediaPickerControllerTest, MoveSource) { |
| 203 [controller_ showWindow:nil]; | 211 [controller_ showWindow:nil]; |
| 204 | 212 |
| 205 media_list_->AddSource(0); | 213 window_list_->AddSource(0); |
| 206 media_list_->AddSource(1); | 214 window_list_->AddSource(1); |
| 207 media_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); | 215 window_list_->SetSourceName(1, base::ASCIIToUTF16("foo")); |
| 208 NSArray* items = [controller_ items]; | 216 NSArray* items = [controller_ items]; |
| 209 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); | 217 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); |
| 210 | 218 |
| 211 media_list_->MoveSource(1, 0); | 219 window_list_->MoveSource(1, 0); |
| 212 EXPECT_NSEQ(@"foo", [[items objectAtIndex:0] imageTitle]); | 220 EXPECT_NSEQ(@"foo", [[items objectAtIndex:0] imageTitle]); |
| 213 | 221 |
| 214 media_list_->MoveSource(0, 1); | 222 window_list_->MoveSource(0, 1); |
| 215 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); | 223 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); |
| 216 } | 224 } |
| 217 | 225 |
| 218 // Make sure the audio share checkbox' state reacts correctly with | 226 // Make sure the audio share checkbox' state reacts correctly with |
| 219 // the source selection. Namely the checkbox is enabled only for tab | 227 // the source selection. Namely the checkbox is enabled only for tab |
| 220 // sharing on Mac. | 228 // sharing on Mac. |
| 221 TEST_F(DesktopMediaPickerControllerTest, AudioShareCheckboxState) { | 229 TEST_F(DesktopMediaPickerControllerTest, AudioShareCheckboxState) { |
| 222 [controller_ showWindow:nil]; | 230 [controller_ showWindow:nil]; |
| 223 | 231 |
| 224 media_list_->AddSourceByFullMediaID( | 232 screen_list_->AddSourceByFullMediaID( |
| 225 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, 0)); | 233 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, 0)); |
| 226 media_list_->AddSourceByFullMediaID( | 234 window_list_->AddSourceByFullMediaID( |
| 227 content::DesktopMediaID(content::DesktopMediaID::TYPE_WINDOW, 1)); | 235 content::DesktopMediaID(content::DesktopMediaID::TYPE_WINDOW, 1)); |
| 228 media_list_->AddSourceByFullMediaID( | 236 tab_list_->AddSourceByFullMediaID( |
| 229 content::DesktopMediaID(content::DesktopMediaID::TYPE_WEB_CONTENTS, 2)); | 237 content::DesktopMediaID(content::DesktopMediaID::TYPE_WEB_CONTENTS, 2)); |
| 230 | 238 |
| 231 NSButton* checkbox = [controller_ audioShareCheckbox]; | 239 NSButton* checkbox = [controller_ audioShareCheckbox]; |
| 232 EXPECT_EQ(NO, [checkbox isEnabled]); | 240 EXPECT_EQ(NO, [checkbox isEnabled]); |
| 233 | 241 |
| 234 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:0]; | 242 NSIndexSet* index_set = [NSIndexSet indexSetWithIndex:0]; |
| 235 [checkbox setEnabled:YES]; | 243 [checkbox setEnabled:YES]; |
| 236 [[controller_ sourceBrowser] setSelectionIndexes:index_set | 244 [[controller_ sourceBrowser] setSelectionIndexes:index_set |
| 237 byExtendingSelection:NO]; | 245 byExtendingSelection:NO]; |
| 238 EXPECT_EQ(NO, [checkbox isEnabled]); | 246 EXPECT_EQ(NO, [checkbox isEnabled]); |
| 239 | 247 |
| 240 index_set = [NSIndexSet indexSetWithIndex:1]; | 248 index_set = [NSIndexSet indexSetWithIndex:1]; |
| 241 [checkbox setEnabled:YES]; | 249 [checkbox setEnabled:YES]; |
| 242 [[controller_ sourceBrowser] setSelectionIndexes:index_set | 250 [[controller_ sourceBrowser] setSelectionIndexes:index_set |
| 243 byExtendingSelection:NO]; | 251 byExtendingSelection:NO]; |
| 244 EXPECT_EQ(NO, [checkbox isEnabled]); | 252 EXPECT_EQ(NO, [checkbox isEnabled]); |
| 245 | 253 |
| 246 index_set = [NSIndexSet indexSetWithIndex:2]; | 254 index_set = [NSIndexSet indexSetWithIndex:2]; |
| 247 [[controller_ sourceBrowser] setSelectionIndexes:index_set | 255 [[controller_ sourceBrowser] setSelectionIndexes:index_set |
| 248 byExtendingSelection:NO]; | 256 byExtendingSelection:NO]; |
| 249 EXPECT_EQ(YES, [checkbox isEnabled]); | 257 EXPECT_EQ(YES, [checkbox isEnabled]); |
| 250 | 258 |
| 251 index_set = [NSIndexSet indexSet]; | 259 index_set = [NSIndexSet indexSet]; |
| 252 [[controller_ sourceBrowser] setSelectionIndexes:index_set | 260 [[controller_ sourceBrowser] setSelectionIndexes:index_set |
| 253 byExtendingSelection:NO]; | 261 byExtendingSelection:NO]; |
| 254 EXPECT_EQ(NO, [checkbox isEnabled]); | 262 EXPECT_EQ(NO, [checkbox isEnabled]); |
| 255 } | 263 } |
| OLD | NEW |