Commit dd110385 authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

testing::WaitUntilConditionOrTimeout in iOS settings and passwords

base::test::ios waiting helpers are deprecated and should be replaced
with testing::WaitUntilConditionOrTimeout, which does not bring the
whole test down with a DCHECK on failure.

This CL migrates the tests in
//ios/chrome/browser/{ui/settings|passwords} directories.

It also adds a new waiting constant kWaitForActionTimeout (10
seconds), which is based on TestTimeouts::action_timeout() (currently
10 seconds). The latter was used as the default argument for the
base::test::ios helpers which did not specify another timeout.

Bug: 784735
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I84a528127eb061baefff799f6e467b72d6b1465a
Reviewed-on: https://chromium-review.googlesource.com/774266
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517376}
parent e41e3235
......@@ -117,7 +117,6 @@ source_set("unit_tests") {
deps = [
":passwords",
"//base",
"//base/test:test_support",
"//components/autofill/core/common",
"//components/autofill/ios/browser",
"//components/password_manager/core/browser",
......@@ -131,6 +130,7 @@ source_set("unit_tests") {
"//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/ssl",
"//ios/chrome/browser/ui/commands",
"//ios/testing:ios_test_support",
"//ios/testing:ocmock_support",
"//ios/web",
"//ios/web/public/test",
......
......@@ -15,7 +15,6 @@
#include "base/memory/ref_counted.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "base/test/scoped_task_environment.h"
#include "base/values.h"
#include "components/autofill/core/common/password_form_fill_data.h"
......@@ -31,6 +30,7 @@
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/chrome/browser/passwords/js_password_manager.h"
#import "ios/chrome/browser/passwords/password_form_filler.h"
#import "ios/testing/wait_util.h"
#import "ios/web/public/navigation_item.h"
#import "ios/web/public/navigation_manager.h"
#include "ios/web/public/ssl_status.h"
......@@ -53,6 +53,9 @@ using autofill::PasswordForm;
using autofill::PasswordFormFillData;
using testing::NiceMock;
using testing::Return;
using testing::kWaitForActionTimeout;
using testing::kWaitForJSCompletionTimeout;
using testing::WaitUntilConditionOrTimeout;
using testing::_;
namespace {
......@@ -568,9 +571,10 @@ TEST_F(PasswordControllerTest, FLAKY_FindPasswordFormsInView) {
block_was_called = YES;
forms = result;
}];
base::test::ios::WaitUntilCondition(^bool() {
return block_was_called;
});
EXPECT_TRUE(
WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool() {
return block_was_called;
}));
if (data.expected_form_found) {
ASSERT_EQ(1U, forms.size());
EXPECT_EQ(base::ASCIIToUTF16(data.expected_username_element),
......@@ -666,9 +670,10 @@ TEST_F(PasswordControllerTest, FLAKY_GetSubmittedPasswordForm) {
[passwordController_
extractSubmittedPasswordForm:FormName(data.number_of_forms_to_submit)
completionHandler:completion_handler];
base::test::ios::WaitUntilCondition(^bool() {
return block_was_called;
});
EXPECT_TRUE(
WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool() {
return block_was_called;
}));
}
}
......@@ -928,9 +933,10 @@ TEST_F(PasswordControllerTest, FillPasswordForm) {
block_was_called = YES;
EXPECT_EQ(data.should_succeed, success);
}];
base::test::ios::WaitUntilCondition(^bool() {
return block_was_called;
});
EXPECT_TRUE(
WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool() {
return block_was_called;
}));
id result = ExecuteJavaScript(kInputFieldValueVerificationScript);
EXPECT_NSEQ(data.expected_result, result);
......@@ -952,9 +958,9 @@ TEST_F(PasswordControllerTest, FindAndFillOnePasswordForm) {
if (complete)
++success_counter;
}];
base::test::ios::WaitUntilCondition(^{
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return call_counter == 1;
});
}));
EXPECT_EQ(1, success_counter);
id result = ExecuteJavaScript(kInputFieldValueVerificationScript);
EXPECT_NSEQ(@"un=john.doe@gmail.com;pw=super!secret;", result);
......@@ -985,9 +991,9 @@ TEST_F(PasswordControllerTest, FindAndFillMultiplePasswordForms) {
<< success_counter;
}];
// There should be 3 password forms and only 2 successfully filled forms.
base::test::ios::WaitUntilCondition(^{
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return call_counter == 3;
});
}));
EXPECT_EQ(2, success_counter);
id result = ExecuteJavaScript(kInputFieldValueVerificationScript);
EXPECT_NSEQ(@"u2=john.doe@gmail.com;p2=super!secret;"
......@@ -1008,9 +1014,9 @@ BOOL PasswordControllerTest::BasicFormFill(NSString* html) {
block_was_called = YES;
return_value = success;
}];
base::test::ios::WaitUntilCondition(^bool() {
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForActionTimeout, ^bool() {
return block_was_called;
});
}));
return return_value;
}
......@@ -1104,9 +1110,9 @@ TEST_F(PasswordControllerTest, SuggestionUpdateTests) {
// Verify that the fill reports failed.
EXPECT_FALSE(success);
}];
base::test::ios::WaitUntilCondition(^bool() {
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool() {
return block_was_called;
});
}));
// Verify that the form has not been autofilled.
EXPECT_NSEQ(@"[]=, onkeyup=false, onchange=false",
......@@ -1222,9 +1228,9 @@ TEST_F(PasswordControllerTest, SelectingSuggestionShouldFillPasswordForm) {
// Verify that the fill reports failed.
EXPECT_FALSE(success);
}];
base::test::ios::WaitUntilCondition(^bool() {
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool() {
return block_was_called;
});
}));
// Verify that the form has not been autofilled.
EXPECT_NSEQ(@"[]=, onkeyup=false, onchange=false",
......@@ -1247,9 +1253,9 @@ TEST_F(PasswordControllerTest, SelectingSuggestionShouldFillPasswordForm) {
forField:@"u"
form:base::SysUTF8ToNSString(FormName(0))
completionHandler:completion];
base::test::ios::WaitUntilCondition(^bool() {
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool() {
return block_was_called;
});
}));
}
// Tests with invalid inputs.
......@@ -1451,9 +1457,9 @@ TEST_F(PasswordControllerTest, SendingToStoreDynamicallyAddedFormsOnFocus) {
ExecuteJavaScript(kSetUsernameInFocusScript);
// Wait until GetLogins is called.
base::test::ios::WaitUntilCondition(^bool() {
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForActionTimeout, ^bool() {
return *p_get_logins_called;
});
}));
}
// Tests that a touchend event from a button which contains in a password form
......
......@@ -249,7 +249,6 @@ source_set("unit_tests") {
":settings",
":test_support",
"//base",
"//base/test:test_support",
"//components/autofill/core/browser",
"//components/autofill/core/common",
"//components/browser_sync:test_support",
......@@ -297,6 +296,7 @@ source_set("unit_tests") {
"//ios/chrome/test:test_support",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/voice",
"//ios/testing:ios_test_support",
"//ios/third_party/material_components_ios",
"//ios/web",
"//ios/web/public/test",
......
......@@ -7,7 +7,6 @@
#include "base/guid.h"
#include "base/mac/foundation_util.h"
#include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
......@@ -15,6 +14,7 @@
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
#include "ios/chrome/browser/ui/settings/personal_data_manager_data_changed_observer.h"
#import "ios/testing/wait_util.h"
#include "ios/web/public/test/test_web_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -136,9 +136,10 @@ TEST_F(AutofillCollectionViewControllerTest, TestOneProfileItemDeleted) {
this->DeleteItem(i, j, ^{
completion_called = YES;
});
base::test::ios::WaitUntilCondition(^bool() {
return completion_called;
});
EXPECT_TRUE(testing::WaitUntilConditionOrTimeout(
testing::kWaitForUIElementTimeout, ^bool() {
return completion_called;
}));
};
autofill::PersonalDataManager* personal_data_manager =
......
......@@ -8,13 +8,13 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
#import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/testing/wait_util.h"
#include "ios/web/public/test/test_web_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......@@ -152,9 +152,10 @@ TEST_F(BlockPopupsCollectionViewControllerTest, TestOneAllowedItemDeleted) {
this->DeleteItem(i, j, ^{
completion_called = YES;
});
base::test::ios::WaitUntilCondition(^bool() {
return completion_called;
});
EXPECT_TRUE(testing::WaitUntilConditionOrTimeout(
testing::kWaitForUIElementTimeout, ^bool() {
return completion_called;
}));
};
delete_item_with_wait(1, 0);
......
......@@ -10,7 +10,6 @@
#include "base/compiler_specific.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "components/autofill/core/common/password_form.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/password_manager/core/browser/mock_password_store.h"
......@@ -19,6 +18,7 @@
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
#import "ios/chrome/browser/ui/settings/password_details_collection_view_controller.h"
#import "ios/testing/wait_util.h"
#include "ios/web/public/test/test_web_thread_bundle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -227,9 +227,10 @@ TEST_F(SavePasswordsCollectionViewControllerTest, DeleteItems) {
this->DeleteItem(i, j, ^{
completionCalled = YES;
});
base::test::ios::WaitUntilCondition(^bool() {
return completionCalled;
});
EXPECT_TRUE(testing::WaitUntilConditionOrTimeout(
testing::kWaitForUIElementTimeout, ^bool() {
return completionCalled;
}));
};
// Delete item in save passwords section.
......@@ -261,9 +262,10 @@ TEST_F(SavePasswordsCollectionViewControllerTest, DeleteItemsWithDuplicates) {
this->DeleteItem(i, j, ^{
completionCalled = YES;
});
base::test::ios::WaitUntilCondition(^bool() {
return completionCalled;
});
EXPECT_TRUE(testing::WaitUntilConditionOrTimeout(
testing::kWaitForUIElementTimeout, ^bool() {
return completionCalled;
}));
};
// Delete item in save passwords section.
......
......@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h>
#include "base/compiler_specific.h"
#import "base/test/ios/wait_util.h"
#include "components/browser_sync/profile_sync_service_mock.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
......@@ -15,6 +14,7 @@
#import "ios/chrome/browser/ui/settings/cells/passphrase_error_item.h"
#import "ios/chrome/browser/ui/settings/passphrase_collection_view_controller_test.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/testing/wait_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
......@@ -186,10 +186,10 @@ TEST_F(SyncCreatePassphraseCollectionViewControllerTest, TestOnStateChanged) {
[sync_controller onSyncStateChanged];
// Calling -onStateChanged with an accepted secondary passphrase should
// cause the controller to be popped off the navigation stack.
base::test::ios::WaitUntilCondition(^bool() {
return [nav_controller_ topViewController] != sync_controller;
});
EXPECT_NE([nav_controller_ topViewController], sync_controller);
EXPECT_TRUE(testing::WaitUntilConditionOrTimeout(
testing::kWaitForUIElementTimeout, ^bool() {
return [nav_controller_ topViewController] != sync_controller;
}));
}
// TODO(crbug.com/658269): Re-enable test once it's been deflaked.
......
......@@ -12,7 +12,6 @@
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "components/browser_sync/profile_sync_service_mock.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
......@@ -24,6 +23,7 @@
#import "ios/chrome/browser/ui/settings/cells/card_multiline_item.h"
#import "ios/chrome/browser/ui/settings/passphrase_collection_view_controller_test.h"
#import "ios/chrome/browser/ui/settings/sync_utils/sync_util.h"
#import "ios/testing/wait_util.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -200,10 +200,10 @@ TEST_F(SyncEncryptionPassphraseCollectionViewControllerTest,
[sync_controller onSyncStateChanged];
// Calling -onStateChanged with an accepted secondary passphrase should
// cause the controller to be popped off the navigation stack.
base::test::ios::WaitUntilCondition(^bool() {
return [nav_controller_ topViewController] != sync_controller;
});
EXPECT_NE([nav_controller_ topViewController], sync_controller);
EXPECT_TRUE(testing::WaitUntilConditionOrTimeout(
testing::kWaitForUIElementTimeout, ^bool() {
return [nav_controller_ topViewController] != sync_controller;
}));
}
TEST_F(SyncEncryptionPassphraseCollectionViewControllerTest, TestMessage) {
......
......@@ -27,6 +27,10 @@ extern const NSTimeInterval kWaitForDownloadTimeout;
// Constant for timeout in seconds while waiting for a pageload to complete.
extern const NSTimeInterval kWaitForPageLoadTimeout;
// Constant for timeout in seconds while waiting for a generic action to
// complete.
extern const NSTimeInterval kWaitForActionTimeout;
// Constant for timeout in seconds while waiting for cookies operations to
// complete.
extern const NSTimeInterval kWaitForCookiesTimeout;
......
......@@ -17,6 +17,7 @@ const NSTimeInterval kWaitForJSCompletionTimeout = 4.0;
const NSTimeInterval kWaitForUIElementTimeout = 4.0;
const NSTimeInterval kWaitForDownloadTimeout = 10.0;
const NSTimeInterval kWaitForPageLoadTimeout = 10.0;
const NSTimeInterval kWaitForActionTimeout = 10.0;
const NSTimeInterval kWaitForCookiesTimeout = 4.0;
const NSTimeInterval kWaitForFileOperationTimeout = 2.0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment