summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/notification_presenter.h
blob: f5b3b07127e9511777efb1034f6a297f6e6dc1b3 (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
// Copyright (c) 2010 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.

#ifndef WEBKIT_TOOLS_TEST_SHELL_NOTIFICATION_PRESENTER_H_
#define WEBKIT_TOOLS_TEST_SHELL_NOTIFICATION_PRESENTER_H_

#include <map>
#include <set>
#include <string>

#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
#include "webkit/tools/test_shell/test_shell.h"

// A class that implements NotificationPresenter for the test shell.
class TestNotificationPresenter : public WebKit::WebNotificationPresenter {
 public:
  explicit TestNotificationPresenter(TestShell* shell)
      : shell_(shell) {
  }

  // Called by the LayoutTestController to simulate a user granting
  // permission.
  void grantPermission(const std::string& origin);

  // WebKit::WebNotificationPresenter interface
  virtual bool show(const WebKit::WebNotification&);
  virtual void cancel(const WebKit::WebNotification&);
  virtual void objectDestroyed(const WebKit::WebNotification&);
  virtual Permission checkPermission(const WebKit::WebURL& url);
  virtual void requestPermission(const WebKit::WebSecurityOrigin& origin,
      WebKit::WebNotificationPermissionCallback* callback);

  void Reset() {
    allowed_origins_.clear();
  }

 private:
  // Non-owned pointer.  The NotificationPresenter is owned by the test shell.
  TestShell* shell_;

  // List of allowed origins.
  std::set<std::string> allowed_origins_;

  // Map of active replacement IDs to the titles of those notifications
  std::map<std::string, std::string> replacements_;
};

#endif  // WEBKIT_TOOLS_TEST_SHELL_NOTIFICATION_PRESENTER_H_