Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / login / login_prompt_test_utils.h
blob224ea6e5337dd08d887ec150cf4254f70e2e9266
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_TEST_UTILS_H_
6 #define CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_TEST_UTILS_H_
8 #include <list>
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/test/test_utils.h"
15 class LoginHandler;
17 // Maintains a set of LoginHandlers that are currently active and
18 // keeps a count of the notifications that were observed.
19 class LoginPromptBrowserTestObserver : public content::NotificationObserver {
20 public:
21 LoginPromptBrowserTestObserver();
22 ~LoginPromptBrowserTestObserver() override;
24 void Observe(int type,
25 const content::NotificationSource& source,
26 const content::NotificationDetails& details) override;
28 void AddHandler(LoginHandler* handler);
30 void RemoveHandler(LoginHandler* handler);
32 void Register(const content::NotificationSource& source);
34 const std::list<LoginHandler*>& handlers() const { return handlers_; }
36 int auth_needed_count() const { return auth_needed_count_; }
37 int auth_supplied_count() const { return auth_supplied_count_; }
38 int auth_cancelled_count() const { return auth_cancelled_count_; }
40 private:
41 std::list<LoginHandler*> handlers_;
43 // The exact number of notifications we receive is depedent on the
44 // number of requests that were dispatched and is subject to a
45 // number of factors that we don't directly control here. The
46 // values below should only be used qualitatively.
47 int auth_needed_count_;
48 int auth_supplied_count_;
49 int auth_cancelled_count_;
51 private:
52 content::NotificationRegistrar registrar_;
54 DISALLOW_COPY_AND_ASSIGN(LoginPromptBrowserTestObserver);
57 template <int T>
58 class WindowedNavigationObserver
59 : public content::WindowedNotificationObserver {
60 public:
61 explicit WindowedNavigationObserver(
62 content::NavigationController* controller);
64 private:
65 DISALLOW_COPY_AND_ASSIGN(WindowedNavigationObserver);
68 template <int T>
69 WindowedNavigationObserver<T>::WindowedNavigationObserver(
70 content::NavigationController* controller)
71 : content::WindowedNotificationObserver(
72 T, content::Source<content::NavigationController>(controller)) {
75 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_NEEDED>
76 WindowedAuthNeededObserver;
78 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_CANCELLED>
79 WindowedAuthCancelledObserver;
81 typedef WindowedNavigationObserver<chrome::NOTIFICATION_AUTH_SUPPLIED>
82 WindowedAuthSuppliedObserver;
84 // LOAD_STOP observer is special since we want to be able to wait for
85 // multiple LOAD_STOP events.
86 class WindowedLoadStopObserver
87 : public WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP> {
88 public:
89 WindowedLoadStopObserver(content::NavigationController* controller,
90 int notification_count);
92 protected:
93 void Observe(int type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) override;
97 private:
98 int remaining_notification_count_; // Number of notifications remaining.
100 DISALLOW_COPY_AND_ASSIGN(WindowedLoadStopObserver);
103 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_TEST_UTILS_H_