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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.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 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
13 #include "testing/gtest_mac.h" | 14 #include "testing/gtest_mac.h" |
14 | 15 |
15 @interface DesktopMediaPickerController (ExposedForTesting) | 16 @interface DesktopMediaPickerController (ExposedForTesting) |
16 - (IKImageBrowserView*)sourceBrowser; | 17 - (IKImageBrowserView*)sourceBrowser; |
17 - (NSButton*)okButton; | 18 - (NSButton*)okButton; |
18 - (NSArray*)items; | 19 - (NSArray*)items; |
19 @end | 20 @end |
20 | 21 |
21 @implementation DesktopMediaPickerController (ExposedForTesting) | 22 @implementation DesktopMediaPickerController (ExposedForTesting) |
22 - (IKImageBrowserView*)sourceBrowser { | 23 - (IKImageBrowserView*)sourceBrowser { |
23 return sourceBrowser_; | 24 return sourceBrowser_; |
24 } | 25 } |
25 | 26 |
26 - (NSButton*)okButton { | 27 - (NSButton*)okButton { |
27 return okButton_; | 28 return okButton_; |
28 } | 29 } |
29 | 30 |
30 - (NSButton*)cancelButton { | 31 - (NSButton*)cancelButton { |
31 return cancelButton_; | 32 return cancelButton_; |
32 } | 33 } |
33 | 34 |
34 - (NSArray*)items { | 35 - (NSArray*)items { |
35 return items_; | 36 return items_; |
36 } | 37 } |
37 @end | 38 @end |
38 | 39 |
39 class FakeDesktopMediaList : public DesktopMediaList { | |
40 public: | |
41 FakeDesktopMediaList() : observer_(NULL) { | |
42 } | |
43 | |
44 void AddSource(int id) { | |
45 Source source; | |
46 source.id = | |
47 content::DesktopMediaID(content::DesktopMediaID::TYPE_WINDOW, id); | |
48 source.name = base::Int64ToString16(id); | |
49 | |
50 sources_.push_back(source); | |
51 observer_->OnSourceAdded(sources_.size() - 1); | |
52 } | |
53 | |
54 void RemoveSource(int index) { | |
55 sources_.erase(sources_.begin() + index); | |
56 observer_->OnSourceRemoved(sources_.size() - 1); | |
57 } | |
58 | |
59 void SetSourceThumbnail(int index) { | |
60 sources_[index].thumbnail = thumbnail_; | |
61 observer_->OnSourceThumbnailChanged(index); | |
62 } | |
63 | |
64 void SetSourceName(int index, string16 name) { | |
65 sources_[index].name = name; | |
66 observer_->OnSourceNameChanged(index); | |
67 } | |
68 | |
69 // DesktopMediaList implementation: | |
70 virtual void SetUpdatePeriod(base::TimeDelta period) OVERRIDE { | |
71 } | |
72 | |
73 virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) OVERRIDE { | |
74 } | |
75 | |
76 virtual void SetViewDialogWindowId( | |
77 content::DesktopMediaID::Id dialog_id) OVERRIDE { | |
78 } | |
79 | |
80 virtual void StartUpdating(DesktopMediaListObserver* observer) OVERRIDE { | |
81 observer_ = observer; | |
82 | |
83 SkBitmap bitmap; | |
84 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 150, 150); | |
85 bitmap.allocPixels(); | |
86 bitmap.eraseRGB(0, 255, 0); | |
87 thumbnail_ = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
88 } | |
89 | |
90 virtual int GetSourceCount() const OVERRIDE { | |
91 return sources_.size(); | |
92 } | |
93 | |
94 virtual const Source& GetSource(int index) const OVERRIDE { | |
95 return sources_[index]; | |
96 } | |
97 | |
98 private: | |
99 std::vector<Source> sources_; | |
100 DesktopMediaListObserver* observer_; | |
101 gfx::ImageSkia thumbnail_; | |
102 }; | |
103 | |
104 class DesktopMediaPickerControllerTest : public CocoaTest { | 40 class DesktopMediaPickerControllerTest : public CocoaTest { |
105 public: | 41 public: |
106 DesktopMediaPickerControllerTest() | 42 DesktopMediaPickerControllerTest() |
107 : callback_called_(false), media_list_(NULL) { | 43 : callback_called_(false), media_list_(NULL) { |
108 } | 44 } |
109 | 45 |
110 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
111 CocoaTest::SetUp(); | 47 CocoaTest::SetUp(); |
112 | 48 |
113 media_list_ = new FakeDesktopMediaList(); | 49 media_list_ = new FakeDesktopMediaList(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 184 |
249 media_list_->AddSource(0); | 185 media_list_->AddSource(0); |
250 media_list_->AddSource(1); | 186 media_list_->AddSource(1); |
251 media_list_->AddSource(2); | 187 media_list_->AddSource(2); |
252 media_list_->SetSourceName(1, ASCIIToUTF16("foo")); | 188 media_list_->SetSourceName(1, ASCIIToUTF16("foo")); |
253 | 189 |
254 NSArray* items = [controller_ items]; | 190 NSArray* items = [controller_ items]; |
255 EXPECT_EQ(3U, [items count]); | 191 EXPECT_EQ(3U, [items count]); |
256 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); | 192 EXPECT_NSEQ(@"foo", [[items objectAtIndex:1] imageTitle]); |
257 } | 193 } |
OLD | NEW |