Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Unified Diff: chrome/browser/ui/login/login_handler_browsertest.cc

Issue 2701473007: Switch WindowedNotificationObserver to use base::RunLoop. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/public/test/test_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/login/login_handler_browsertest.cc
diff --git a/chrome/browser/ui/login/login_handler_browsertest.cc b/chrome/browser/ui/login/login_handler_browsertest.cc
index d3e1ca5cc07fd9f8607d69f32eae961158b99615..46524439a74b89f1f95715f69987464331cf2b4c 100644
--- a/chrome/browser/ui/login/login_handler_browsertest.cc
+++ b/chrome/browser/ui/login/login_handler_browsertest.cc
@@ -98,6 +98,7 @@ const char kPrefetchAuthPage[] = "/login/prefetch.html";
const char kMultiRealmTestPage[] = "/login/multi_realm.html";
const int kMultiRealmTestRealmCount = 2;
+const int kMultiRealmTestAuthRequestsCount = 4;
const char kSingleRealmTestPage[] = "/login/single_realm.html";
@@ -475,36 +476,34 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmCancellation) {
WindowedLoadStopObserver load_stop_waiter(controller, 1);
- {
- WindowedAuthNeededObserver auth_needed_waiter(controller);
- browser()->OpenURL(OpenURLParams(test_page, Referrer(),
- WindowOpenDisposition::CURRENT_TAB,
- ui::PAGE_TRANSITION_TYPED, false));
- auth_needed_waiter.Wait();
- }
-
- int n_handlers = 0;
-
- while (n_handlers < kMultiRealmTestRealmCount) {
- WindowedAuthNeededObserver auth_needed_waiter(controller);
-
- while (!observer.handlers().empty()) {
- WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
- LoginHandler* handler = *observer.handlers().begin();
-
- ASSERT_TRUE(handler);
- n_handlers++;
- handler->CancelAuth();
- auth_cancelled_waiter.Wait();
- }
+ browser()->OpenURL(OpenURLParams(test_page, Referrer(),
+ WindowOpenDisposition::CURRENT_TAB,
+ ui::PAGE_TRANSITION_TYPED, false));
- if (n_handlers < kMultiRealmTestRealmCount)
- auth_needed_waiter.Wait();
+ // Need to have LoginHandlers created for all requests that need
+ // authentication.
+ while (observer.handlers().size() < kMultiRealmTestAuthRequestsCount)
+ WindowedAuthNeededObserver(controller).Wait();
+
+ // Now cancel auth once per realm. This should be sufficient to cancel all
+ // auth requests.
+ std::set<std::string> seen_realms;
+ for (int i = 0; i < kMultiRealmTestRealmCount; ++i) {
+ auto it = std::find_if(
+ observer.handlers().begin(), observer.handlers().end(),
+ [&seen_realms](LoginHandler* handler) {
+ return seen_realms.count(handler->auth_info()->realm) == 0;
+ });
+ ASSERT_TRUE(it != observer.handlers().end());
+ seen_realms.insert((*it)->auth_info()->realm);
+
+ WindowedAuthCancelledObserver auth_cancelled_waiter(controller);
+ (*it)->CancelAuth();
+ auth_cancelled_waiter.Wait();
}
load_stop_waiter.Wait();
- EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers);
EXPECT_EQ(0, observer.auth_supplied_count());
EXPECT_LT(0, observer.auth_needed_count());
EXPECT_LT(0, observer.auth_cancelled_count());
@@ -524,37 +523,35 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, MultipleRealmConfirmation) {
observer.Register(content::Source<NavigationController>(controller));
WindowedLoadStopObserver load_stop_waiter(controller, 1);
- int n_handlers = 0;
- {
- WindowedAuthNeededObserver auth_needed_waiter(controller);
-
- browser()->OpenURL(OpenURLParams(test_page, Referrer(),
- WindowOpenDisposition::CURRENT_TAB,
- ui::PAGE_TRANSITION_TYPED, false));
- auth_needed_waiter.Wait();
- }
-
- while (n_handlers < kMultiRealmTestRealmCount) {
- WindowedAuthNeededObserver auth_needed_waiter(controller);
-
- while (!observer.handlers().empty()) {
- WindowedAuthSuppliedObserver auth_supplied_waiter(controller);
- LoginHandler* handler = *observer.handlers().begin();
+ browser()->OpenURL(OpenURLParams(test_page, Referrer(),
+ WindowOpenDisposition::CURRENT_TAB,
+ ui::PAGE_TRANSITION_TYPED, false));
- ASSERT_TRUE(handler);
- n_handlers++;
- SetAuthFor(handler);
- auth_supplied_waiter.Wait();
- }
+ // Need to have LoginHandlers created for all requests that need
+ // authentication.
+ while (observer.handlers().size() < kMultiRealmTestAuthRequestsCount)
+ WindowedAuthNeededObserver(controller).Wait();
+
+ // Now supply auth once per realm. This should be sufficient to confirm all
+ // auth requests.
+ std::set<std::string> seen_realms;
+ for (int i = 0; i < kMultiRealmTestRealmCount; ++i) {
+ auto it = std::find_if(
+ observer.handlers().begin(), observer.handlers().end(),
+ [&seen_realms](LoginHandler* handler) {
+ return seen_realms.count(handler->auth_info()->realm) == 0;
+ });
+ ASSERT_TRUE(it != observer.handlers().end());
+ seen_realms.insert((*it)->auth_info()->realm);
- if (n_handlers < kMultiRealmTestRealmCount)
- auth_needed_waiter.Wait();
+ WindowedAuthSuppliedObserver auth_supplied_waiter(controller);
+ SetAuthFor(*it);
+ auth_supplied_waiter.Wait();
}
load_stop_waiter.Wait();
- EXPECT_EQ(kMultiRealmTestRealmCount, n_handlers);
EXPECT_LT(0, observer.auth_needed_count());
EXPECT_LT(0, observer.auth_supplied_count());
EXPECT_EQ(0, observer.auth_cancelled_count());
« no previous file with comments | « no previous file | content/public/test/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698