Commit b49b929e authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[iOS Enterprise] Add another unit test to verify password saving behavior

Ensure that the password saving behaves correct when the pref is unset, enabled and disabled.

Bug: 1065143
Change-Id: I7e112f167008b01c903cea53f06958f6e0c10e1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2136863
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarGuillaume Jenkins <gujen@google.com>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759353}
parent 048fbfbf
...@@ -158,6 +158,7 @@ source_set("unit_tests") { ...@@ -158,6 +158,7 @@ source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"credential_manager_unittest.mm", "credential_manager_unittest.mm",
"ios_chrome_password_manager_client_unittest.mm",
"js_credential_manager_unittest.mm", "js_credential_manager_unittest.mm",
"password_controller_js_unittest.mm", "password_controller_js_unittest.mm",
"password_controller_unittest.mm", "password_controller_unittest.mm",
......
// Copyright 2020 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.
#import "ios/chrome/browser/passwords/ios_chrome_password_manager_client.h"
#import <Foundation/Foundation.h>
#include <memory>
#include "components/password_manager/core/browser/mock_password_store.h"
#include "components/password_manager/core/browser/password_form_manager.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/testing_pref_service.h"
#import "ios/chrome/browser/passwords/password_controller.h"
#include "ios/chrome/browser/web/chrome_web_client.h"
#import "ios/chrome/browser/web/chrome_web_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using password_manager::PasswordFormManager;
using password_manager::PasswordManagerClient;
using password_manager::prefs::kCredentialsEnableService;
using testing::Return;
// TODO(crbug.com/958833): this file is initiated because of needing test for
// ios policy. More unit test of the client should be added.
class IOSChromePasswordManagerClientTest : public ChromeWebTest {
public:
IOSChromePasswordManagerClientTest()
: ChromeWebTest(std::make_unique<ChromeWebClient>()),
store_(new testing::NiceMock<password_manager::MockPasswordStore>()) {}
~IOSChromePasswordManagerClientTest() override {
store_->ShutdownOnUIThread();
}
void SetUp() override {
ChromeWebTest::SetUp();
ON_CALL(*store_, IsAbleToSavePasswords).WillByDefault(Return(true));
// When waiting for predictions is on, it makes tests more complicated.
// Disable waiting, since most tests have nothing to do with predictions.
// All tests that test working with prediction should explicitly turn
// predictions on.
PasswordFormManager::set_wait_for_server_predictions_for_filling(false);
passwordController_ =
[[PasswordController alloc] initWithWebState:web_state()];
}
// PasswordController for testing.
PasswordController* passwordController_;
scoped_refptr<password_manager::MockPasswordStore> store_;
};
// Tests that saving password behaves properly with the
// kCredentialsEnableService pref.
TEST_F(IOSChromePasswordManagerClientTest, PasswordManagerEnabledPolicyTest) {
PasswordManagerClient* client = passwordController_.passwordManagerClient;
GURL url = GURL("http://foo.example.com");
// Password Manager is enabled by default. IsSavingAndFillingEnabled should be
// true when PasswordManagerEnabled policy is not set.
EXPECT_TRUE(client->IsSavingAndFillingEnabled(url));
// The pref kCredentialsEnableService should be false when disable the policy.
client->GetPrefs()->SetBoolean(kCredentialsEnableService, false);
// IsSavingAndFillingEnabled should return false, which means the password
// won't be saved anymore.
EXPECT_FALSE(client->IsSavingAndFillingEnabled(url));
// The pref kCredentialsEnableService should be true when enable the policy.
client->GetPrefs()->SetBoolean(kCredentialsEnableService, true);
// IsSavingAndFillingEnabled should return true, which means the password
// should be saved.
EXPECT_TRUE(client->IsSavingAndFillingEnabled(url));
}
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