| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_TEST_RUNNER_MOCK_COLOR_CHOOSER_H_ | 5 #ifndef COMPONENTS_TEST_RUNNER_MOCK_COLOR_CHOOSER_H_ |
| 6 #define COMPONENTS_TEST_RUNNER_MOCK_COLOR_CHOOSER_H_ | 6 #define COMPONENTS_TEST_RUNNER_MOCK_COLOR_CHOOSER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "third_party/WebKit/public/web/WebColorChooser.h" | 10 #include "third_party/WebKit/public/web/WebColorChooser.h" |
| 11 #include "third_party/WebKit/public/web/WebColorChooserClient.h" | 11 #include "third_party/WebKit/public/web/WebColorChooserClient.h" |
| 12 | 12 |
| 13 namespace test_runner { | 13 namespace test_runner { |
| 14 | 14 |
| 15 class TestRunner; | 15 class TestRunner; |
| 16 class WebTestDelegate; | 16 class WebTestDelegate; |
| 17 | 17 |
| 18 class MockColorChooser : public blink::WebColorChooser { | 18 class MockColorChooser : public blink::WebColorChooser { |
| 19 public: | 19 public: |
| 20 // Caller has to guarantee that |client| and |delegate| are alive | 20 // Caller has to guarantee that |client| is alive until |
| 21 // until |WebColorChooserClient::didEndChooser| is called. | 21 // |WebColorChooserClient::didEndChooser| is called. |
| 22 // Caller has to guarantee that |test_runner| lives longer | 22 // Caller has to guarantee that |test_runner| lives longer |
| 23 // than MockColorChooser. | 23 // than MockColorChooser. |
| 24 MockColorChooser(blink::WebColorChooserClient* client, | 24 MockColorChooser(blink::WebColorChooserClient* client, |
| 25 WebTestDelegate* delegate, | 25 WebTestDelegate* delegate, |
| 26 TestRunner* test_runner); | 26 TestRunner* test_runner); |
| 27 ~MockColorChooser() override; | 27 ~MockColorChooser() override; |
| 28 | 28 |
| 29 // blink::WebColorChooser implementation. | 29 // blink::WebColorChooser implementation. |
| 30 void setSelectedColor(const blink::WebColor color) override; | 30 void setSelectedColor(const blink::WebColor color) override; |
| 31 void endChooser() override; | 31 void endChooser() override; |
| 32 | 32 |
| 33 void InvokeDidEndChooser(); | 33 void InvokeDidEndChooser(); |
| 34 // MockColorChooser is owned by ColorChooserUIController which is garbage |
| 35 // collected. That means this might be destroyed after WebTestDelegate is |
| 36 // destryed, so we use this to clear |delegate_|. |
| 37 void SetDelegate(WebTestDelegate*); |
| 34 | 38 |
| 35 private: | 39 private: |
| 36 blink::WebColorChooserClient* client_; | 40 blink::WebColorChooserClient* client_; |
| 37 WebTestDelegate* delegate_; | 41 WebTestDelegate* delegate_; |
| 38 TestRunner* test_runner_; | 42 TestRunner* test_runner_; |
| 39 | 43 |
| 40 base::WeakPtrFactory<MockColorChooser> weak_factory_; | 44 base::WeakPtrFactory<MockColorChooser> weak_factory_; |
| 41 | 45 |
| 42 DISALLOW_COPY_AND_ASSIGN(MockColorChooser); | 46 DISALLOW_COPY_AND_ASSIGN(MockColorChooser); |
| 43 }; | 47 }; |
| 44 | 48 |
| 45 } // namespace test_runner | 49 } // namespace test_runner |
| 46 | 50 |
| 47 #endif // COMPONENTS_TEST_RUNNER_MOCK_COLOR_CHOOSER_H_ | 51 #endif // COMPONENTS_TEST_RUNNER_MOCK_COLOR_CHOOSER_H_ |
| OLD | NEW |