Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / login / login_prompt_test_utils.cc
blobdfd1fccff272d9af2c506f66b84e51f66cc464b5
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 #include "chrome/browser/ui/login/login_prompt_test_utils.h"
7 #include "chrome/browser/ui/login/login_prompt.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 LoginPromptBrowserTestObserver::LoginPromptBrowserTestObserver()
11 : auth_needed_count_(0), auth_supplied_count_(0), auth_cancelled_count_(0) {
14 LoginPromptBrowserTestObserver::~LoginPromptBrowserTestObserver() {
17 void LoginPromptBrowserTestObserver::Observe(
18 int type,
19 const content::NotificationSource& source,
20 const content::NotificationDetails& details) {
21 if (type == chrome::NOTIFICATION_AUTH_NEEDED) {
22 AddHandler(content::Details<LoginNotificationDetails>(details)->handler());
23 auth_needed_count_++;
24 } else if (type == chrome::NOTIFICATION_AUTH_SUPPLIED) {
25 RemoveHandler(content::Details<AuthSuppliedLoginNotificationDetails>(
26 details)->handler());
27 auth_supplied_count_++;
28 } else if (type == chrome::NOTIFICATION_AUTH_CANCELLED) {
29 RemoveHandler(
30 content::Details<LoginNotificationDetails>(details)->handler());
31 auth_cancelled_count_++;
35 void LoginPromptBrowserTestObserver::AddHandler(LoginHandler* handler) {
36 std::list<LoginHandler*>::iterator i =
37 std::find(handlers_.begin(), handlers_.end(), handler);
38 // Cannot use ASSERT_EQ, because gTest on Android confuses iterators with
39 // containers.
40 ASSERT_TRUE(i == handlers_.end());
41 handlers_.push_back(handler);
44 void LoginPromptBrowserTestObserver::RemoveHandler(LoginHandler* handler) {
45 std::list<LoginHandler*>::iterator i =
46 std::find(handlers_.begin(), handlers_.end(), handler);
47 // Cannot use ASSERT_NE, because gTest on Android confuses iterators with
48 // containers.
49 ASSERT_TRUE(i != handlers_.end());
50 handlers_.erase(i);
53 void LoginPromptBrowserTestObserver::Register(
54 const content::NotificationSource& source) {
55 registrar_.Add(this, chrome::NOTIFICATION_AUTH_NEEDED, source);
56 registrar_.Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED, source);
57 registrar_.Add(this, chrome::NOTIFICATION_AUTH_CANCELLED, source);
60 WindowedLoadStopObserver::WindowedLoadStopObserver(
61 content::NavigationController* controller,
62 int notification_count)
63 : WindowedNavigationObserver<content::NOTIFICATION_LOAD_STOP>(controller),
64 remaining_notification_count_(notification_count) {
65 // This should really be an ASSERT, if those were allowed in a method which
66 // does not return void.
67 EXPECT_LE(0, remaining_notification_count_);
70 void WindowedLoadStopObserver::Observe(
71 int type,
72 const content::NotificationSource& source,
73 const content::NotificationDetails& details) {
74 ASSERT_LT(0, remaining_notification_count_);
75 if (--remaining_notification_count_ == 0)
76 WindowedNotificationObserver::Observe(type, source, details);