summaryrefslogtreecommitdiffstats
path: root/components/test_runner/mock_color_chooser.cc
blob: 55d586b3580f82a2fe62b5df7eeaf8d4e89c965d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/test_runner/mock_color_chooser.h"

#include "components/test_runner/web_test_delegate.h"
#include "components/test_runner/web_test_proxy.h"

namespace test_runner {

namespace {
class HostMethodTask : public WebMethodTask<MockColorChooser> {
 public:
  typedef void (MockColorChooser::*CallbackMethodType)();
  HostMethodTask(MockColorChooser* object, CallbackMethodType callback)
      : WebMethodTask<MockColorChooser>(object),
        callback_(callback) {}

  void RunIfValid() override { (object_->*callback_)(); }

 private:
  CallbackMethodType callback_;
};

} // namespace

MockColorChooser::MockColorChooser(blink::WebColorChooserClient* client,
                                   WebTestDelegate* delegate,
                                   WebTestProxyBase* proxy)
    : client_(client),
      delegate_(delegate),
      proxy_(proxy) {
  proxy_->DidOpenChooser();
}

MockColorChooser::~MockColorChooser() {
  proxy_->DidCloseChooser();
}

void MockColorChooser::setSelectedColor(const blink::WebColor color) {}

void MockColorChooser::endChooser() {
  delegate_->PostDelayedTask(
      new HostMethodTask(this, &MockColorChooser::InvokeDidEndChooser), 0);
}

void MockColorChooser::InvokeDidEndChooser() {
  client_->didEndChooser();
}

}  // namespace test_runner