| 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 #include <queue> | 5 #include <queue> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_api.h" | 10 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_api.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 bool picker_deleted; | 35 bool picker_deleted; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 class FakeDesktopMediaPicker : public DesktopMediaPicker { | 38 class FakeDesktopMediaPicker : public DesktopMediaPicker { |
| 39 public: | 39 public: |
| 40 explicit FakeDesktopMediaPicker(TestFlags* expectation) | 40 explicit FakeDesktopMediaPicker(TestFlags* expectation) |
| 41 : expectation_(expectation), | 41 : expectation_(expectation), |
| 42 weak_factory_(this) { | 42 weak_factory_(this) { |
| 43 expectation_->picker_created = true; | 43 expectation_->picker_created = true; |
| 44 } | 44 } |
| 45 virtual ~FakeDesktopMediaPicker() { | 45 ~FakeDesktopMediaPicker() override { expectation_->picker_deleted = true; } |
| 46 expectation_->picker_deleted = true; | |
| 47 } | |
| 48 | 46 |
| 49 // DesktopMediaPicker interface. | 47 // DesktopMediaPicker interface. |
| 50 virtual void Show(content::WebContents* web_contents, | 48 void Show(content::WebContents* web_contents, |
| 51 gfx::NativeWindow context, | 49 gfx::NativeWindow context, |
| 52 gfx::NativeWindow parent, | 50 gfx::NativeWindow parent, |
| 53 const base::string16& app_name, | 51 const base::string16& app_name, |
| 54 const base::string16& target_name, | 52 const base::string16& target_name, |
| 55 scoped_ptr<DesktopMediaList> model, | 53 scoped_ptr<DesktopMediaList> model, |
| 56 const DoneCallback& done_callback) override { | 54 const DoneCallback& done_callback) override { |
| 57 if (!expectation_->cancelled) { | 55 if (!expectation_->cancelled) { |
| 58 // Post a task to call the callback asynchronously. | 56 // Post a task to call the callback asynchronously. |
| 59 base::ThreadTaskRunnerHandle::Get()->PostTask( | 57 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 60 FROM_HERE, | 58 FROM_HERE, |
| 61 base::Bind(&FakeDesktopMediaPicker::CallCallback, | 59 base::Bind(&FakeDesktopMediaPicker::CallCallback, |
| 62 weak_factory_.GetWeakPtr(), done_callback)); | 60 weak_factory_.GetWeakPtr(), done_callback)); |
| 63 } else { | 61 } else { |
| 64 // If we expect the dialog to be cancelled then store the callback to | 62 // If we expect the dialog to be cancelled then store the callback to |
| 65 // retain reference to the callback handler. | 63 // retain reference to the callback handler. |
| 66 done_callback_ = done_callback; | 64 done_callback_ = done_callback; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 | 75 |
| 78 base::WeakPtrFactory<FakeDesktopMediaPicker> weak_factory_; | 76 base::WeakPtrFactory<FakeDesktopMediaPicker> weak_factory_; |
| 79 | 77 |
| 80 DISALLOW_COPY_AND_ASSIGN(FakeDesktopMediaPicker); | 78 DISALLOW_COPY_AND_ASSIGN(FakeDesktopMediaPicker); |
| 81 }; | 79 }; |
| 82 | 80 |
| 83 class FakeDesktopMediaPickerFactory : | 81 class FakeDesktopMediaPickerFactory : |
| 84 public DesktopCaptureChooseDesktopMediaFunction::PickerFactory { | 82 public DesktopCaptureChooseDesktopMediaFunction::PickerFactory { |
| 85 public: | 83 public: |
| 86 FakeDesktopMediaPickerFactory() {} | 84 FakeDesktopMediaPickerFactory() {} |
| 87 virtual ~FakeDesktopMediaPickerFactory() {} | 85 ~FakeDesktopMediaPickerFactory() override {} |
| 88 | 86 |
| 89 void SetTestFlags(TestFlags* test_flags, int tests_count) { | 87 void SetTestFlags(TestFlags* test_flags, int tests_count) { |
| 90 test_flags_ = test_flags; | 88 test_flags_ = test_flags; |
| 91 tests_count_ = tests_count; | 89 tests_count_ = tests_count; |
| 92 current_test_ = 0; | 90 current_test_ = 0; |
| 93 } | 91 } |
| 94 | 92 |
| 95 // DesktopCaptureChooseDesktopMediaFunction::PickerFactory interface. | 93 // DesktopCaptureChooseDesktopMediaFunction::PickerFactory interface. |
| 96 virtual scoped_ptr<DesktopMediaList> CreateModel( | 94 scoped_ptr<DesktopMediaList> CreateModel(bool show_screens, |
| 97 bool show_screens, | 95 bool show_windows) override { |
| 98 bool show_windows) override { | |
| 99 EXPECT_LE(current_test_, tests_count_); | 96 EXPECT_LE(current_test_, tests_count_); |
| 100 if (current_test_ >= tests_count_) | 97 if (current_test_ >= tests_count_) |
| 101 return scoped_ptr<DesktopMediaList>(); | 98 return scoped_ptr<DesktopMediaList>(); |
| 102 EXPECT_EQ(test_flags_[current_test_].expect_screens, show_screens); | 99 EXPECT_EQ(test_flags_[current_test_].expect_screens, show_screens); |
| 103 EXPECT_EQ(test_flags_[current_test_].expect_windows, show_windows); | 100 EXPECT_EQ(test_flags_[current_test_].expect_windows, show_windows); |
| 104 return scoped_ptr<DesktopMediaList>(new FakeDesktopMediaList()); | 101 return scoped_ptr<DesktopMediaList>(new FakeDesktopMediaList()); |
| 105 } | 102 } |
| 106 | 103 |
| 107 virtual scoped_ptr<DesktopMediaPicker> CreatePicker() override { | 104 scoped_ptr<DesktopMediaPicker> CreatePicker() override { |
| 108 EXPECT_LE(current_test_, tests_count_); | 105 EXPECT_LE(current_test_, tests_count_); |
| 109 if (current_test_ >= tests_count_) | 106 if (current_test_ >= tests_count_) |
| 110 return scoped_ptr<DesktopMediaPicker>(); | 107 return scoped_ptr<DesktopMediaPicker>(); |
| 111 ++current_test_; | 108 ++current_test_; |
| 112 return scoped_ptr<DesktopMediaPicker>( | 109 return scoped_ptr<DesktopMediaPicker>( |
| 113 new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1)); | 110 new FakeDesktopMediaPicker(test_flags_ + current_test_ - 1)); |
| 114 } | 111 } |
| 115 | 112 |
| 116 private: | 113 private: |
| 117 TestFlags* test_flags_; | 114 TestFlags* test_flags_; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 EXPECT_TRUE(result); | 231 EXPECT_TRUE(result); |
| 235 EXPECT_TRUE(test_flags[2].picker_created); | 232 EXPECT_TRUE(test_flags[2].picker_created); |
| 236 EXPECT_FALSE(test_flags[2].picker_deleted); | 233 EXPECT_FALSE(test_flags[2].picker_deleted); |
| 237 | 234 |
| 238 web_contents->Close(); | 235 web_contents->Close(); |
| 239 destroyed_watcher.Wait(); | 236 destroyed_watcher.Wait(); |
| 240 EXPECT_TRUE(test_flags[2].picker_deleted); | 237 EXPECT_TRUE(test_flags[2].picker_deleted); |
| 241 } | 238 } |
| 242 | 239 |
| 243 } // namespace extensions | 240 } // namespace extensions |
| OLD | NEW |